You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class PlanetaPlayIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?planetaplay\.com/\?sng=(?P<id>[0-9]+)'
  8. _API_URL = 'http://planetaplay.com/action/playlist/?sng={0:}'
  9. _THUMBNAIL_URL = 'http://planetaplay.com/img/thumb/{thumb:}'
  10. _TEST = {
  11. 'url': 'http://planetaplay.com/?sng=3586',
  12. 'md5': '9d569dceb7251a4e01355d5aea60f9db',
  13. 'info_dict': {
  14. 'id': '3586',
  15. 'ext': 'flv',
  16. 'title': 'md5:e829428ee28b1deed00de90de49d1da1',
  17. }
  18. }
  19. _SONG_FORMATS = {
  20. 'lq': (0, 'http://www.planetaplay.com/videoplayback/{med_hash:}'),
  21. 'hq': (1, 'http://www.planetaplay.com/videoplayback/hi/{med_hash:}'),
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. response = self._download_json(
  27. self._API_URL.format(video_id), video_id)['response']
  28. try:
  29. data = response.get('data')[0]
  30. except IndexError:
  31. raise ExtractorError(
  32. '%s: failed to get the playlist' % self.IE_NAME, expected=True)
  33. title = '{song_artists:} - {sng_name:}'.format(**data)
  34. thumbnail = self._THUMBNAIL_URL.format(**data)
  35. formats = []
  36. for format_id, (quality, url_template) in self._SONG_FORMATS.items():
  37. formats.append({
  38. 'format_id': format_id,
  39. 'url': url_template.format(**data),
  40. 'quality': quality,
  41. 'ext': 'flv',
  42. })
  43. self._sort_formats(formats)
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'formats': formats,
  48. 'thumbnail': thumbnail,
  49. }