add base class for job types
This commit is contained in:
10
gallery_dl/exceptions.py
Normal file
10
gallery_dl/exceptions.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2015 Mike Fährmann
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
class NoExtractorError(Exception):
|
||||||
|
pass
|
||||||
@@ -7,17 +7,27 @@
|
|||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
from . import config, extractor, downloader, text, output, exceptions
|
||||||
from . import config, extractor, downloader, text, output
|
|
||||||
from .extractor.message import Message
|
from .extractor.message import Message
|
||||||
|
|
||||||
class DownloadJob():
|
class Job():
|
||||||
|
"""Base class for Job-types"""
|
||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
self.extractor = extractor.find(url)
|
self.extractor = extractor.find(url)
|
||||||
if self.extractor is None:
|
if self.extractor is None:
|
||||||
print(url, ": No extractor found", sep="", file=sys.stderr)
|
raise exceptions.NoExtractorError(url)
|
||||||
return
|
|
||||||
|
def run(self):
|
||||||
|
"""Execute or run the job"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadJob(Job):
|
||||||
|
"""Download images into appropriate directory/filename locations"""
|
||||||
|
|
||||||
|
def __init__(self, url):
|
||||||
|
Job.__init__(self, url)
|
||||||
self.directory = self.get_base_directory()
|
self.directory = self.get_base_directory()
|
||||||
self.downloaders = {}
|
self.downloaders = {}
|
||||||
self.queue = None
|
self.queue = None
|
||||||
@@ -34,7 +44,6 @@ 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 download job"""
|
|
||||||
if self.extractor is None:
|
if self.extractor is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -63,7 +72,10 @@ class DownloadJob():
|
|||||||
|
|
||||||
if self.queue:
|
if self.queue:
|
||||||
for url in self.queue:
|
for url in self.queue:
|
||||||
DownloadJob(url).run()
|
try:
|
||||||
|
DownloadJob(url).run()
|
||||||
|
except exceptions.NoExtractorError:
|
||||||
|
pass
|
||||||
|
|
||||||
def download(self, msg):
|
def download(self, msg):
|
||||||
"""Download the resource specified in 'msg'"""
|
"""Download the resource specified in 'msg'"""
|
||||||
@@ -117,16 +129,10 @@ class DownloadJob():
|
|||||||
return os.path.expanduser(os.path.expandvars(bdir))
|
return os.path.expanduser(os.path.expandvars(bdir))
|
||||||
|
|
||||||
|
|
||||||
class KeywordJob():
|
class KeywordJob(Job):
|
||||||
|
"""Print available keywords"""
|
||||||
def __init__(self, url):
|
|
||||||
self.extractor = extractor.find(url)
|
|
||||||
if self.extractor is None:
|
|
||||||
print(url, ": No extractor found", sep="", file=sys.stderr)
|
|
||||||
return
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Execute/Run the download job"""
|
|
||||||
if self.extractor is None:
|
if self.extractor is None:
|
||||||
return
|
return
|
||||||
for msg in self.extractor:
|
for msg in self.extractor:
|
||||||
@@ -146,12 +152,8 @@ class KeywordJob():
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
class UrlJob():
|
class UrlJob(Job):
|
||||||
|
"""Print download urls"""
|
||||||
def __init__(self, url):
|
|
||||||
self.extractor = extractor.find(url)
|
|
||||||
if self.extractor is None:
|
|
||||||
print(url, ": No extractor found", sep="", file=sys.stderr)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.extractor is None:
|
if self.extractor is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user