Merge pull request #28 from radiorabe/feature/robbt/podcast-naming
Podcast naming feature as per #26
This commit is contained in:
commit
d86e223c45
|
@ -45,7 +45,8 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
|||
*/
|
||||
public function importEpisode($podcastId, $episode) {
|
||||
$e = $this->addPlaceholder($podcastId, $episode);
|
||||
$this->_download($e->getDbId(), $e->getDbDownloadUrl());
|
||||
$p = $e->getPodcast();
|
||||
$this->_download($e->getDbId(), $e->getDbDownloadUrl(), $p->getDbTitle());
|
||||
return $e;
|
||||
}
|
||||
|
||||
|
@ -126,7 +127,8 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
|||
public function downloadEpisodes($episodes) {
|
||||
/** @var PodcastEpisodes $episode */
|
||||
foreach($episodes as $episode) {
|
||||
$this->_download($episode->getDbId(), $episode->getDbDownloadUrl());
|
||||
$podcast = $episode->getPodcast();
|
||||
$this->_download($episode->getDbId(), $episode->getDbDownloadUrl(), $podcast->getDbTitle());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,8 +138,9 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
|||
*
|
||||
* @param int $id episode unique ID
|
||||
* @param string $url download url for the episode
|
||||
* @param string $title title of podcast to be downloaded - added as album to track metadata
|
||||
*/
|
||||
private function _download($id, $url) {
|
||||
private function _download($id, $url, $title) {
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$stationUrl = Application_Common_HTTPHelper::getStationUrl();
|
||||
$stationUrl .= substr($stationUrl, -1) == '/' ? '' : '/';
|
||||
|
@ -146,6 +149,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
|||
'url' => $url,
|
||||
'callback_url' => $stationUrl . 'rest/media',
|
||||
'api_key' => $CC_CONFIG["apiKey"][0],
|
||||
'podcast_name' => $title,
|
||||
);
|
||||
$task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data);
|
||||
// Get the created ThirdPartyTaskReference and set the episode ID so
|
||||
|
@ -436,4 +440,4 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,7 @@ class Application_Service_PodcastService
|
|||
$podcastArray["language"] = htmlspecialchars($rss->get_language());
|
||||
$podcastArray["copyright"] = htmlspecialchars($rss->get_copyright());
|
||||
|
||||
$rssAuthor = $rss->getAuthor();
|
||||
$name = empty($rssAuthor) ? "" : $rss->rssAuthor->get_name();
|
||||
$name = empty($rss->get_author()) ? "" : $rss->get_author()->get_name();
|
||||
$podcastArray["creator"] = htmlspecialchars($name);
|
||||
|
||||
$categories = array();
|
||||
|
@ -471,4 +470,4 @@ class Application_Service_PodcastService
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,12 @@ import soundcloud
|
|||
import cgi
|
||||
import urlparse
|
||||
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.utils.log import get_task_logger
|
||||
from contextlib import closing
|
||||
|
@ -123,7 +129,7 @@ def soundcloud_delete(token, track_id):
|
|||
|
||||
|
||||
@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
|
||||
|
||||
|
@ -131,6 +137,7 @@ def podcast_download(id, url, callback_url, api_key):
|
|||
: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
|
||||
|
||||
:return: JSON formatted string of a dictionary of download statuses
|
||||
and file identifiers (for successful uploads)
|
||||
|
@ -143,7 +150,18 @@ def podcast_download(id, url, callback_url, api_key):
|
|||
re = None
|
||||
with closing(requests.get(url, stream=True)) as 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)
|
||||
# currently hardcoded for mp3s may want to add support for oggs etc
|
||||
m = MP3(audiofile.name, ID3=EasyID3)
|
||||
try:
|
||||
m['album']
|
||||
except KeyError:
|
||||
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()
|
||||
f = json.loads(re.content) # Read the response from the media API to get the file id
|
||||
obj['fileid'] = f['id']
|
||||
|
|
Loading…
Reference in New Issue