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