]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/playfm.py
e895ba480c8d5cac22a746169708c4ebf95f0c8e
[yt-dlp.git] / yt_dlp / extractor / playfm.py
1 from .common import InfoExtractor
2 from ..compat import compat_str
3 from ..utils import (
4 ExtractorError,
5 int_or_none,
6 parse_iso8601,
7 )
8
9
10 class PlayFMIE(InfoExtractor):
11 IE_NAME = 'play.fm'
12 _VALID_URL = r'https?://(?:www\.)?play\.fm/(?P<slug>(?:[^/]+/)+(?P<id>[^/]+))/?(?:$|[?#])'
13
14 _TEST = {
15 'url': 'https://www.play.fm/dan-drastic/sven-tasnadi-leipzig-electronic-music-batofar-paris-fr-2014-07-12',
16 'md5': 'c505f8307825a245d0c7ad1850001f22',
17 'info_dict': {
18 'id': '71276',
19 'ext': 'mp3',
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',
27 'view_count': int,
28 'comment_count': int,
29 },
30 }
31
32 def _real_extract(self, url):
33 mobj = self._match_valid_url(url)
34 video_id = mobj.group('id')
35 slug = mobj.group('slug')
36
37 recordings = self._download_json(
38 'http://v2api.play.fm/recordings/slug/%s' % slug, video_id)
39
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)
45
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')]
57
58 return {
59 'id': video_id,
60 'url': audio_url,
61 'title': title,
62 'description': description,
63 'duration': duration,
64 'timestamp': timestamp,
65 'uploader': uploader,
66 'uploader_id': uploader_id,
67 'view_count': view_count,
68 'comment_count': comment_count,
69 'categories': categories,
70 }