]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/everyonesmixtape.py
Annotate changelog bug being closed.
[youtubedl] / youtube_dl / extractor / everyonesmixtape.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_urllib_request,
8 )
9 from ..utils import (
10 ExtractorError,
11 )
12
13
14 class EveryonesMixtapeIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?everyonesmixtape\.com/#/mix/(?P<id>[0-9a-zA-Z]+)(?:/(?P<songnr>[0-9]))?$'
16
17 _TESTS = [{
18 'url': 'http://everyonesmixtape.com/#/mix/m7m0jJAbMQi/5',
19 "info_dict": {
20 'id': '5bfseWNmlds',
21 'ext': 'mp4',
22 "title": "Passion Pit - \"Sleepyhead\" (Official Music Video)",
23 "uploader": "FKR.TV",
24 "uploader_id": "frenchkissrecords",
25 "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",
26 "upload_date": "20081015"
27 },
28 'params': {
29 'skip_download': True, # This is simply YouTube
30 }
31 }, {
32 'url': 'http://everyonesmixtape.com/#/mix/m7m0jJAbMQi',
33 'info_dict': {
34 'id': 'm7m0jJAbMQi',
35 'title': 'Driving',
36 },
37 'playlist_count': 24
38 }]
39
40 def _real_extract(self, url):
41 mobj = re.match(self._VALID_URL, url)
42 playlist_id = mobj.group('id')
43
44 pllist_url = 'http://everyonesmixtape.com/mixtape.php?a=getMixes&u=-1&linked=%s&explore=' % playlist_id
45 pllist_req = compat_urllib_request.Request(pllist_url)
46 pllist_req.add_header('X-Requested-With', 'XMLHttpRequest')
47
48 playlist_list = self._download_json(
49 pllist_req, playlist_id, note='Downloading playlist metadata')
50 try:
51 playlist_no = next(playlist['id']
52 for playlist in playlist_list
53 if playlist['code'] == playlist_id)
54 except StopIteration:
55 raise ExtractorError('Playlist id not found')
56
57 pl_url = 'http://everyonesmixtape.com/mixtape.php?a=getMix&id=%s&userId=null&code=' % playlist_no
58 pl_req = compat_urllib_request.Request(pl_url)
59 pl_req.add_header('X-Requested-With', 'XMLHttpRequest')
60 playlist = self._download_json(
61 pl_req, playlist_id, note='Downloading playlist info')
62
63 entries = [{
64 '_type': 'url',
65 'url': t['url'],
66 'title': t['title'],
67 } for t in playlist['tracks']]
68
69 if mobj.group('songnr'):
70 songnr = int(mobj.group('songnr')) - 1
71 return entries[songnr]
72
73 playlist_title = playlist['mixData']['name']
74 return {
75 '_type': 'playlist',
76 'id': playlist_id,
77 'title': playlist_title,
78 'entries': entries,
79 }