本文整理汇总了Python中Utiles.url_fix方法的典型用法代码示例。如果您正苦于以下问题:Python Utiles.url_fix方法的具体用法?Python Utiles.url_fix怎么用?Python Utiles.url_fix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utiles
的用法示例。
在下文中一共展示了Utiles.url_fix方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: atresplayer_mobile
# 需要导入模块: import Utiles [as 别名]
# 或者: from Utiles import url_fix [as 别名]
def atresplayer_mobile(self):
#stream = self.__get(self.url)
stream = Descargar.get(self.url)
episode = re.findall('episode="(.*)">', stream)[0]
header = {"Accept":"application/json"}
j = json.loads(Descargar.getHtmlHeaders("http://servicios.atresplayer.com/episode/get?episodePk="+episode, header=header))
if j['type'] == "REGISTER":
url = Utiles.url_fix(self.__getApiMobileUrl2(episode))
#self.debug(unicode(url))
#jj = json.loads(Descargar.getHtmlHeaders(Utiles.url_fix(url)))
try:
#url2down = jj['resultDes']
url2down = url
except:
raise Error.GeneralPyspainTVsError(unicode(jj['resultDes']))
elif j['type'] == "FREE": # TEMP FIX
url = Utiles.url_fix(self.__getApiMobileUrl2(episode))
try:
url2down = url
except:
raise Error.GeneralPyspainTVsError(unicode(jj['resultDes']))
else:
url = Utiles.url_fix(self.__getApiMobileUrl(episode).replace("https://", "http://"))
self.debug(unicode(url))
#jj = json.loads(self.__get(Utiles.url_fix(url)))
jj = json.loads(Descargar.get(Utiles.url_fix(url)))
try:
url2down = jj['resultObject']['es']
except:
raise Error.GeneralPyspainTVsError(unicode(jj['resultDes']))
if url2down is None:
raise Error.GeneralPyspainTVsError(u"[Atresplayer] No se han podido obtener enlaces para URL proporcionada")
title = u"%s %s".encode('utf-8') % (j['titleSection'].encode('utf-8'), j['titleDetail'].encode('utf-8'))
desc = unicode(j['seoDescription']).encode('utf-8')
name = u"VideoAtresPlayer.mp4"
img = j['urlImage'].replace(".jpg", "06.jpg")
return {"exito" : True,
"num_videos" : 1,
"mensaje" : u"URL obtenido correctamente",
"videos":[{
"url_video" : [url2down] if type(url2down) != list else url2down,
"url_img" : img if img is not None else None,
"filename" : [name] if type(name) != list else name,
"tipo" : "http",
"partes" : 1 if type(url2down) != list else len(url2down),
"rtmpd_cmd" : None,
"menco_cmd" : None,
"url_publi" : None,
"otros" : None,
"mensaje" : None
}],
"titulos": [title] if title is not None else None,
"descs": [desc] if desc is not None else None
}
示例2: atresplayer_mobile
# 需要导入模块: import Utiles [as 别名]
# 或者: from Utiles import url_fix [as 别名]
def atresplayer_mobile(self):
#stream = self.__get(self.url)
stream = Descargar.get(self.url)
episode = re.findall('episode="(.*)">', stream)[0]
header = {"Accept":"application/json"}
j = json.loads(Descargar.getHtmlHeaders(self.URL_EPISODE_INFO+episode, header=header))
url = Utiles.url_fix(self.__getApiMobileUrl(episode).replace("https://", "http://"))
self.debug(unicode(url))
#jj = json.loads(self.__get(Utiles.url_fix(url)))
jj = json.loads(Descargar.get(Utiles.url_fix(url)))
try:
url2down = jj['resultObject']['es']
except:
raise Error.GeneralPyspainTVsError(unicode(jj['resultDes']))
if url2down is None:
raise Error.GeneralPyspainTVsError(u"[Atresplayer] No se han podido obtener enlaces para URL proporcionada")
title = u"%s %s".encode('utf-8') % (j['titleSection'].encode('utf-8'), j['titleDetail'].encode('utf-8'))
desc = unicode(j['seoDescription']).encode('utf-8')
urlparsed = urlparse.urlparse(self.url)
pathsplit = urlparsed.path.split('/')
del pathsplit[:3]
name = u'_'.join(pathsplit)
name = name.replace('.html','.mp4')
img = j['urlImage'].replace(".jpg", "06.jpg")
return {"exito" : True,
"num_videos" : 1,
"mensaje" : u"URL obtenido correctamente",
"videos":[{
"url_video" : [url2down] if type(url2down) != list else url2down,
"url_img" : img if img is not None else None,
"filename" : [name] if type(name) != list else name,
"tipo" : "http",
"partes" : 1 if type(url2down) != list else len(url2down),
"rtmpd_cmd" : None,
"menco_cmd" : None,
"url_publi" : None,
"otros" : None,
"mensaje" : None
}],
"titulos": [title] if title is not None else None,
"descs": [desc] if desc is not None else None
}
示例3: atresplayer_mobile
# 需要导入模块: import Utiles [as 别名]
# 或者: from Utiles import url_fix [as 别名]
def atresplayer_mobile(self):
# stream = self.__get(self.url)
stream = Descargar.get(self.url)
episode = re.findall('episode="(.*)">', stream)[0]
header = {"Accept": "application/json"}
self.debug("http://servicios.atresplayer.com/episode/get?episodePk=" + episode)
j = json.loads(
Descargar.getHtmlHeaders("http://servicios.atresplayer.com/episode/get?episodePk=" + episode, header=header)
)
if j["type"] == "FREE":
url = Utiles.url_fix(self.__getApiMobileUrl2(episode))
header = {"User-Agent": "Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J)"}
data = json.loads(Descargar.getHtmlHeaders(url.replace("https://", "http://"), header=header))
self.debug(u"DATA:\n%s" % data)
try:
url2down = data["resultObject"]["es"]
if url2down is None:
raise Error.GeneralPyspainTVsError(u"No se ha podido obtener el enlace del vídeo")
# url2down = url.replace("https://", "http://")
except:
raise Error.GeneralPyspainTVsError(unicode(jj["resultDes"]))
else:
if not self.opcs["a3user"] or not self.opcs["a3pass"]:
raise Error.GeneralPyspainTVsError(
u"No tienes permisos para acceder al contenido. Proporciona tu usuario y contraseña para volver a intentarlo (en la web: botón de opciones arriba a la izquierda)."
)
cj = self.atresplayer_mobile_login(
"http://servicios.atresplayer.com/j_spring_security_check",
{"j_username": self.opcs["a3user"], "j_password": self.opcs["a3pass"]},
)
apiUrl = Utiles.url_fix(self.__getApiMobileUrl2(episode)).replace("https://", "http://")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [
("Accept", "application/json"),
("User-Agent", "Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J"),
("Referer", "http://www.atresplayer.com/"),
]
response = opener.open(apiUrl)
content = json.loads(response.read())
self.debug(u"CONTENT:\n%s" % content)
url2down = content["resultObject"]["es"]
if url2down is None:
raise Error.GeneralPyspainTVsError(u"No se ha podido obtener el enlace del vídeo")
if not url2down:
raise Error.GeneralPyspainTVsError(unicode(content["resultDes"]))
# if j['type'] == "REGISTER":
# url = Utiles.url_fix(self.__getApiMobileUrl2(episode))
# #header = {"User-Agent":"Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J)"}
# #data = json.loads(Descargar.getHtmlHeaders(url.replace("https://", "http://"), header=header))
# try:
# #url2down = data['resultObject']['es']
# url2down = url.replace("https://", "http://")
# except:
# raise Error.GeneralPyspainTVsError(unicode(jj['resultDes']))
# elif j['type'] == "FREE": # TEMP FIX
# else:
# url = Utiles.url_fix(self.__getApiMobileUrl2(episode).replace("https://", "http://"))
# self.debug(unicode(url))
# #jj = json.loads(self.__get(Utiles.url_fix(url)))
# jj = json.loads(Descargar.get(Utiles.url_fix(url)))
# try:
# url2down = jj['resultObject']['es']
# except:
# raise Error.GeneralPyspainTVsError(unicode(jj['resultDes']))
# if url2down is None:
# raise Error.GeneralPyspainTVsError(u"[Atresplayer] No se han podido obtener enlaces para URL proporcionada")
title = u"%s %s".encode("utf-8") % (j["titleSection"].encode("utf-8"), j["titleDetail"].encode("utf-8"))
desc = unicode(j["seoDescription"]).encode("utf-8")
name = u"VideoAtresPlayer.mp4"
img = j["urlImage"].replace(".jpg", "06.jpg")
return {
"exito": True,
"num_videos": 1,
"mensaje": u"URL obtenido correctamente",
"videos": [
{
"url_video": [url2down] if type(url2down) != list else url2down,
"url_img": img if img is not None else None,
"filename": [name] if type(name) != list else name,
"tipo": "http",
"partes": 1 if type(url2down) != list else len(url2down),
"rtmpd_cmd": None,
"menco_cmd": None,
"url_publi": None,
"otros": None,
"mensaje": None,
}
],
"titulos": [title] if title is not None else None,
"descs": [desc] if desc is not None else None,
}
示例4: getInfo
# 需要导入模块: import Utiles [as 别名]
# 或者: from Utiles import url_fix [as 别名]
def getInfo(self):
'''
Devuelve toda la información asociada a la URL recibida, de la siguiente forma:
{
"exito" : bool, <-- True (si se han obtenido videos)
"num_video" : int, <-- Número de vídeos obtenidos
"mensaje" : u"" , <-- Mensajes de la API (ej.: El vídeo no ha sido encontrado ["exito": False])
"videos" : [{
"url_video" : [], <-- Url de descarga de vídeo
"url_img" : "", <-- Url de la miniatura del video
"filename" : [], <-- Nombre de las partes para guardar en disco
"tipo" : "", <-- http, rtmp[e,..], mms, ...
"partes" : int, <-- Número de partes que tiene el vídeo
"rtmpd_cmd" : [], <-- Comando rtmpdump (si tipo == rtmp) sino None
"menco_cmd" : [], <-- Comando mencoder (Si tipo == rtmp) sino None
"url_publi" : "", <-- Url del vídeo de publicidad asociado al vídeo
"otros" : [], <-- Lista donde se pueden pasar cosas opcionales
"mensaje" : "" <-- Mensajes de la API
}], <-- Debe ser una lista de tamaño "num_videos"
"titulos" : [u""], <-- Titulos de los videos
"descs" : [u""] <-- Descripción de cada vídeo
}
Los valores que no se rellenen, deberán devolver None.
La clave "exito" es obligatoria, sino se puede encontrar el vídeo se puede devolver directamente:
{
"exito": False,
"mensaje": "No se pudo descargar el video"
}
"videos", "mesajes" y "descs" deben ser listas de cadenas (si no son None)
"url_video", "filename", "rtmp_cmd", "menco_cmd" (de "videos") deben ser listas de cadenas (si no son None)
'''
html = Descargar.getHtmlUtf8Intereconomia(self.url)
rtmp = False
try: tit = Utiles.recortar(html, "title: '", "'").encode('utf-8')
except:
try: tit = Utiles.recortar(html, "<title>", "</title>").encode('utf-8')
except:tit = u"Vídeo de Intereconomía".encode('utf8')
desc = tit
try: name = Utiles.formatearNombre(tit+".mp4")
except: name = "VideoIntereconomia.mp4"
try: img = self.URL_INTER+Utiles.recortar(html, "backgroundImage: 'url(", ")'")
except: img = None
try: url = Utiles.url_fix(Utiles.recortar(html, "clip: '", "'"))
except:
try: url = Utiles.url_fix(html.split("playlist:")[1].split("url: '")[1].split("'")[0])
except:
try:
url = Utiles.url_fix(html.split("clip:")[1].split("url: \'")[1].split("\'")[0])
rtmp = True
except: raise Error.GeneralPyspainTVsError(u"No se ha podido encontrar el vídeo en la página")
if rtmp:
url = (Utiles.recortar(html, "netConnectionUrl: \'", "\'") + "/" + url).replace("mp4:", "mp4/").replace("mp4%3A", "mp4/")
rtmpd_cmd = "rtmpdump -r \'"+url+"\' -o \'"+name+"\'"
return {"exito" : True,
"num_videos" : 1,
"mensaje" : u"URL obtenido correctamente",
"videos":[{
"url_video" : [url],
"url_img" : img if img is not None else None,
"filename" : [name] if name is not None else None,
"tipo" : "rtmp",
"partes" : 1,
"rtmpd_cmd" : [rtmpd_cmd],
"menco_cmd" : None,
"url_publi" : None,
"otros" : None,
"mensaje" : None
}],
"titulos": [tit] if tit is not None else None,
"descs": [desc] if desc is not None else None
}
return {"exito" : True,
"num_videos" : 1,
"mensaje" : u"URL obtenido correctamente",
"videos":[{
"url_video" : [url],
"url_img" : img if img is not None else None,
"filename" : [name] if name is not None else None,
"tipo" : "http",
"partes" : 1,
"rtmpd_cmd" : None,
"menco_cmd" : None,
"url_publi" : None,
"otros" : None,
"mensaje" : None
}],
"titulos": [tit] if tit is not None else None,
"descs": [desc] if desc is not None else None
}