]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xminus.py
f7e2e8ac9594ef45a1d329c6359e447796b70f4b
[youtubedl] / youtube_dl / extractor / xminus.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
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
14
15 class XMinusIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?x-minus\.org/track/(?P<id>[0-9]+)'
17 _TEST = {
18 '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',
19 'md5': '401a15f2d2dcf6d592cb95528d72a2a8',
20 'info_dict': {
21 'id': '4542',
22 'ext': 'mp3',
23 'title': 'Леонид Агутин-Песенка шофера',
24 'duration': 156,
25 'tbr': 320,
26 'filesize_approx': 5900000,
27 'view_count': int,
28 }
29 }
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 webpage = self._download_webpage(url, video_id)
34
35 artist = self._html_search_regex(
36 r'minus_track\.artist="(.+?)"', webpage, 'artist')
37 title = artist + '-' + self._html_search_regex(
38 r'minus_track\.title="(.+?)"', webpage, 'title')
39 duration = int_or_none(self._html_search_regex(
40 r'minus_track\.dur_sec=\'([0-9]*?)\'',
41 webpage, 'duration', fatal=False))
42 filesize_approx = parse_filesize(self._html_search_regex(
43 r'<div class="filesize[^"]*"></div>\s*([0-9.]+\s*[a-zA-Z][bB])',
44 webpage, 'approximate filesize', fatal=False))
45 tbr = int_or_none(self._html_search_regex(
46 r'<div class="quality[^"]*"></div>\s*([0-9]+)\s*kbps',
47 webpage, 'bitrate', fatal=False))
48 view_count = int_or_none(self._html_search_regex(
49 r'<div class="quality.*?► ([0-9]+)',
50 webpage, 'view count', fatal=False))
51
52 enc_token = self._html_search_regex(
53 r'minus_track\.tkn="(.+?)"', webpage, 'enc_token')
54 token = ''.join(
55 c if pos == 3 else compat_chr(compat_ord(c) - 1)
56 for pos, c in enumerate(reversed(enc_token)))
57 video_url = 'http://x-minus.org/dwlf/%s/%s.mp3' % (video_id, token)
58
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 }