]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tapely.py
283e11350b212db0c857f1ccdb8982519a78cfbb
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
10 compat_urllib_request
,
16 class TapelyIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?tape\.ly/(?P<id>[A-Za-z0-9\-_]+)(?:/(?P<songnr>\d+))?'
18 _API_URL
= 'http://tape.ly/showtape?id={0:}'
19 _S3_SONG_URL
= 'http://mytape.s3.amazonaws.com/{0:}'
20 _SOUNDCLOUD_SONG_URL
= 'http://api.soundcloud.com{0:}'
23 'url': 'http://tape.ly/my-grief-as-told-by-water',
26 'title': 'my grief as told by water',
27 'thumbnail': 're:^https?://.*\.png$',
29 'timestamp': 1411848286,
30 'description': 'For Robin and Ponkers, whom the tides of life have taken out to sea.',
35 'url': 'http://tape.ly/my-grief-as-told-by-water/1',
36 'md5': '79031f459fdec6530663b854cbc5715c',
39 'title': 'Dreaming Awake (My Brightest Diamond)',
45 def _real_extract(self
, url
):
46 mobj
= re
.match(self
._VALID
_URL
, url
)
47 display_id
= mobj
.group('id')
49 playlist_url
= self
._API
_URL
.format(display_id
)
50 request
= compat_urllib_request
.Request(playlist_url
)
51 request
.add_header('X-Requested-With', 'XMLHttpRequest')
52 request
.add_header('Accept', 'application/json')
53 request
.add_header('Referer', url
)
55 playlist
= self
._download
_json
(request
, display_id
)
57 tape
= playlist
['tape']
60 for s
in tape
['songs']:
64 'duration': float_or_none(song
.get('songduration'), 1000),
65 'title': song
['title'],
67 if song
['source'] == 'S3':
69 'url': self
._S
3_SONG
_URL
.format(song
['filename']),
72 elif song
['source'] == 'YT':
73 self
.to_screen('YouTube video detected')
74 yt_id
= song
['filename'].replace('/youtube/', '')
75 entry
.update(self
.url_result(yt_id
, 'Youtube', video_id
=yt_id
))
77 elif song
['source'] == 'SC':
78 self
.to_screen('SoundCloud song detected')
79 sc_url
= self
._SOUNDCLOUD
_SONG
_URL
.format(song
['filename'])
80 entry
.update(self
.url_result(sc_url
, 'Soundcloud'))
83 self
.report_warning('Unknown song source: %s' % song
['source'])
85 if mobj
.group('songnr'):
86 songnr
= int(mobj
.group('songnr')) - 1
88 return entries
[songnr
]
91 'No song with index: %s' % mobj
.group('songnr'),
97 'display_id': display_id
,
98 'title': tape
['name'],
100 'thumbnail': tape
.get('image_url'),
101 'description': clean_html(tape
.get('subtext')),
102 'like_count': tape
.get('likescount'),
103 'uploader_id': tape
.get('user_id'),
104 'timestamp': parse_iso8601(tape
.get('published_at')),