diff options
Diffstat (limited to 'gallery_dl/util.py')
| -rw-r--r-- | gallery_dl/util.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 98b6d59..8ce1fb4 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -19,6 +19,7 @@ import binascii import datetime import functools import itertools +import subprocess import urllib.parse from http.cookiejar import Cookie from email.utils import mktime_tz, parsedate_tz @@ -273,6 +274,39 @@ Response Headers fp.write(response.content) +def extract_headers(response): + headers = response.headers + data = dict(headers) + + hcd = headers.get("content-disposition") + if hcd: + name = text.extr(hcd, 'filename="', '"') + if name: + text.nameext_from_url(name, data) + + hlm = headers.get("last-modified") + if hlm: + data["date"] = datetime.datetime(*parsedate_tz(hlm)[:6]) + + return data + + +@functools.lru_cache(maxsize=None) +def git_head(): + try: + out, err = subprocess.Popen( + ("git", "rev-parse", "--short", "HEAD"), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=os.path.dirname(os.path.abspath(__file__)), + ).communicate() + if out and not err: + return out.decode().rstrip() + except (OSError, subprocess.SubprocessError): + pass + return None + + def expand_path(path): """Expand environment variables and tildes (~)""" if not path: |
