unquote youtube key
This commit is contained in:
parent
7274f400ad
commit
e11f98b676
1 changed files with 3 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
from urllib import quote
|
from urllib import quote, unquote
|
||||||
import httplib
|
import httplib
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import re
|
import re
|
||||||
|
@ -14,7 +14,7 @@ def getVideoKey(youtubeId):
|
||||||
data = getUrl("http://www.youtube.com/watch?v=%s" % youtubeId)
|
data = getUrl("http://www.youtube.com/watch?v=%s" % youtubeId)
|
||||||
match = re.compile(".*[?&]t=([^&]+).*").findall(data)
|
match = re.compile(".*[?&]t=([^&]+).*").findall(data)
|
||||||
if match:
|
if match:
|
||||||
return match[0]
|
return unquote(match[0])
|
||||||
try:
|
try:
|
||||||
conn = httplib.HTTPConnection ("www.youtube.com")
|
conn = httplib.HTTPConnection ("www.youtube.com")
|
||||||
conn.request ("HEAD", '/v/' + youtubeId)
|
conn.request ("HEAD", '/v/' + youtubeId)
|
||||||
|
@ -27,7 +27,7 @@ def getVideoKey(youtubeId):
|
||||||
location = response.getheader("location")
|
location = response.getheader("location")
|
||||||
match = re.match(".*[?&]t=([^&]+)", location)
|
match = re.match(".*[?&]t=([^&]+)", location)
|
||||||
if match:
|
if match:
|
||||||
return match.groups()[0]
|
return unquote(match.groups()[0])
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getVideoUrl(youtubeId, format='mp4'):
|
def getVideoUrl(youtubeId, format='mp4'):
|
||||||
|
|
Loading…
Reference in a new issue