]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/planetaplay.py
596c621d75067255f5be6e4eaf97ba897cc51fe5
[youtubedl] / youtube_dl / extractor / planetaplay.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 ExtractorError
8
9
10 class PlanetaPlayIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?planetaplay\.com/\?sng=(?P<id>[0-9]+)'
12 _API_URL = 'http://planetaplay.com/action/playlist/?sng={0:}'
13 _THUMBNAIL_URL = 'http://planetaplay.com/img/thumb/{thumb:}'
14 _TEST = {
15 'url': 'http://planetaplay.com/?sng=3586',
16 'md5': '9d569dceb7251a4e01355d5aea60f9db',
17 'info_dict': {
18 'id': '3586',
19 'ext': 'flv',
20 'title': 'md5:e829428ee28b1deed00de90de49d1da1',
21 }
22 }
23
24 _SONG_FORMATS = {
25 'lq': (0, 'http://www.planetaplay.com/videoplayback/{med_hash:}'),
26 'hq': (1, 'http://www.planetaplay.com/videoplayback/hi/{med_hash:}'),
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32
33 response = self._download_json(
34 self._API_URL.format(video_id), video_id)['response']
35 try:
36 data = response.get('data')[0]
37 except IndexError:
38 raise ExtractorError(
39 '%s: failed to get the playlist' % self.IE_NAME, expected=True)
40
41 title = '{song_artists:} - {sng_name:}'.format(**data)
42 thumbnail = self._THUMBNAIL_URL.format(**data)
43
44 formats = []
45 for format_id, (quality, url_template) in self._SONG_FORMATS.items():
46 formats.append({
47 'format_id': format_id,
48 'url': url_template.format(**data),
49 'quality': quality,
50 'ext': 'flv',
51 })
52
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': title,
58 'formats': formats,
59 'thumbnail': thumbnail,
60 }