]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/clyp.py
[aljazeera] Extend _VALID_URL
[yt-dlp.git] / youtube_dl / extractor / clyp.py
CommitLineData
4e16c1f8
CR
1from __future__ import unicode_literals
2
4e16c1f8 3from .common import InfoExtractor
03c2c162
S
4from ..utils import (
5 float_or_none,
6 parse_iso8601,
7)
4e16c1f8
CR
8
9
10class ClypIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
03c2c162 12 _TEST = {
4e16c1f8
CR
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',
03c2c162
S
20 'duration': 263.21,
21 'timestamp': 1443515251,
22 'upload_date': '20150929',
4e16c1f8 23 },
03c2c162 24 }
4e16c1f8
CR
25
26 def _real_extract(self, url):
27 audio_id = self._match_id(url)
4e16c1f8 28
03c2c162
S
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)
4e16c1f8 44
03c2c162
S
45 title = metadata['Title']
46 description = metadata.get('Description')
47 duration = float_or_none(metadata.get('Duration'))
48 timestamp = parse_iso8601(metadata.get('DateCreated'))
4e16c1f8
CR
49
50 return {
51 'id': audio_id,
52 'title': title,
4e16c1f8 53 'description': description,
03c2c162
S
54 'duration': duration,
55 'timestamp': timestamp,
56 'formats': formats,
4e16c1f8 57 }