Created
May 18, 2019 03:01
-
-
Save thurask/5b92f9f2ca250a4ee6d0d22ed9911a4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import os | |
import requests | |
import subprocess | |
import zipfile | |
EXIFTOOLDIR = "C:\\tools\\exiftool" | |
EXIFTOOLURL = "https://www.sno.phy.queensu.ca/~phil/exiftool/" | |
EXIFTOOLVER = "http://owl.phy.queensu.ca/~phil/exiftool/ver.txt" | |
def get_local_version(): | |
exepath = os.path.join(EXIFTOOLDIR, "exiftool.exe") | |
try: | |
rawver = subprocess.run([exepath, "-ver"], capture_output=True).stdout | |
except Exception: | |
purever = "00.00" | |
else: | |
purever = str(rawver.strip(), "utf-8") | |
return purever | |
def get_remote_version(): | |
req = requests.get(EXIFTOOLVER) | |
if req.status_code == 200: | |
remver = req.text | |
else: | |
remver = "00.00" | |
return remver | |
def download_exiftool(remver): | |
remurl = "{}exiftool-{}.zip".format(EXIFTOOLURL, remver) | |
req = requests.get(remurl) | |
bio = io.BytesIO(req.content) | |
zipf = zipfile.ZipFile(bio) | |
exiftoolexe = zipf.read("exiftool(-k).exe") | |
with open(os.path.join(EXIFTOOLDIR, "exiftool.exe"), "wb") as afile: | |
afile.write(exiftoolexe) | |
def is_it_newer(curver, remver): | |
curint = int(curver.replace(".", "")) | |
remint = int(remver.replace(".", "")) | |
sentinel = True if remint > curint else False | |
return sentinel | |
def main(): | |
curver = get_local_version() | |
remver = get_remote_version() | |
is_newer = is_it_newer(curver, remver) | |
if is_newer: | |
download_exiftool(remver) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment