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.

53 lines
1.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class XMinusIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?x-minus\.org/track/(?P<id>[0-9]+)'
  7. _TEST = {
  8. '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',
  9. 'md5': '401a15f2d2dcf6d592cb95528d72a2a8',
  10. 'info_dict': {
  11. 'id': '4542',
  12. 'ext': 'mp3',
  13. 'title': 'Леонид Агутин-Песенка шофера',
  14. 'duration': 156,
  15. }
  16. }
  17. def _real_extract(self, url):
  18. video_id = self._match_id(url)
  19. # TODO more code goes here, for example ...
  20. webpage = self._download_webpage(url, video_id)
  21. artist = self._html_search_regex(
  22. r'minus_track.artist="(.+?)"', webpage, 'artist')
  23. title = artist + '-' + self._html_search_regex(
  24. r'minus_track.title="(.+?)"', webpage, 'title')
  25. duration = int_or_none(self._html_search_regex(
  26. r'minus_track.dur_sec=\'([0-9]+?)\'', webpage, 'duration'))
  27. enc_token = self._html_search_regex(
  28. r'data-mt="(.*?)"', webpage, 'enc_token')
  29. token = self._decode_token(enc_token)
  30. url = 'http://x-minus.org/dwlf/{}/{}.mp3'.format(video_id, token)
  31. return {
  32. 'id': video_id,
  33. 'title': title,
  34. 'url': url,
  35. 'duration': duration,
  36. }
  37. def _decode_token(self, enc_token):
  38. token = ''
  39. pos = 0
  40. for c in reversed(enc_token):
  41. if pos != 3:
  42. token += chr(ord(c) - 1)
  43. else:
  44. token += c
  45. pos += 1
  46. return token