]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/planetaplay.py
Merge tag 'upstream/2015.11.27.1'
[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 'skip': 'Not accessible from Travis CI server',
23 }
24
25 _SONG_FORMATS = {
26 'lq': (0, 'http://www.planetaplay.com/videoplayback/{med_hash:}'),
27 'hq': (1, 'http://www.planetaplay.com/videoplayback/hi/{med_hash:}'),
28 }
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('id')
33
34 response = self._download_json(
35 self._API_URL.format(video_id), video_id)['response']
36 try:
37 data = response.get('data')[0]
38 except IndexError:
39 raise ExtractorError(
40 '%s: failed to get the playlist' % self.IE_NAME, expected=True)
41
42 title = '{song_artists:} - {sng_name:}'.format(**data)
43 thumbnail = self._THUMBNAIL_URL.format(**data)
44
45 formats = []
46 for format_id, (quality, url_template) in self._SONG_FORMATS.items():
47 formats.append({
48 'format_id': format_id,
49 'url': url_template.format(**data),
50 'quality': quality,
51 'ext': 'flv',
52 })
53
54 self._sort_formats(formats)
55
56 return {
57 'id': video_id,
58 'title': title,
59 'formats': formats,
60 'thumbnail': thumbnail,
61 }