]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/clyp.py
New upstream version 2018.06.18
[youtubedl] / youtube_dl / extractor / clyp.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5 float_or_none,
6 parse_iso8601,
7 )
8
9
10 class ClypIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
12 _TEST = {
13 'url': 'https://clyp.it/ojz2wfah',
14 'md5': '1d4961036c41247ecfdcc439c0cddcbb',
15 'info_dict': {
16 'id': 'ojz2wfah',
17 'ext': 'mp3',
18 'title': 'Krisson80 - bits wip wip',
19 'description': '#Krisson80BitsWipWip #chiptune\n#wip',
20 'duration': 263.21,
21 'timestamp': 1443515251,
22 'upload_date': '20150929',
23 },
24 }
25
26 def _real_extract(self, url):
27 audio_id = self._match_id(url)
28
29 metadata = self._download_json(
30 'https://api.clyp.it/%s' % audio_id, audio_id)
31
32 formats = []
33 for secure in ('', 'Secure'):
34 for ext in ('Ogg', 'Mp3'):
35 format_id = '%s%s' % (secure, ext)
36 format_url = metadata.get('%sUrl' % format_id)
37 if format_url:
38 formats.append({
39 'url': format_url,
40 'format_id': format_id,
41 'vcodec': 'none',
42 })
43 self._sort_formats(formats)
44
45 title = metadata['Title']
46 description = metadata.get('Description')
47 duration = float_or_none(metadata.get('Duration'))
48 timestamp = parse_iso8601(metadata.get('DateCreated'))
49
50 return {
51 'id': audio_id,
52 'title': title,
53 'description': description,
54 'duration': duration,
55 'timestamp': timestamp,
56 'formats': formats,
57 }