first part of the adding album tags to podcast downloads

This commit is contained in:
Robb Ebright 2017-02-13 09:32:07 -05:00 committed by Lucas Bickel
parent 4557395a86
commit 2cebb7dfa2
2 changed files with 21 additions and 3 deletions

View file

@ -146,6 +146,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
'url' => $url, 'url' => $url,
'callback_url' => $stationUrl . 'rest/media', 'callback_url' => $stationUrl . 'rest/media',
'api_key' => $CC_CONFIG["apiKey"][0], 'api_key' => $CC_CONFIG["apiKey"][0],
'podcast_name' => "best podcast",
); );
$task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data); $task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data);
// Get the created ThirdPartyTaskReference and set the episode ID so // Get the created ThirdPartyTaskReference and set the episode ID so

View file

@ -6,6 +6,12 @@ import soundcloud
import cgi import cgi
import urlparse import urlparse
import posixpath import posixpath
import shutil
import tempfile
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3
import mutagen.id3
from StringIO import StringIO
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 contextlib import closing from contextlib import closing
@ -123,7 +129,7 @@ def soundcloud_delete(token, track_id):
@celery.task(name='podcast-download', acks_late=True) @celery.task(name='podcast-download', acks_late=True)
def podcast_download(id, url, callback_url, api_key): def podcast_download(id, url, callback_url, api_key, podcast_name):
""" """
Download a podcast episode Download a podcast episode
@ -131,6 +137,7 @@ def podcast_download(id, url, callback_url, api_key):
: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 callback_url: callback URL to send the downloaded file to
:param api_key: API key for callback authentication :param api_key: API key for callback authentication
:param podcast_name: NAme of podcast to be added to id3 metadata for smartblock
:return: JSON formatted string of a dictionary of download statuses :return: JSON formatted string of a dictionary of download statuses
and file identifiers (for successful uploads) and file identifiers (for successful uploads)
@ -143,7 +150,17 @@ def podcast_download(id, url, callback_url, api_key):
re = None re = None
with closing(requests.get(url, stream=True)) as r: with closing(requests.get(url, stream=True)) as r:
filename = get_filename(r) filename = get_filename(r)
re = requests.post(callback_url, files={'file': (filename, r.content)}, auth=requests.auth.HTTPBasicAuth(api_key, '')) with tempfile.NamedTemporaryFile(mode ='wb+', delete=False) as audiofile:
shutil.copyfileobj(r.raw, audiofile)
#m = mutagen.File(audiofile.name, easy=True)
# currently hardcoded for mp3s may want to add support for oggs etc
m = MP3(audiofile.name, ID3=EasyID3)
#m = EasyID3(audiofile.name)
m['album'] = [podcast_name]
m.save()
filetypeinfo = m.pprint()
logger.info('filetypeinfo is {0}'.format(filetypeinfo))
re = requests.post(callback_url, files={'file': (filename, open(audiofile.name, 'rb'))}, auth=requests.auth.HTTPBasicAuth(api_key, ''))
re.raise_for_status() re.raise_for_status()
f = json.loads(re.content) # Read the response from the media API to get the file id f = json.loads(re.content) # Read the response from the media API to get the file id
obj['fileid'] = f['id'] obj['fileid'] = f['id']