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