]>
Commit | Line | Data |
---|---|---|
e330d59a | 1 | from .common import InfoExtractor |
8075d4f9 | 2 | from ..compat import compat_str |
1cc79574 | 3 | from ..utils import ( |
e330d59a | 4 | ExtractorError, |
e330d59a | 5 | int_or_none, |
8075d4f9 | 6 | parse_iso8601, |
e330d59a PH |
7 | ) |
8 | ||
9 | ||
10 | class PlayFMIE(InfoExtractor): | |
11 | IE_NAME = 'play.fm' | |
8075d4f9 | 12 | _VALID_URL = r'https?://(?:www\.)?play\.fm/(?P<slug>(?:[^/]+/)+(?P<id>[^/]+))/?(?:$|[?#])' |
e330d59a PH |
13 | |
14 | _TEST = { | |
8075d4f9 | 15 | 'url': 'https://www.play.fm/dan-drastic/sven-tasnadi-leipzig-electronic-music-batofar-paris-fr-2014-07-12', |
e330d59a PH |
16 | 'md5': 'c505f8307825a245d0c7ad1850001f22', |
17 | 'info_dict': { | |
8075d4f9 | 18 | 'id': '71276', |
e330d59a | 19 | 'ext': 'mp3', |
8075d4f9 S |
20 | 'title': 'Sven Tasnadi - LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12', |
21 | 'description': '', | |
22 | 'duration': 5627, | |
23 | 'timestamp': 1406033781, | |
24 | 'upload_date': '20140722', | |
25 | 'uploader': 'Dan Drastic', | |
26 | 'uploader_id': '71170', | |
e330d59a | 27 | 'view_count': int, |
273dea42 | 28 | 'comment_count': int, |
e330d59a PH |
29 | }, |
30 | } | |
31 | ||
32 | def _real_extract(self, url): | |
5ad28e7f | 33 | mobj = self._match_valid_url(url) |
e330d59a | 34 | video_id = mobj.group('id') |
8075d4f9 | 35 | slug = mobj.group('slug') |
e330d59a | 36 | |
8075d4f9 S |
37 | recordings = self._download_json( |
38 | 'http://v2api.play.fm/recordings/slug/%s' % slug, video_id) | |
e330d59a | 39 | |
8075d4f9 S |
40 | error = recordings.get('error') |
41 | if isinstance(error, dict): | |
42 | raise ExtractorError( | |
43 | '%s returned error: %s' % (self.IE_NAME, error.get('message')), | |
44 | expected=True) | |
e330d59a | 45 | |
8075d4f9 S |
46 | audio_url = recordings['audio'] |
47 | video_id = compat_str(recordings.get('id') or video_id) | |
48 | title = recordings['title'] | |
49 | description = recordings.get('description') | |
50 | duration = int_or_none(recordings.get('recordingDuration')) | |
51 | timestamp = parse_iso8601(recordings.get('created_at')) | |
52 | uploader = recordings.get('page', {}).get('title') | |
53 | uploader_id = compat_str(recordings.get('page', {}).get('id')) | |
54 | view_count = int_or_none(recordings.get('playCount')) | |
55 | comment_count = int_or_none(recordings.get('commentCount')) | |
56 | categories = [tag['name'] for tag in recordings.get('tags', []) if tag.get('name')] | |
e330d59a PH |
57 | |
58 | return { | |
59 | 'id': video_id, | |
8075d4f9 | 60 | 'url': audio_url, |
e330d59a | 61 | 'title': title, |
8075d4f9 | 62 | 'description': description, |
e330d59a | 63 | 'duration': duration, |
8075d4f9 | 64 | 'timestamp': timestamp, |
e330d59a PH |
65 | 'uploader': uploader, |
66 | 'uploader_id': uploader_id, | |
8075d4f9 S |
67 | 'view_count': view_count, |
68 | 'comment_count': comment_count, | |
69 | 'categories': categories, | |
e330d59a | 70 | } |