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