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