]>
Commit | Line | Data |
---|---|---|
4e16c1f8 | 1 | from .common import InfoExtractor |
03c2c162 S |
2 | from ..utils import ( |
3 | float_or_none, | |
4dfbf869 | 4 | parse_qs, |
d37dc6e1 | 5 | unified_timestamp, |
03c2c162 | 6 | ) |
4e16c1f8 CR |
7 | |
8 | ||
9 | class ClypIE(InfoExtractor): | |
10 | _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)' | |
d37dc6e1 | 11 | _TESTS = [{ |
4e16c1f8 CR |
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', | |
03c2c162 S |
19 | 'duration': 263.21, |
20 | 'timestamp': 1443515251, | |
21 | 'upload_date': '20150929', | |
4e16c1f8 | 22 | }, |
d37dc6e1 S |
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 | }] | |
4e16c1f8 CR |
38 | |
39 | def _real_extract(self, url): | |
40 | audio_id = self._match_id(url) | |
4e16c1f8 | 41 | |
4dfbf869 | 42 | qs = parse_qs(url) |
d37dc6e1 S |
43 | token = qs.get('token', [None])[0] |
44 | ||
45 | query = {} | |
46 | if token: | |
47 | query['token'] = token | |
48 | ||
03c2c162 | 49 | metadata = self._download_json( |
d37dc6e1 | 50 | 'https://api.clyp.it/%s' % audio_id, audio_id, query=query) |
03c2c162 S |
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 | self._sort_formats(formats) | |
4e16c1f8 | 64 | |
03c2c162 S |
65 | title = metadata['Title'] |
66 | description = metadata.get('Description') | |
67 | duration = float_or_none(metadata.get('Duration')) | |
d37dc6e1 | 68 | timestamp = unified_timestamp(metadata.get('DateCreated')) |
4e16c1f8 CR |
69 | |
70 | return { | |
71 | 'id': audio_id, | |
72 | 'title': title, | |
4e16c1f8 | 73 | 'description': description, |
03c2c162 S |
74 | 'duration': duration, |
75 | 'timestamp': timestamp, | |
76 | 'formats': formats, | |
4e16c1f8 | 77 | } |