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