]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/chirbit.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / chirbit.py
1 import re
2
3 from .common import InfoExtractor
4 from ..compat import compat_b64decode
5 from ..utils import parse_duration
6
7
8 class ChirbitIE(InfoExtractor):
9 IE_NAME = 'chirbit'
10 _VALID_URL = r'https?://(?:www\.)?chirb\.it/(?:(?:wp|pl)/|fb_chirbit_player\.swf\?key=)?(?P<id>[\da-zA-Z]+)'
11 _TESTS = [{
12 'url': 'http://chirb.it/be2abG',
13 'info_dict': {
14 'id': 'be2abG',
15 'ext': 'mp3',
16 'title': 'md5:f542ea253f5255240be4da375c6a5d7e',
17 'description': 'md5:f24a4e22a71763e32da5fed59e47c770',
18 'duration': 306,
19 'uploader': 'Gerryaudio',
20 },
21 'params': {
22 'skip_download': True,
23 }
24 }, {
25 'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
26 'only_matching': True,
27 }, {
28 'url': 'https://chirb.it/wp/MN58c2',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 audio_id = self._match_id(url)
34
35 webpage = self._download_webpage(
36 'http://chirb.it/%s' % audio_id, audio_id)
37
38 data_fd = self._search_regex(
39 r'data-fd=(["\'])(?P<url>(?:(?!\1).)+)\1',
40 webpage, 'data fd', group='url')
41
42 # Reverse engineered from https://chirb.it/js/chirbit.player.js (look
43 # for soundURL)
44 audio_url = compat_b64decode(data_fd[::-1]).decode('utf-8')
45
46 title = self._search_regex(
47 r'class=["\']chirbit-title["\'][^>]*>([^<]+)', webpage, 'title')
48 description = self._search_regex(
49 r'<h3>Description</h3>\s*<pre[^>]*>([^<]+)</pre>',
50 webpage, 'description', default=None)
51 duration = parse_duration(self._search_regex(
52 r'class=["\']c-length["\'][^>]*>([^<]+)',
53 webpage, 'duration', fatal=False))
54 uploader = self._search_regex(
55 r'id=["\']chirbit-username["\'][^>]*>([^<]+)',
56 webpage, 'uploader', fatal=False)
57
58 return {
59 'id': audio_id,
60 'url': audio_url,
61 'title': title,
62 'description': description,
63 'duration': duration,
64 'uploader': uploader,
65 }
66
67
68 class ChirbitProfileIE(InfoExtractor):
69 IE_NAME = 'chirbit:profile'
70 _VALID_URL = r'https?://(?:www\.)?chirbit\.com/(?:rss/)?(?P<id>[^/]+)'
71 _TEST = {
72 'url': 'http://chirbit.com/ScarletBeauty',
73 'info_dict': {
74 'id': 'ScarletBeauty',
75 },
76 'playlist_mincount': 3,
77 }
78
79 def _real_extract(self, url):
80 profile_id = self._match_id(url)
81
82 webpage = self._download_webpage(url, profile_id)
83
84 entries = [
85 self.url_result(self._proto_relative_url('//chirb.it/' + video_id))
86 for _, video_id in re.findall(r'<input[^>]+id=([\'"])copy-btn-(?P<id>[0-9a-zA-Z]+)\1', webpage)]
87
88 return self.playlist_result(entries, profile_id)