]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/clyp.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / clyp.py
1 from .common import InfoExtractor
2 from ..utils import (
3 float_or_none,
4 parse_qs,
5 unified_timestamp,
6 )
7
8
9 class ClypIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
11 _TESTS = [{
12 'url': 'https://clyp.it/ojz2wfah',
13 'md5': '1d4961036c41247ecfdcc439c0cddcbb',
14 'info_dict': {
15 'id': 'ojz2wfah',
16 'ext': 'mp3',
17 'title': 'Krisson80 - bits wip wip',
18 'description': '#Krisson80BitsWipWip #chiptune\n#wip',
19 'duration': 263.21,
20 'timestamp': 1443515251,
21 'upload_date': '20150929',
22 },
23 }, {
24 'url': 'https://clyp.it/b04p1odi?token=b0078e077e15835845c528a44417719d',
25 'info_dict': {
26 'id': 'b04p1odi',
27 'ext': 'mp3',
28 'title': 'GJ! (Reward Edit)',
29 'description': 'Metal Resistance (THE ONE edition)',
30 'duration': 177.789,
31 'timestamp': 1528241278,
32 'upload_date': '20180605',
33 },
34 'params': {
35 'skip_download': True,
36 },
37 }]
38
39 def _real_extract(self, url):
40 audio_id = self._match_id(url)
41
42 qs = parse_qs(url)
43 token = qs.get('token', [None])[0]
44
45 query = {}
46 if token:
47 query['token'] = token
48
49 metadata = self._download_json(
50 'https://api.clyp.it/%s' % audio_id, audio_id, query=query)
51
52 formats = []
53 for secure in ('', 'Secure'):
54 for ext in ('Ogg', 'Mp3'):
55 format_id = '%s%s' % (secure, ext)
56 format_url = metadata.get('%sUrl' % format_id)
57 if format_url:
58 formats.append({
59 'url': format_url,
60 'format_id': format_id,
61 'vcodec': 'none',
62 })
63
64 title = metadata['Title']
65 description = metadata.get('Description')
66 duration = float_or_none(metadata.get('Duration'))
67 timestamp = unified_timestamp(metadata.get('DateCreated'))
68
69 return {
70 'id': audio_id,
71 'title': title,
72 'description': description,
73 'duration': duration,
74 'timestamp': timestamp,
75 'formats': formats,
76 }