xminus.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import re
  2. import time
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_ord,
  6. )
  7. from ..utils import (
  8. int_or_none,
  9. parse_duration,
  10. )
  11. class XMinusIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?x-minus\.org/track/(?P<id>[0-9]+)'
  13. _TEST = {
  14. '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',
  15. 'md5': '401a15f2d2dcf6d592cb95528d72a2a8',
  16. 'info_dict': {
  17. 'id': '4542',
  18. 'ext': 'mp3',
  19. 'title': 'Леонид Агутин-Песенка шофёра',
  20. 'duration': 156,
  21. 'tbr': 320,
  22. 'filesize_approx': 5900000,
  23. 'view_count': int,
  24. 'description': 'md5:03238c5b663810bc79cf42ef3c03e371',
  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'<a[^>]+href="/artist/\d+">([^<]+)</a>', webpage, 'artist')
  32. title = artist + '-' + self._html_search_regex(
  33. r'<span[^>]+class="minustrack-full-title(?:\s+[^"]+)?"[^>]*>([^<]+)', webpage, 'title')
  34. duration = parse_duration(self._html_search_regex(
  35. r'<span[^>]+class="player-duration(?:\s+[^"]+)?"[^>]*>([^<]+)',
  36. webpage, 'duration', fatal=False))
  37. mobj = re.search(
  38. r'<div[^>]+class="dw-info(?:\s+[^"]+)?"[^>]*>(?P<tbr>\d+)\s*кбит/c\s+(?P<filesize>[0-9.]+)\s*мб</div>',
  39. webpage)
  40. tbr = filesize_approx = None
  41. if mobj:
  42. filesize_approx = float(mobj.group('filesize')) * 1000000
  43. tbr = float(mobj.group('tbr'))
  44. view_count = int_or_none(self._html_search_regex(
  45. r'<span><[^>]+class="icon-chart-bar".*?>(\d+)</span>',
  46. webpage, 'view count', fatal=False))
  47. description = self._html_search_regex(
  48. r'(?s)<pre[^>]+id="lyrics-original"[^>]*>(.*?)</pre>',
  49. webpage, 'song lyrics', fatal=False)
  50. if description:
  51. description = re.sub(' *\r *', '\n', description)
  52. k = self._search_regex(
  53. r'<div[^>]+id="player-bottom"[^>]+data-k="([^"]+)">', webpage,
  54. 'encoded data')
  55. h = time.time() / 3600
  56. a = sum(map(int, [compat_ord(c) for c in k])) + int(video_id) + h
  57. video_url = 'http://x-minus.me/dl/minus?id=%s&tkn2=%df%d' % (video_id, a, h)
  58. return {
  59. 'id': video_id,
  60. 'title': title,
  61. 'url': video_url,
  62. # The extension is unknown until actual downloading
  63. 'ext': 'mp3',
  64. 'duration': duration,
  65. 'filesize_approx': filesize_approx,
  66. 'tbr': tbr,
  67. 'view_count': view_count,
  68. 'description': description,
  69. }