2 from __future__ import unicode_literals
6 from .common import InfoExtractor
18 class TapelyIE(InfoExtractor):
19 _VALID_URL = r'https?://(?:www\.)?tape\.ly/(?P<id>[A-Za-z0-9\-_]+)(?:/(?P<songnr>\d+))?'
20 _API_URL = 'http://tape.ly/showtape?id={0:}'
21 _S3_SONG_URL = 'http://mytape.s3.amazonaws.com/{0:}'
22 _SOUNDCLOUD_SONG_URL = 'http://api.soundcloud.com{0:}'
25 'url': 'http://tape.ly/my-grief-as-told-by-water',
28 'title': 'my grief as told by water',
29 'thumbnail': 're:^https?://.*\.png$',
31 'timestamp': 1411848286,
32 'description': 'For Robin and Ponkers, whom the tides of life have taken out to sea.',
37 'url': 'http://tape.ly/my-grief-as-told-by-water/1',
38 'md5': '79031f459fdec6530663b854cbc5715c',
41 'title': 'Dreaming Awake (My Brightest Diamond)',
47 def _real_extract(self, url):
48 mobj = re.match(self._VALID_URL, url)
49 display_id = mobj.group('id')
51 playlist_url = self._API_URL.format(display_id)
52 request = compat_urllib_request.Request(playlist_url)
53 request.add_header('X-Requested-With', 'XMLHttpRequest')
54 request.add_header('Accept', 'application/json')
55 request.add_header('Referer', url)
57 playlist = self._download_json(request, display_id)
59 tape = playlist['tape']
62 for s in tape['songs']:
66 'duration': float_or_none(song.get('songduration'), 1000),
67 'title': song['title'],
69 if song['source'] == 'S3':
71 'url': self._S3_SONG_URL.format(song['filename']),
74 elif song['source'] == 'YT':
75 self.to_screen('YouTube video detected')
76 yt_id = song['filename'].replace('/youtube/', '')
77 entry.update(self.url_result(yt_id, 'Youtube', video_id=yt_id))
79 elif song['source'] == 'SC':
80 self.to_screen('SoundCloud song detected')
81 sc_url = self._SOUNDCLOUD_SONG_URL.format(song['filename'])
82 entry.update(self.url_result(sc_url, 'Soundcloud'))
85 self.report_warning('Unknown song source: %s' % song['source'])
87 if mobj.group('songnr'):
88 songnr = int(mobj.group('songnr')) - 1
90 return entries[songnr]
93 'No song with index: %s' % mobj.group('songnr'),
99 'display_id': display_id,
100 'title': tape['name'],
102 'thumbnail': tape.get('image_url'),
103 'description': clean_html(tape.get('subtext')),
104 'like_count': tape.get('likescount'),
105 'uploader_id': tape.get('user_id'),
106 'timestamp': parse_iso8601(tape.get('published_at')),