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. _WORKING = False
  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. 'description': 'md5:03238c5b663810bc79cf42ef3c03e371',
  26. },
  27. }
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. webpage = self._download_webpage(url, video_id)
  31. artist = self._html_search_regex(
  32. r'<a[^>]+href="/artist/\d+">([^<]+)</a>', webpage, 'artist')
  33. title = artist + '-' + self._html_search_regex(
  34. r'<span[^>]+class="minustrack-full-title(?:\s+[^"]+)?"[^>]*>([^<]+)', webpage, 'title')
  35. duration = parse_duration(self._html_search_regex(
  36. r'<span[^>]+class="player-duration(?:\s+[^"]+)?"[^>]*>([^<]+)',
  37. webpage, 'duration', fatal=False))
  38. mobj = re.search(
  39. r'<div[^>]+class="dw-info(?:\s+[^"]+)?"[^>]*>(?P<tbr>\d+)\s*кбит/c\s+(?P<filesize>[0-9.]+)\s*мб</div>',
  40. webpage)
  41. tbr = filesize_approx = None
  42. if mobj:
  43. filesize_approx = float(mobj.group('filesize')) * 1000000
  44. tbr = float(mobj.group('tbr'))
  45. view_count = int_or_none(self._html_search_regex(
  46. r'<span><[^>]+class="icon-chart-bar".*?>(\d+)</span>',
  47. webpage, 'view count', fatal=False))
  48. description = self._html_search_regex(
  49. r'(?s)<pre[^>]+id="lyrics-original"[^>]*>(.*?)</pre>',
  50. webpage, 'song lyrics', fatal=False)
  51. if description:
  52. description = re.sub(' *\r *', '\n', description)
  53. k = self._search_regex(
  54. r'<div[^>]+id="player-bottom"[^>]+data-k="([^"]+)">', webpage,
  55. 'encoded data')
  56. h = time.time() / 3600
  57. a = sum(map(int, [compat_ord(c) for c in k])) + int(video_id) + h
  58. video_url = 'http://x-minus.me/dl/minus?id=%s&tkn2=%df%d' % (video_id, a, h)
  59. return {
  60. 'id': video_id,
  61. 'title': title,
  62. 'url': video_url,
  63. # The extension is unknown until actual downloading
  64. 'ext': 'mp3',
  65. 'duration': duration,
  66. 'filesize_approx': filesize_approx,
  67. 'tbr': tbr,
  68. 'view_count': view_count,
  69. 'description': description,
  70. }