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