[ie/twitter:spaces] Support video spaces (#10789)
[yt-dlp3.git] / yt_dlp / extractor / xminus.py
blobaf9cf40abd2f454dcdc2d6120a15f4ac650c3a4c
1 import re
2 import time
4 from .common import InfoExtractor
5 from ..compat import (
6 compat_ord,
8 from ..utils import (
9 int_or_none,
10 parse_duration,
14 class XMinusIE(InfoExtractor):
15 _WORKING = False
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 'description': 'md5:03238c5b663810bc79cf42ef3c03e371',
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34 webpage = self._download_webpage(url, video_id)
36 artist = self._html_search_regex(
37 r'<a[^>]+href="/artist/\d+">([^<]+)</a>', webpage, 'artist')
38 title = artist + '-' + self._html_search_regex(
39 r'<span[^>]+class="minustrack-full-title(?:\s+[^"]+)?"[^>]*>([^<]+)', webpage, 'title')
40 duration = parse_duration(self._html_search_regex(
41 r'<span[^>]+class="player-duration(?:\s+[^"]+)?"[^>]*>([^<]+)',
42 webpage, 'duration', fatal=False))
43 mobj = re.search(
44 r'<div[^>]+class="dw-info(?:\s+[^"]+)?"[^>]*>(?P<tbr>\d+)\s*кбит/c\s+(?P<filesize>[0-9.]+)\s*мб</div>',
45 webpage)
46 tbr = filesize_approx = None
47 if mobj:
48 filesize_approx = float(mobj.group('filesize')) * 1000000
49 tbr = float(mobj.group('tbr'))
50 view_count = int_or_none(self._html_search_regex(
51 r'<span><[^>]+class="icon-chart-bar".*?>(\d+)</span>',
52 webpage, 'view count', fatal=False))
53 description = self._html_search_regex(
54 r'(?s)<pre[^>]+id="lyrics-original"[^>]*>(.*?)</pre>',
55 webpage, 'song lyrics', fatal=False)
56 if description:
57 description = re.sub(' *\r *', '\n', description)
59 k = self._search_regex(
60 r'<div[^>]+id="player-bottom"[^>]+data-k="([^"]+)">', webpage,
61 'encoded data')
62 h = time.time() / 3600
63 a = sum(map(int, [compat_ord(c) for c in k])) + int(video_id) + h
64 video_url = 'http://x-minus.me/dl/minus?id=%s&tkn2=%df%d' % (video_id, a, h)
66 return {
67 'id': video_id,
68 'title': title,
69 'url': video_url,
70 # The extension is unknown until actual downloading
71 'ext': 'mp3',
72 'duration': duration,
73 'filesize_approx': filesize_approx,
74 'tbr': tbr,
75 'view_count': view_count,
76 'description': description,