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