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.

67 lines
2.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_chr,
  6. compat_ord,
  7. )
  8. from ..utils import (
  9. int_or_none,
  10. parse_filesize,
  11. )
  12. class XMinusIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?x-minus\.org/track/(?P<id>[0-9]+)'
  14. _TEST = {
  15. 'url': 'http://x-minus.org/track/4542/%D0%BF%D0%B5%D1%81%D0%B5%D0%BD%D0%BA%D0%B0-%D1%88%D0%BE%D1%84%D0%B5%D1%80%D0%B0.html',
  16. 'md5': '401a15f2d2dcf6d592cb95528d72a2a8',
  17. 'info_dict': {
  18. 'id': '4542',
  19. 'ext': 'mp3',
  20. 'title': 'Леонид Агутин-Песенка шофера',
  21. 'duration': 156,
  22. 'tbr': 320,
  23. 'filesize_approx': 5900000,
  24. 'view_count': int,
  25. }
  26. }
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(url, video_id)
  30. artist = self._html_search_regex(
  31. r'minus_track\.artist="(.+?)"', webpage, 'artist')
  32. title = artist + '-' + self._html_search_regex(
  33. r'minus_track\.title="(.+?)"', webpage, 'title')
  34. duration = int_or_none(self._html_search_regex(
  35. r'minus_track\.dur_sec=\'([0-9]*?)\'',
  36. webpage, 'duration', fatal=False))
  37. filesize_approx = parse_filesize(self._html_search_regex(
  38. r'<div class="filesize[^"]*"></div>\s*([0-9.]+\s*[a-zA-Z][bB])',
  39. webpage, 'approximate filesize', fatal=False))
  40. tbr = int_or_none(self._html_search_regex(
  41. r'<div class="quality[^"]*"></div>\s*([0-9]+)\s*kbps',
  42. webpage, 'bitrate', fatal=False))
  43. view_count = int_or_none(self._html_search_regex(
  44. r'<div class="quality.*?► ([0-9]+)',
  45. webpage, 'view count', fatal=False))
  46. enc_token = self._html_search_regex(
  47. r'data-mt="(.*?)"', webpage, 'enc_token')
  48. token = ''.join(
  49. c if pos == 3 else compat_chr(compat_ord(c) - 1)
  50. for pos, c in enumerate(reversed(enc_token)))
  51. video_url = 'http://x-minus.org/dwlf/%s/%s.mp3' % (video_id, token)
  52. return {
  53. 'id': video_id,
  54. 'title': title,
  55. 'url': video_url,
  56. 'duration': duration,
  57. 'filesize_approx': filesize_approx,
  58. 'tbr': tbr,
  59. 'view_count': view_count,
  60. }