logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

xminus.py (2937B)


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