enable long pathnames on windows (#4)
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import platform
|
||||||
from . import config, extractor, downloader, text, output, exception
|
from . import config, extractor, downloader, text, output, exception
|
||||||
from .extractor.message import Message
|
from .extractor.message import Message
|
||||||
|
|
||||||
@@ -24,7 +25,6 @@ class Job():
|
|||||||
"""Execute or run the job"""
|
"""Execute or run the job"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DownloadJob(Job):
|
class DownloadJob(Job):
|
||||||
"""Download images into appropriate directory/filename locations"""
|
"""Download images into appropriate directory/filename locations"""
|
||||||
|
|
||||||
@@ -84,12 +84,13 @@ class DownloadJob(Job):
|
|||||||
_, url, metadata = msg
|
_, url, metadata = msg
|
||||||
filename = text.clean_path(self.filename_fmt.format(**metadata))
|
filename = text.clean_path(self.filename_fmt.format(**metadata))
|
||||||
path = os.path.join(self.directory, filename)
|
path = os.path.join(self.directory, filename)
|
||||||
if os.path.exists(path):
|
realpath = self.adjust_path(path)
|
||||||
|
if os.path.exists(realpath):
|
||||||
self.printer.skip(path)
|
self.printer.skip(path)
|
||||||
return
|
return
|
||||||
dlinstance = self.get_downloader(url)
|
dlinstance = self.get_downloader(url)
|
||||||
self.printer.start(path)
|
self.printer.start(path)
|
||||||
with open(path, "wb") as file:
|
with open(realpath, "wb") as file:
|
||||||
tries = dlinstance.download(url, file)
|
tries = dlinstance.download(url, file)
|
||||||
self.printer.success(path, tries)
|
self.printer.success(path, tries)
|
||||||
|
|
||||||
@@ -103,7 +104,7 @@ class DownloadJob(Job):
|
|||||||
self.get_base_directory(),
|
self.get_base_directory(),
|
||||||
*segments
|
*segments
|
||||||
)
|
)
|
||||||
os.makedirs(self.directory, exist_ok=True)
|
os.makedirs(self.adjust_path(self.directory), exist_ok=True)
|
||||||
|
|
||||||
def get_downloader(self, url):
|
def get_downloader(self, url):
|
||||||
"""Return, and possibly construct, a downloader suitable for 'url'"""
|
"""Return, and possibly construct, a downloader suitable for 'url'"""
|
||||||
@@ -133,6 +134,11 @@ class DownloadJob(Job):
|
|||||||
bdir = os.path.join(*bdir)
|
bdir = os.path.join(*bdir)
|
||||||
return os.path.expanduser(os.path.expandvars(bdir))
|
return os.path.expanduser(os.path.expandvars(bdir))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def adjust_path(path, longpaths=platform.system() == "Windows"):
|
||||||
|
"""Enable longer-than-260-character paths on windows"""
|
||||||
|
return "\\\\?\\" + os.path.abspath(path) if longpaths else path
|
||||||
|
|
||||||
|
|
||||||
class KeywordJob(Job):
|
class KeywordJob(Job):
|
||||||
"""Print available keywords"""
|
"""Print available keywords"""
|
||||||
|
|||||||
Reference in New Issue
Block a user