diff --git a/youtube-dl b/youtube-dl index 760930e44..b4005b851 100755 --- a/youtube-dl +++ b/youtube-dl @@ -39,6 +39,7 @@ import urllib import urllib2 import warnings import zlib +import json if os.name == 'nt': import ctypes @@ -1519,7 +1520,7 @@ class DailymotionIE(InfoExtractor): video_id = mobj.group(1) simple_title = mobj.group(2).decode('utf-8') - video_extension = 'flv' + video_extension = 'mp4' # Retrieve video webpage to extract further information request = urllib2.Request(url) @@ -1531,16 +1532,31 @@ class DailymotionIE(InfoExtractor): return # Extract URL, uploader and title from webpage + # First we need to get the sequence urlencoded json variable self.report_extraction(video_id) - mobj = re.search(r'(?i)addVariable\(\"video\"\s*,\s*\"([^\"]*)\"\)', webpage) + mobj = re.search(r'(?i)addVariable\(\"sequence\"\s*,\s*\"([^\"]*)\"\)', webpage) if mobj is None: self._downloader.trouble(u'ERROR: unable to extract media URL') return - mediaURL = urllib.unquote(mobj.group(1)) # if needed add http://www.dailymotion.com/ if relative URL + sequenceJsonContent = urllib.unquote_plus(mobj.group(1)) - video_url = mediaURL + # JSON does not suppot escaping of '. + # Replace every \' by a ' in the JSON string + sequenceJsonContent = sequenceJsonContent.replace("\\'", "'") + + # Build the JSON object based on the string + try: + sequenceJson = json.loads(sequenceJsonContent) + except: + self._downloader.trouble(u'ERROR: unable to extract media URL (Bad JSON encoding)') + return + try: + video_url = sequenceJson[0]["layerList"][0]["sequenceList"][1]["layerList"][2]["param"]["videoPluginParameters"]["hqURL"] + except: + self._downloader.trouble(u'ERROR: unable to extract media URL (Unable to find the URL)') + return # '' mobj = re.search(r'(?im)