]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/clyp.py
Start new release.
[youtubedl] / youtube_dl / extractor / clyp.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import (
5 compat_parse_qs,
6 compat_urllib_parse_urlparse,
7 )
8 from ..utils import (
9 float_or_none,
10 unified_timestamp,
11 )
12
13
14 class ClypIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
16 _TESTS = [{
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',
24 'duration': 263.21,
25 'timestamp': 1443515251,
26 'upload_date': '20150929',
27 },
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 }]
43
44 def _real_extract(self, url):
45 audio_id = self._match_id(url)
46
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
54 metadata = self._download_json(
55 'https://api.clyp.it/%s' % audio_id, audio_id, query=query)
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)
69
70 title = metadata['Title']
71 description = metadata.get('Description')
72 duration = float_or_none(metadata.get('Duration'))
73 timestamp = unified_timestamp(metadata.get('DateCreated'))
74
75 return {
76 'id': audio_id,
77 'title': title,
78 'description': description,
79 'duration': duration,
80 'timestamp': timestamp,
81 'formats': formats,
82 }