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