From d93731807c3386745cdbf25e566cf79fe60e2ab2 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Tue, 26 Jul 2022 14:18:41 +0200 Subject: [PATCH] feat(worker): load callback details from config (#1994) --- .../services/PodcastEpisodeService.php | 4 ---- worker/libretime_worker/config.py | 3 ++- worker/libretime_worker/tasks.py | 15 +++++++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/legacy/application/services/PodcastEpisodeService.php b/legacy/application/services/PodcastEpisodeService.php index 7436f07e0..c7f60b251 100644 --- a/legacy/application/services/PodcastEpisodeService.php +++ b/legacy/application/services/PodcastEpisodeService.php @@ -180,13 +180,9 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir */ private function _download($id, $url, $title, $album_override, $track_title = null) { - $CC_CONFIG = Config::getConfig(); - $stationUrl = Config::getPublicUrl(); $data = [ 'id' => $id, 'url' => $url, - 'callback_url' => $stationUrl . 'rest/media', - 'api_key' => $CC_CONFIG['apiKey'][0], 'podcast_name' => $title, 'album_override' => $album_override, 'track_title' => $track_title, diff --git a/worker/libretime_worker/config.py b/worker/libretime_worker/config.py index 0e24c6fe0..2c49682b7 100644 --- a/worker/libretime_worker/config.py +++ b/worker/libretime_worker/config.py @@ -1,10 +1,11 @@ from os import getenv from kombu import Exchange, Queue -from libretime_shared.config import BaseConfig, RabbitMQConfig +from libretime_shared.config import BaseConfig, GeneralConfig, RabbitMQConfig class Config(BaseConfig): + general: GeneralConfig rabbitmq: RabbitMQConfig = RabbitMQConfig() diff --git a/worker/libretime_worker/tasks.py b/worker/libretime_worker/tasks.py index 7259bb9e8..57b3da707 100644 --- a/worker/libretime_worker/tasks.py +++ b/worker/libretime_worker/tasks.py @@ -12,21 +12,25 @@ import requests from celery import Celery from celery.utils.log import get_task_logger +from .config import config + worker = Celery() logger = get_task_logger(__name__) @worker.task(name="podcast-download", acks_late=True) def podcast_download( - id, url, callback_url, api_key, podcast_name, album_override, track_title + id, + url, + podcast_name, + album_override, + track_title, ): """ Download a podcast episode :param id: episode unique ID :param url: download url for the episode - :param callback_url: callback URL to send the downloaded file to - :param api_key: API key for callback authentication :param podcast_name: Name of podcast to be added to id3 metadata for smartblock :param album_override: Passing whether to override the album id3 even if it exists :param track_title: Passing the title of the episode from feed to override the metadata @@ -66,10 +70,13 @@ def podcast_download( logger.info( "filetypeinfo is {}".format(filetypeinfo.encode("ascii", "ignore")) ) + callback_url = f"{config.general.public_url}/rest/media" + callback_api_key = config.general.api_key + re = requests.post( callback_url, files={"file": (filename, open(audiofile.name, "rb"))}, - auth=requests.auth.HTTPBasicAuth(api_key, ""), + auth=requests.auth.HTTPBasicAuth(callback_api_key, ""), ) re.raise_for_status() try: