2014-01-16 20:53:34 -05:00
from __future__ import unicode_literals
import re
from . common import InfoExtractor
2014-12-13 06:24:42 -05:00
from . . utils import (
2014-01-16 20:53:34 -05:00
ExtractorError ,
2015-11-21 11:18:17 -05:00
sanitized_Request ,
2014-01-16 20:53:34 -05:00
)
class EveryonesMixtapeIE ( InfoExtractor ) :
_VALID_URL = r ' https?://(?:www \ .)?everyonesmixtape \ .com/#/mix/(?P<id>[0-9a-zA-Z]+)(?:/(?P<songnr>[0-9]))?$ '
2014-08-27 18:58:24 -04:00
_TESTS = [ {
2014-01-16 20:53:34 -05:00
' url ' : ' http://everyonesmixtape.com/#/mix/m7m0jJAbMQi/5 ' ,
" info_dict " : {
2014-08-27 18:58:24 -04:00
' id ' : ' 5bfseWNmlds ' ,
' ext ' : ' mp4 ' ,
2014-01-16 20:53:34 -05:00
" title " : " Passion Pit - \" Sleepyhead \" (Official Music Video) " ,
" uploader " : " FKR.TV " ,
" uploader_id " : " frenchkissrecords " ,
" description " : " Music video for \" Sleepyhead \" from Passion Pit ' s debut EP Chunk Of Change. \n Buy on iTunes: https://itunes.apple.com/us/album/chunk-of-change-ep/id300087641 \n \n Directed by The Wilderness. \n \n http://www.passionpitmusic.com \n http://www.frenchkissrecords.com " ,
" upload_date " : " 20081015 "
} ,
' params ' : {
' skip_download ' : True , # This is simply YouTube
}
2014-08-27 18:58:24 -04:00
} , {
' url ' : ' http://everyonesmixtape.com/#/mix/m7m0jJAbMQi ' ,
' info_dict ' : {
' id ' : ' m7m0jJAbMQi ' ,
' title ' : ' Driving ' ,
} ,
' playlist_count ' : 24
} ]
2014-01-16 20:53:34 -05:00
def _real_extract ( self , url ) :
mobj = re . match ( self . _VALID_URL , url )
playlist_id = mobj . group ( ' id ' )
pllist_url = ' http://everyonesmixtape.com/mixtape.php?a=getMixes&u=-1&linked= %s &explore= ' % playlist_id
2015-11-21 11:18:17 -05:00
pllist_req = sanitized_Request ( pllist_url )
2014-01-16 20:53:34 -05:00
pllist_req . add_header ( ' X-Requested-With ' , ' XMLHttpRequest ' )
playlist_list = self . _download_json (
pllist_req , playlist_id , note = ' Downloading playlist metadata ' )
try :
playlist_no = next ( playlist [ ' id ' ]
for playlist in playlist_list
if playlist [ ' code ' ] == playlist_id )
except StopIteration :
raise ExtractorError ( ' Playlist id not found ' )
pl_url = ' http://everyonesmixtape.com/mixtape.php?a=getMix&id= %s &userId=null&code= ' % playlist_no
2015-11-21 11:18:17 -05:00
pl_req = sanitized_Request ( pl_url )
2014-01-16 20:53:34 -05:00
pl_req . add_header ( ' X-Requested-With ' , ' XMLHttpRequest ' )
playlist = self . _download_json (
pl_req , playlist_id , note = ' Downloading playlist info ' )
entries = [ {
' _type ' : ' url ' ,
' url ' : t [ ' url ' ] ,
' title ' : t [ ' title ' ] ,
} for t in playlist [ ' tracks ' ] ]
if mobj . group ( ' songnr ' ) :
songnr = int ( mobj . group ( ' songnr ' ) ) - 1
return entries [ songnr ]
playlist_title = playlist [ ' mixData ' ] [ ' name ' ]
return {
' _type ' : ' playlist ' ,
' id ' : playlist_id ,
' title ' : playlist_title ,
' entries ' : entries ,
}