]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/everyonesmixtape.py
Initiate release.
[youtubedl] / youtube_dl / extractor / everyonesmixtape.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 compat_urllib_request,
8 ExtractorError,
9 )
10
11
12 class EveryonesMixtapeIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?everyonesmixtape\.com/#/mix/(?P<id>[0-9a-zA-Z]+)(?:/(?P<songnr>[0-9]))?$'
14
15 _TEST = {
16 'url': 'http://everyonesmixtape.com/#/mix/m7m0jJAbMQi/5',
17 'file': '5bfseWNmlds.mp4',
18 "info_dict": {
19 "title": "Passion Pit - \"Sleepyhead\" (Official Music Video)",
20 "uploader": "FKR.TV",
21 "uploader_id": "frenchkissrecords",
22 "description": "Music video for \"Sleepyhead\" from Passion Pit's debut EP Chunk Of Change.\nBuy on iTunes: https://itunes.apple.com/us/album/chunk-of-change-ep/id300087641\n\nDirected by The Wilderness.\n\nhttp://www.passionpitmusic.com\nhttp://www.frenchkissrecords.com",
23 "upload_date": "20081015"
24 },
25 'params': {
26 'skip_download': True, # This is simply YouTube
27 }
28 }
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 playlist_id = mobj.group('id')
33
34 pllist_url = 'http://everyonesmixtape.com/mixtape.php?a=getMixes&u=-1&linked=%s&explore=' % playlist_id
35 pllist_req = compat_urllib_request.Request(pllist_url)
36 pllist_req.add_header('X-Requested-With', 'XMLHttpRequest')
37
38 playlist_list = self._download_json(
39 pllist_req, playlist_id, note='Downloading playlist metadata')
40 try:
41 playlist_no = next(playlist['id']
42 for playlist in playlist_list
43 if playlist['code'] == playlist_id)
44 except StopIteration:
45 raise ExtractorError('Playlist id not found')
46
47 pl_url = 'http://everyonesmixtape.com/mixtape.php?a=getMix&id=%s&userId=null&code=' % playlist_no
48 pl_req = compat_urllib_request.Request(pl_url)
49 pl_req.add_header('X-Requested-With', 'XMLHttpRequest')
50 playlist = self._download_json(
51 pl_req, playlist_id, note='Downloading playlist info')
52
53 entries = [{
54 '_type': 'url',
55 'url': t['url'],
56 'title': t['title'],
57 } for t in playlist['tracks']]
58
59 if mobj.group('songnr'):
60 songnr = int(mobj.group('songnr')) - 1
61 return entries[songnr]
62
63 playlist_title = playlist['mixData']['name']
64 return {
65 '_type': 'playlist',
66 'id': playlist_id,
67 'title': playlist_title,
68 'entries': entries,
69 }