]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/playfm.py
Update changelog.
[youtubedl] / youtube_dl / extractor / playfm.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_urllib_parse,
9 compat_urllib_request,
10 )
11 from ..utils import (
12 ExtractorError,
13 float_or_none,
14 int_or_none,
15 str_to_int,
16 )
17
18
19 class PlayFMIE(InfoExtractor):
20 IE_NAME = 'play.fm'
21 _VALID_URL = r'https?://(?:www\.)?play\.fm/[^?#]*(?P<upload_date>[0-9]{8})(?P<id>[0-9]{6})(?:$|[?#])'
22
23 _TEST = {
24 'url': 'http://www.play.fm/recording/leipzigelectronicmusicbatofarparis_fr20140712137220',
25 'md5': 'c505f8307825a245d0c7ad1850001f22',
26 'info_dict': {
27 'id': '137220',
28 'ext': 'mp3',
29 'title': 'LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12',
30 'uploader': 'Sven Tasnadi',
31 'uploader_id': 'sventasnadi',
32 'duration': 5627.428,
33 'upload_date': '20140712',
34 'view_count': int,
35 'comment_count': int,
36 'thumbnail': 're:^https?://.*\.jpg$',
37 },
38 }
39
40 def _real_extract(self, url):
41 mobj = re.match(self._VALID_URL, url)
42 video_id = mobj.group('id')
43 upload_date = mobj.group('upload_date')
44
45 rec_data = compat_urllib_parse.urlencode({'rec_id': video_id})
46 req = compat_urllib_request.Request(
47 'http://www.play.fm/flexRead/recording', data=rec_data)
48 req.add_header('Content-Type', 'application/x-www-form-urlencoded')
49 rec_doc = self._download_xml(req, video_id)
50
51 error_node = rec_doc.find('./error')
52 if error_node is not None:
53 raise ExtractorError('An error occured: %s (code %s)' % (
54 error_node.text, rec_doc.find('./status').text))
55
56 recording = rec_doc.find('./recording')
57 title = recording.find('./title').text
58 view_count = str_to_int(recording.find('./stats/playcount').text)
59 comment_count = str_to_int(recording.find('./stats/comments').text)
60 duration = float_or_none(recording.find('./duration').text, scale=1000)
61 thumbnail = recording.find('./image').text
62
63 artist = recording.find('./artists/artist')
64 uploader = artist.find('./name').text
65 uploader_id = artist.find('./slug').text
66
67 video_url = '%s//%s/%s/%s/offset/0/sh/%s/rec/%s/jingle/%s/loc/%s' % (
68 'http:', recording.find('./url').text,
69 recording.find('./_class').text, recording.find('./file_id').text,
70 rec_doc.find('./uuid').text, video_id,
71 rec_doc.find('./jingle/file_id').text,
72 'http%3A%2F%2Fwww.play.fm%2Fplayer',
73 )
74
75 return {
76 'id': video_id,
77 'url': video_url,
78 'ext': 'mp3',
79 'filesize': int_or_none(recording.find('./size').text),
80 'title': title,
81 'upload_date': upload_date,
82 'view_count': view_count,
83 'comment_count': comment_count,
84 'duration': duration,
85 'thumbnail': thumbnail,
86 'uploader': uploader,
87 'uploader_id': uploader_id,
88 }