Files
addon/servers/dailymotion.py
2019-11-21 19:59:55 +01:00

42 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
from core import httptools
from core import scrapertools
from platformcode import logger
def test_video_exists(page_url):
logger.info("(page_url='%s')" % page_url)
response = httptools.downloadpage(page_url)
if response.code == 404:
return False, config.get_localized_string(70449) % "dailymotion"
return True, ""
def get_video_url(page_url, premium=False, user="", password="", video_password=""):
logger.info("(page_url='%s')" % page_url)
video_urls = []
response = httptools.downloadpage(page_url, cookies=False)
cookie = {'Cookie': response.headers["set-cookie"]}
data = response.data.replace("\\", "")
subtitle = scrapertools.find_single_match(data, r'"subtitles":.*?"es":.*?urls":\["([^"]+)"')
qualities = scrapertools.find_multiple_matches(data, r'"([^"]+)":(\[\{"type":".*?\}\])')
for calidad, urls in qualities:
patron = '"type":"(?:video|application)/([^"]+)","url":"([^"]+)"'
matches = scrapertools.find_multiple_matches(urls, patron)
for stream_type, stream_url in matches:
stream_type = stream_type.replace('x-mpegURL', 'm3u8')
if stream_type == "mp4":
stream_url = httptools.downloadpage(stream_url, headers=cookie, only_headers=True,
follow_redirects=False).headers.get("location", stream_url)
video_urls.append(["%sp .%s [dailymotion]" % (calidad, stream_type), stream_url, 0, subtitle])
# else:
# data_m3u8 = httptools.downloadpage(stream_url).data
# stream_url_http = scrapertools.find_single_match(data_m3u8, r'(http:.*?\.m3u8)')
# if stream_url_http:
# stream_url = stream_url_http
# video_urls.append(["%sp .%s [Dailymotion]" % (calidad, stream_type), stream_url, 0, subtitle])
for video_url in video_urls:
logger.info("%s - %s" % (video_url[0], video_url[1]))
return video_urls