[playfm] Adapt to v2api (Closes #5344)

pull/5351/head
Sergey M․ 2015-04-02 20:26:05 +06:00
parent 1a944d8a2a
commit 8075d4f99d
1 changed files with 37 additions and 50 deletions

View File

@ -4,85 +4,72 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import compat_str
compat_urllib_parse,
compat_urllib_request,
)
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
float_or_none,
int_or_none, int_or_none,
str_to_int, parse_iso8601,
) )
class PlayFMIE(InfoExtractor): class PlayFMIE(InfoExtractor):
IE_NAME = 'play.fm' IE_NAME = 'play.fm'
_VALID_URL = r'https?://(?:www\.)?play\.fm/[^?#]*(?P<upload_date>[0-9]{8})(?P<id>[0-9]{6})(?:$|[?#])' _VALID_URL = r'https?://(?:www\.)?play\.fm/(?P<slug>(?:[^/]+/)+(?P<id>[^/]+))/?(?:$|[?#])'
_TEST = { _TEST = {
'url': 'http://www.play.fm/recording/leipzigelectronicmusicbatofarparis_fr20140712137220', 'url': 'https://www.play.fm/dan-drastic/sven-tasnadi-leipzig-electronic-music-batofar-paris-fr-2014-07-12',
'md5': 'c505f8307825a245d0c7ad1850001f22', 'md5': 'c505f8307825a245d0c7ad1850001f22',
'info_dict': { 'info_dict': {
'id': '137220', 'id': '71276',
'ext': 'mp3', 'ext': 'mp3',
'title': 'LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12', 'title': 'Sven Tasnadi - LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12',
'uploader': 'Sven Tasnadi', 'description': '',
'uploader_id': 'sventasnadi', 'duration': 5627,
'duration': 5627.428, 'timestamp': 1406033781,
'upload_date': '20140712', 'upload_date': '20140722',
'uploader': 'Dan Drastic',
'uploader_id': '71170',
'view_count': int, 'view_count': int,
'comment_count': int, 'comment_count': int,
'thumbnail': 're:^https?://.*\.jpg$',
}, },
} }
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') video_id = mobj.group('id')
upload_date = mobj.group('upload_date') slug = mobj.group('slug')
rec_data = compat_urllib_parse.urlencode({'rec_id': video_id}) recordings = self._download_json(
req = compat_urllib_request.Request( 'http://v2api.play.fm/recordings/slug/%s' % slug, video_id)
'http://www.play.fm/flexRead/recording', data=rec_data)
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
rec_doc = self._download_xml(req, video_id)
error_node = rec_doc.find('./error') error = recordings.get('error')
if error_node is not None: if isinstance(error, dict):
raise ExtractorError('An error occured: %s (code %s)' % ( raise ExtractorError(
error_node.text, rec_doc.find('./status').text)) '%s returned error: %s' % (self.IE_NAME, error.get('message')),
expected=True)
recording = rec_doc.find('./recording') audio_url = recordings['audio']
title = recording.find('./title').text video_id = compat_str(recordings.get('id') or video_id)
view_count = str_to_int(recording.find('./stats/playcount').text) title = recordings['title']
comment_count = str_to_int(recording.find('./stats/comments').text) description = recordings.get('description')
duration = float_or_none(recording.find('./duration').text, scale=1000) duration = int_or_none(recordings.get('recordingDuration'))
thumbnail = recording.find('./image').text timestamp = parse_iso8601(recordings.get('created_at'))
uploader = recordings.get('page', {}).get('title')
artist = recording.find('./artists/artist') uploader_id = compat_str(recordings.get('page', {}).get('id'))
uploader = artist.find('./name').text view_count = int_or_none(recordings.get('playCount'))
uploader_id = artist.find('./slug').text comment_count = int_or_none(recordings.get('commentCount'))
categories = [tag['name'] for tag in recordings.get('tags', []) if tag.get('name')]
video_url = '%s//%s/%s/%s/offset/0/sh/%s/rec/%s/jingle/%s/loc/%s' % (
'http:', recording.find('./url').text,
recording.find('./_class').text, recording.find('./file_id').text,
rec_doc.find('./uuid').text, video_id,
rec_doc.find('./jingle/file_id').text,
'http%3A%2F%2Fwww.play.fm%2Fplayer',
)
return { return {
'id': video_id, 'id': video_id,
'url': video_url, 'url': audio_url,
'ext': 'mp3',
'filesize': int_or_none(recording.find('./size').text),
'title': title, 'title': title,
'upload_date': upload_date, 'description': description,
'view_count': view_count,
'comment_count': comment_count,
'duration': duration, 'duration': duration,
'thumbnail': thumbnail, 'timestamp': timestamp,
'uploader': uploader, 'uploader': uploader,
'uploader_id': uploader_id, 'uploader_id': uploader_id,
'view_count': view_count,
'comment_count': comment_count,
'categories': categories,
} }