mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
add base class for job types
This commit is contained in:
parent
75ff08f73c
commit
059b1ee5e8
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.
|
||||
|
||||
import os
|
||||
import sys
|
||||
from . import config, extractor, downloader, text, output
|
||||
from . import config, extractor, downloader, text, output, exceptions
|
||||
from .extractor.message import Message
|
||||
|
||||
class DownloadJob():
|
||||
class Job():
|
||||
"""Base class for Job-types"""
|
||||
|
||||
def __init__(self, url):
|
||||
self.extractor = extractor.find(url)
|
||||
if self.extractor is None:
|
||||
print(url, ": No extractor found", sep="", file=sys.stderr)
|
||||
return
|
||||
raise exceptions.NoExtractorError(url)
|
||||
|
||||
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.downloaders = {}
|
||||
self.queue = None
|
||||
@ -34,7 +44,6 @@ class DownloadJob():
|
||||
self.directory_fmt = os.path.join(*segments)
|
||||
|
||||
def run(self):
|
||||
"""Execute/Run the download job"""
|
||||
if self.extractor is None:
|
||||
return
|
||||
|
||||
@ -63,7 +72,10 @@ class DownloadJob():
|
||||
|
||||
if self.queue:
|
||||
for url in self.queue:
|
||||
DownloadJob(url).run()
|
||||
try:
|
||||
DownloadJob(url).run()
|
||||
except exceptions.NoExtractorError:
|
||||
pass
|
||||
|
||||
def download(self, msg):
|
||||
"""Download the resource specified in 'msg'"""
|
||||
@ -117,16 +129,10 @@ class DownloadJob():
|
||||
return os.path.expanduser(os.path.expandvars(bdir))
|
||||
|
||||
|
||||
class KeywordJob():
|
||||
|
||||
def __init__(self, url):
|
||||
self.extractor = extractor.find(url)
|
||||
if self.extractor is None:
|
||||
print(url, ": No extractor found", sep="", file=sys.stderr)
|
||||
return
|
||||
class KeywordJob(Job):
|
||||
"""Print available keywords"""
|
||||
|
||||
def run(self):
|
||||
"""Execute/Run the download job"""
|
||||
if self.extractor is None:
|
||||
return
|
||||
for msg in self.extractor:
|
||||
@ -146,12 +152,8 @@ class KeywordJob():
|
||||
print()
|
||||
|
||||
|
||||
class UrlJob():
|
||||
|
||||
def __init__(self, url):
|
||||
self.extractor = extractor.find(url)
|
||||
if self.extractor is None:
|
||||
print(url, ": No extractor found", sep="", file=sys.stderr)
|
||||
class UrlJob(Job):
|
||||
"""Print download urls"""
|
||||
|
||||
def run(self):
|
||||
if self.extractor is None:
|
||||
|
Loading…
Reference in New Issue
Block a user