2022-04-17 22:32:56 +02:00

60 lines
1.7 KiB
Python

from .worker_template import TemplateWorker
from .download.browser import PDFDownloader
from .download.youtube import save_video
from .fetch.runner import get_description
from .upload.runner import upload_to_archive as run_upload
from .compress.runner import shrink_pdf
import logging
logger = logging.getLogger(__name__)
class DownloadWorker(TemplateWorker):
def __init__(self) -> None:
self.dl_runner = PDFDownloader().download
self.yt_runner = save_video
super().__init__()
def _handle_article(self, article_watcher):
article = article_watcher.article
u = article.article_url
if "youtu.be/" in u or "youtube.com/" in u:
action = self.yt_runner
else:
action = self.dl_runner
super()._handle_article(article_watcher, action)
article_watcher.download_completed = True
class FetchWorker(TemplateWorker):
def __init__(self) -> None:
super().__init__()
def _handle_article(self, article_watcher):
action = get_description # function
super()._handle_article(article_watcher, action)
article_watcher.fetch_completed = True
class UploadWorker(TemplateWorker):
def __init__(self) -> None:
super().__init__()
def _handle_article(self, article_watcher):
action = run_upload # function
super()._handle_article(article_watcher, action)
article_watcher.upload_completed = True
class CompressWorker(TemplateWorker):
def __init__(self) -> None:
super().__init__()
def _handle_article(self, article_watcher):
action = shrink_pdf
super()._handle_article(article_watcher, action)
article_watcher.compression_completed = True