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.

76 lines
2.7 KiB

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