sanatize output
This commit is contained in:
@@ -58,4 +58,4 @@ def main():
|
|||||||
for url in opts.urls:
|
for url in opts.urls:
|
||||||
dlmgr.add(url)
|
dlmgr.add(url)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("KeyboardInterrupt")
|
print("\nKeyboardInterrupt")
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class DownloadJob():
|
|||||||
def __init__(self, mngr, url):
|
def __init__(self, mngr, url):
|
||||||
self.mngr = mngr
|
self.mngr = mngr
|
||||||
self.extractor, self.info = mngr.extractors.get_for_url(url)
|
self.extractor, self.info = mngr.extractors.get_for_url(url)
|
||||||
|
if self.extractor is None:
|
||||||
|
return
|
||||||
self.directory = mngr.get_base_directory()
|
self.directory = mngr.get_base_directory()
|
||||||
self.downloaders = {}
|
self.downloaders = {}
|
||||||
self.filename_fmt = mngr.config.get(
|
self.filename_fmt = mngr.config.get(
|
||||||
@@ -61,7 +63,7 @@ class DownloadJob():
|
|||||||
self.directory_fmt = os.path.join(*segments)
|
self.directory_fmt = os.path.join(*segments)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Execute/Run the downlaod job"""
|
"""Execute/Run the download job"""
|
||||||
if self.extractor is None:
|
if self.extractor is None:
|
||||||
return # TODO: error msg
|
return # TODO: error msg
|
||||||
|
|
||||||
@@ -146,28 +148,26 @@ class ExtractorFinder():
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def get_for_url(self, url):
|
def get_for_url(self, url):
|
||||||
"""Get an extractor-instance suitable for 'ur'"""
|
"""Get an extractor-instance suitable for 'url'"""
|
||||||
name, match = self.find_pattern_match(url)
|
name, match = self.find_pattern_match(url)
|
||||||
if match:
|
if match:
|
||||||
module = importlib.import_module(".extractor." + name, __package__)
|
module = importlib.import_module(".extractor." + name, __package__)
|
||||||
klass = getattr(module, module.info["extractor"])
|
klass = getattr(module, module.info["extractor"])
|
||||||
return klass(match, self.config), module.info
|
return klass(match, self.config), module.info
|
||||||
else:
|
else:
|
||||||
print("pattern mismatch")
|
print("no suitable extractor found")
|
||||||
return None
|
return None, None
|
||||||
|
|
||||||
def find_pattern_match(self, url):
|
def find_pattern_match(self, url):
|
||||||
"""Find a pattern, that matches 'url', and return the (category,match) tuple"""
|
"""Find a pattern, that matches 'url', and return the (category,match) tuple"""
|
||||||
for category in self.config:
|
for category in self.config:
|
||||||
for key, value in self.config[category].items():
|
for key, value in self.config[category].items():
|
||||||
if key.startswith("regex"):
|
if key.startswith("regex"):
|
||||||
print(value)
|
|
||||||
match = re.match(value, url)
|
match = re.match(value, url)
|
||||||
if match:
|
if match:
|
||||||
return category, match
|
return category, match
|
||||||
for category, info in self.extractor_metadata():
|
for category, info in self.extractor_metadata():
|
||||||
for pattern in info["pattern"]:
|
for pattern in info["pattern"]:
|
||||||
print(pattern)
|
|
||||||
match = re.match(pattern, url)
|
match = re.match(pattern, url)
|
||||||
if match:
|
if match:
|
||||||
return category, match
|
return category, match
|
||||||
|
|||||||
Reference in New Issue
Block a user