feat(worker): load callback details from config (#1994)
This commit is contained in:
parent
2d334d3ede
commit
d93731807c
|
@ -180,13 +180,9 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
||||||
*/
|
*/
|
||||||
private function _download($id, $url, $title, $album_override, $track_title = null)
|
private function _download($id, $url, $title, $album_override, $track_title = null)
|
||||||
{
|
{
|
||||||
$CC_CONFIG = Config::getConfig();
|
|
||||||
$stationUrl = Config::getPublicUrl();
|
|
||||||
$data = [
|
$data = [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'callback_url' => $stationUrl . 'rest/media',
|
|
||||||
'api_key' => $CC_CONFIG['apiKey'][0],
|
|
||||||
'podcast_name' => $title,
|
'podcast_name' => $title,
|
||||||
'album_override' => $album_override,
|
'album_override' => $album_override,
|
||||||
'track_title' => $track_title,
|
'track_title' => $track_title,
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
|
||||||
from kombu import Exchange, Queue
|
from kombu import Exchange, Queue
|
||||||
from libretime_shared.config import BaseConfig, RabbitMQConfig
|
from libretime_shared.config import BaseConfig, GeneralConfig, RabbitMQConfig
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseConfig):
|
class Config(BaseConfig):
|
||||||
|
general: GeneralConfig
|
||||||
rabbitmq: RabbitMQConfig = RabbitMQConfig()
|
rabbitmq: RabbitMQConfig = RabbitMQConfig()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,25 @@ import requests
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
from celery.utils.log import get_task_logger
|
from celery.utils.log import get_task_logger
|
||||||
|
|
||||||
|
from .config import config
|
||||||
|
|
||||||
worker = Celery()
|
worker = Celery()
|
||||||
logger = get_task_logger(__name__)
|
logger = get_task_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@worker.task(name="podcast-download", acks_late=True)
|
@worker.task(name="podcast-download", acks_late=True)
|
||||||
def podcast_download(
|
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
|
Download a podcast episode
|
||||||
|
|
||||||
:param id: episode unique ID
|
:param id: episode unique ID
|
||||||
:param url: download url for the episode
|
: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 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 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
|
:param track_title: Passing the title of the episode from feed to override the metadata
|
||||||
|
@ -66,10 +70,13 @@ def podcast_download(
|
||||||
logger.info(
|
logger.info(
|
||||||
"filetypeinfo is {}".format(filetypeinfo.encode("ascii", "ignore"))
|
"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(
|
re = requests.post(
|
||||||
callback_url,
|
callback_url,
|
||||||
files={"file": (filename, open(audiofile.name, "rb"))},
|
files={"file": (filename, open(audiofile.name, "rb"))},
|
||||||
auth=requests.auth.HTTPBasicAuth(api_key, ""),
|
auth=requests.auth.HTTPBasicAuth(callback_api_key, ""),
|
||||||
)
|
)
|
||||||
re.raise_for_status()
|
re.raise_for_status()
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue