Ejemplo n.º 1
0
  def parseVInfo(self, videoinfo, watch_url):
	flashvars = self.extractFlashVars(videoinfo, 0)
	if not flashvars.has_key(u"url_encoded_fmt_stream_map"):
		if self.useProxy and not self.retryParse:
			self.retryParse = True
			self.tw_agent_hlp.getWebPage(watch_url).addCallback(self.parseVInfo, watch_url).addErrback(self.dataError)
		else:
			self.checkFlashvars(flashvars, videoinfo, True)
	else:
		links = {}
		for url_desc in flashvars[u"url_encoded_fmt_stream_map"].split(u","):
			url_desc_map = parse_qs(url_desc)
			if not (url_desc_map.has_key(u"url") or url_desc_map.has_key(u"stream")):
				continue

			key = int(url_desc_map[u"itag"][0])
			url = u""

			if url_desc_map.has_key(u"url"):
				url = urllib.unquote(url_desc_map[u"url"][0])
			elif url_desc_map.has_key(u"conn") and url_desc_map.has_key(u"stream"):
				url = urllib.unquote(url_desc_map[u"conn"][0])
				if url.rfind("/") < len(url) -1:
					url = url + "/"
				url = url + urllib.unquote(url_desc_map[u"stream"][0])
			elif url_desc_map.has_key(u"stream") and not url_desc_map.has_key(u"conn"):
				url = urllib.unquote(url_desc_map[u"stream"][0])

			if url_desc_map.has_key(u"sig"):
				url = url + u"&signature=" + url_desc_map[u"sig"][0]
			elif url_desc_map.has_key(u"s"):
				sig = url_desc_map[u"s"][0]
				flashvars = self.extractFlashVars(videoinfo, 1)
				if isVEVODecryptor:
					signature = decryptor.decryptSignature(sig, flashvars[u"js"])
				else:
					signature = None
				if not signature:
					self.error = "[YoutubeURL] Error: cannot decrypt signature!"
					self.errReturn(None)
					return
				else:
					url += u"&signature=" + signature

			try:
				links[self.VIDEO_FMT_PRIORITY_MAP[str(key)]] = url
			except KeyError:
				print 'skipping',key,'fmt not in priority videos'
				continue

		if not links:
			url = flashvars.get('hlsvp','')
			print 'hlsvp:',str(url)
			if url:
				links[0] = url

		try:
			self.video_url = links[sorted(links.iterkeys())[0]].encode('utf-8')
			self.callBack(self.video_url)
		except (KeyError,IndexError):
			self.error = "[YoutubeURL] Error: no video url found"
			self.errReturn(self.video_url)
    def parseVInfo(self, videoinfo, watch_url):
        flashvars = self.extractFlashVars(videoinfo, 0)
        if not flashvars.has_key(u"url_encoded_fmt_stream_map"):
            self.checkFlashvars(flashvars, videoinfo, True)
        else:
            links = {}
            audio = {}
            encoded_url_map = ""
            if self.dash:
                try:
                    encoded_url_map += u"," + flashvars.get(
                        'adaptive_fmts', [])
                except:
                    pass
            encoded_url_map += u"," + flashvars[u"url_encoded_fmt_stream_map"]
            for url_desc in encoded_url_map.split(u","):
                url_desc_map = parse_qs(url_desc)
                if not (url_desc_map.has_key(u"url")
                        or url_desc_map.has_key(u"stream")):
                    continue

                try:
                    key = int(url_desc_map[u"itag"][0])
                except ValueError:
                    continue

                url = u""
                if url_desc_map.has_key(u"url"):
                    url = urllib.unquote(url_desc_map[u"url"][0])
                elif url_desc_map.has_key(u"conn") and url_desc_map.has_key(
                        u"stream"):
                    url = urllib.unquote(url_desc_map[u"conn"][0])
                    if url.rfind("/") < len(url) - 1:
                        url = url + "/"
                    url = url + urllib.unquote(url_desc_map[u"stream"][0])
                elif url_desc_map.has_key(
                        u"stream") and not url_desc_map.has_key(u"conn"):
                    url = urllib.unquote(url_desc_map[u"stream"][0])

                if url_desc_map.has_key(u"sig"):
                    url = url + u"&signature=" + url_desc_map[u"sig"][0]
                elif url_desc_map.has_key(u"s"):
                    sig = url_desc_map[u"s"][0]
                    flashvars = self.extractFlashVars(videoinfo, 1)
                    signature = decryptor.decryptSignature(
                        sig, flashvars[u"js"])
                    if not signature:
                        self.error = "[YoutubeURL] Error: cannot decrypt url"
                        self.errReturn(None)
                        return
                    else:
                        url += u"&signature=" + signature

                try:
                    links[self.VIDEO_FMT_PRIORITY_MAP[str(key)]] = url
                except KeyError:
                    try:
                        audio[self.AUDIO_FMT_PRIORITY_MAP[str(key)]] = url
                    except KeyError:
                        continue

            url = flashvars.get('hlsvp', '')
            if url:
                links = {}
                links[0] = url

            #print "#####################################################################################"
            #try:
            #	for i in links:
            #		type = re.search('.*?itag=(\d+)', links[i]).group(1)
            #		print type + "\t" + links[i]
            #except:
            #	pass
            #print "#####################################################################################"
            try:
                self.video_url = links[sorted(
                    links.iterkeys())[0]].encode('utf-8')
                try:
                    if int(
                            re.search('.*?itag=(\d+)',
                                      self.video_url).group(1)) > 100:
                        self.audio_url = audio[sorted(
                            audio.iterkeys())[0]].encode('utf-8')
                        #print "#####################################################################################"
                        #for i in audio:
                        #	type = re.search('.*?itag=(\d+)', audio[i]).group(1)
                        #	print type + "\t" + audio[i]
                        #print "#####################################################################################"
                except:
                    pass
                #self.__callBack(self.video_url)
                self.callBack(self.video_url, self.audio_url)
            except (KeyError, IndexError):
                self.error = "[YoutubeURL] Error: no video url found"
                self.errReturn(self.video_url)
Ejemplo n.º 3
0
    def parseVInfo2(self, videoinfo, playerUrl=None):
        flashvars = parse_qs(videoinfo)
        if not flashvars.has_key(u"url_encoded_fmt_stream_map"):
            if 'hlsvp=' in videoinfo:
                url = urllib.unquote(
                    re.search('hlsvp=(.*?\.m3u8)', videoinfo).group(1))
                self.__callBack(url)
            else:
                self.checkFlashvars(flashvars, videoinfo)
        else:
            video_fmt_map = {}
            fmt_infomap = {}
            tmp_fmtUrlDATA = flashvars['url_encoded_fmt_stream_map'][0].split(
                ',')
            for fmtstring in tmp_fmtUrlDATA:
                fmturl = fmtid = fmtsig = ""
                if flashvars.has_key('url_encoded_fmt_stream_map'):
                    try:
                        for arg in fmtstring.split('&'):
                            if arg.find('=') >= 0:
                                key, value = arg.split('=')
                                if key == 'itag':
                                    if len(value) > 3:
                                        value = value[:2]
                                    fmtid = value
                                elif key == 'url':
                                    fmturl = value
                                elif key == 'sig':
                                    fmtsig = value
                                elif key == 's' and playerUrl != None:
                                    fmtsig = decryptor.decryptSignature(
                                        value, playerUrl)

                        if fmtid != "" and fmturl != "" and self.VIDEO_FMT_PRIORITY_MAP.has_key(
                                fmtid):
                            video_fmt_map[
                                self.VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                                    'fmtid': fmtid,
                                    'fmturl': unquote_plus(fmturl),
                                    'fmtsig': fmtsig
                                }
                            fmt_infomap[int(fmtid)] = "%s&signature=%s" % (
                                unquote_plus(fmturl), fmtsig)
                        fmturl = fmtid = fmtsig = ""

                    except:
                        self.error = "[YoutubeURL] Error parsing fmtstring: %s" % fmtstring
                        self.errReturn(self.video_url)
                        return

                else:
                    (fmtid, fmturl) = fmtstring.split('|')

                if self.VIDEO_FMT_PRIORITY_MAP.has_key(fmtid) and fmtid != "":
                    video_fmt_map[self.VIDEO_FMT_PRIORITY_MAP[fmtid]] = {
                        'fmtid': fmtid,
                        'fmturl': unquote_plus(fmturl)
                    }
                    fmt_infomap[int(fmtid)] = unquote_plus(fmturl)

            if video_fmt_map and len(video_fmt_map):
                best_video = video_fmt_map[sorted(video_fmt_map.iterkeys())[0]]
                if best_video['fmtsig']:
                    self.video_url = "%s&signature=%s" % (
                        best_video['fmturl'].split(';')[0],
                        best_video['fmtsig'])
                else:
                    self.video_url = "%s" % (
                        best_video['fmturl'].split(';')[0])
                #self.__callBack(self.video_url)
                self.callBack(str(self.video_url))
            else:
                self.error = "[YoutubeURL] Error: no video url found"
                self.errReturn(self.video_url)
Ejemplo n.º 4
0
  def parseVInfo(self, videoinfo, watch_url):
	flashvars = self.extractFlashVars(videoinfo, 0)
	if not flashvars.has_key(u"url_encoded_fmt_stream_map"):
		self.checkFlashvars(flashvars, videoinfo, True)
	else:
		links = {}
		encoded_url_map = flashvars[u"url_encoded_fmt_stream_map"]
		if self.dash: encoded_url_map += flashvars.get('adaptive_fmts', [])
		for url_desc in encoded_url_map.split(u","):
			url_desc_map = parse_qs(url_desc)
			if not (url_desc_map.has_key(u"url") or url_desc_map.has_key(u"stream")):
				continue

			try:
				key = int(url_desc_map[u"itag"][0])
			except ValueError:
				continue

			url = u""
			if url_desc_map.has_key(u"url"):
				url = urllib.unquote(url_desc_map[u"url"][0])
			elif url_desc_map.has_key(u"conn") and url_desc_map.has_key(u"stream"):
				url = urllib.unquote(url_desc_map[u"conn"][0])
				if url.rfind("/") < len(url) -1:
					url = url + "/"
				url = url + urllib.unquote(url_desc_map[u"stream"][0])
			elif url_desc_map.has_key(u"stream") and not url_desc_map.has_key(u"conn"):
				url = urllib.unquote(url_desc_map[u"stream"][0])

			if url_desc_map.has_key(u"sig"):
				url = url + u"&signature=" + url_desc_map[u"sig"][0]
			elif url_desc_map.has_key(u"s"):
				sig = url_desc_map[u"s"][0]
				flashvars = self.extractFlashVars(videoinfo, 1)
				if isVEVODecryptor:
					signature = decryptor.decryptSignature(sig, flashvars[u"js"])
				else:
					signature = None
				if not signature:
					self.error = "[YoutubeURL] Error: cannot decrypt url"
					self.errReturn(None)
					return
				else:
					url += u"&signature=" + signature

			try:
				links[self.VIDEO_FMT_PRIORITY_MAP[str(key)]] = url
			except KeyError:
				continue

		if not links:
			url = flashvars.get('hlsvp','')
			if url:
				links[0] = url

		try:
			self.video_url = links[sorted(links.iterkeys())[0]].encode('utf-8')
			#self.__callBack(self.video_url)
			self.callBack(self.video_url)
		except (KeyError,IndexError):
			self.error = "[YoutubeURL] Error: no video url found"
			self.errReturn(self.video_url)
Ejemplo n.º 5
0
    def parseVInfo(self, videoinfo, watch_url):
        flashvars = self.extractFlashVars(videoinfo, 0)
        if not flashvars.has_key(u"url_encoded_fmt_stream_map"):
            playerUrl = re.search(
                '.*src="(.*?)"\s+(?:type="text/javascript"\s|)name="player(?:_ias|)/base"',
                videoinfo, re.S)
            if playerUrl:
                playerUrl = playerUrl.group(1).replace('\/', '/')
            else:
                playerUrl = None
            self.checkFlashvars(flashvars,
                                videoinfo,
                                True,
                                playerUrl=playerUrl)
        else:
            links = {}
            audio = {}
            encoded_url_map = ""
            if self.dash and (
                    self.videoPrio >= 3 or
                (config_mp.mediaportal.youtubeenabledash480p.value
                 and self.videoPrio >= 1) or
                (config_mp.mediaportal.youtubeenabledash720p.value
                 and self.videoPrio >= 2)):
                try:
                    encoded_url_map += u"," + flashvars.get(
                        'adaptive_fmts', [])
                except:
                    pass
            encoded_url_map += u"," + flashvars[u"url_encoded_fmt_stream_map"]
            for url_desc in encoded_url_map.split(u","):
                url_desc_map = parse_qs(url_desc)
                if not (url_desc_map.has_key(u"url")
                        or url_desc_map.has_key(u"stream")):
                    continue

                try:
                    key = int(url_desc_map[u"itag"][0])
                except ValueError:
                    continue

                url = u""
                if url_desc_map.has_key(u"url"):
                    url = urllib.unquote(url_desc_map[u"url"][0])
                elif url_desc_map.has_key(u"conn") and url_desc_map.has_key(
                        u"stream"):
                    url = urllib.unquote(url_desc_map[u"conn"][0])
                    if url.rfind("/") < len(url) - 1:
                        url = url + "/"
                    url = url + urllib.unquote(url_desc_map[u"stream"][0])
                elif url_desc_map.has_key(
                        u"stream") and not url_desc_map.has_key(u"conn"):
                    url = urllib.unquote(url_desc_map[u"stream"][0])

                if url_desc_map.has_key(u"sig"):
                    url = url + u"&signature=" + url_desc_map[u"sig"][0]
                elif url_desc_map.has_key(u"s"):
                    sig = url_desc_map[u"s"][0]
                    flashvars = self.extractFlashVars(videoinfo, 1)
                    signature = decryptor.decryptSignature(
                        sig, flashvars[u"js"])
                    if not signature:
                        self.error = "[YoutubeURL] Error: cannot decrypt url"
                        self.errReturn(None)
                        return
                    else:
                        url += u"&signature=" + signature

                try:
                    links[self.VIDEO_FMT_PRIORITY_MAP[str(key)]] = url
                except KeyError:
                    if self.dash and (
                            self.videoPrio >= 3 or
                        (config_mp.mediaportal.youtubeenabledash480p.value
                         and self.videoPrio >= 1) or
                        (config_mp.mediaportal.youtubeenabledash720p.value
                         and self.videoPrio >= 2)):
                        try:
                            audio[self.AUDIO_FMT_PRIORITY_MAP[str(key)]] = url
                        except KeyError:
                            continue
                    else:
                        continue

            hlsdata = videoinfo.replace('\\/', '/').replace('\\"', '"')
            url = re.findall('hlsManifestUrl":"(http.*?\.m3u8)"(?:}|,)',
                             hlsdata, re.S)
            if url:
                links = {}
                links[0] = url[-1]

            #print "#####################################################################################"
            #try:
            #	for i in links:
            #		type = re.search('.*?itag=(\d+)', links[i]).group(1)
            #		print type + "\t" + links[i]
            #except:
            #	pass
            #print "#####################################################################################"
            try:
                self.video_url = links[sorted(
                    links.iterkeys())[0]].encode('utf-8')
                if self.dash:
                    try:
                        if int(
                                re.search('.*?itag=(\d+)',
                                          self.video_url).group(1)) > 100:
                            self.audio_url = audio[sorted(
                                audio.iterkeys())[0]].encode('utf-8')
                            #print "#####################################################################################"
                            #for i in audio:
                            #	type = re.search('.*?itag=(\d+)', audio[i]).group(1)
                            #	print type + "\t" + audio[i]
                            #print "#####################################################################################"
                    except:
                        pass
                #self.__callBack(self.video_url)
                self.callBack(self.video_url, self.audio_url)
            except (KeyError, IndexError):
                self.error = "[YoutubeURL] Error: no video url found"
                self.errReturn(self.video_url)