From f6e46178a2e0944c4c377281e13ff1982e6be7ad Mon Sep 17 00:00:00 2001 From: dalgr Date: Sat, 27 Jan 2018 00:03:42 +0100 Subject: [PATCH] Add support for service mtv.se --- lib/svtplay_dl/__init__.py | 2 ++ lib/svtplay_dl/service/mtvnn.py | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 4cceeaf..5500eec 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -34,6 +34,7 @@ from svtplay_dl.service.flowonline import Flowonline from svtplay_dl.service.hbo import Hbo from svtplay_dl.service.twitch import Twitch from svtplay_dl.service.lemonwhale import Lemonwhale +from svtplay_dl.service.mtvnn import MtvMusic from svtplay_dl.service.mtvnn import Mtvnn from svtplay_dl.service.mtvservices import Mtvservices from svtplay_dl.service.nhl import NHL @@ -83,6 +84,7 @@ sites = [ Twitch, Lemonwhale, Mtvservices, + MtvMusic, Mtvnn, NHL, Nrk, diff --git a/lib/svtplay_dl/service/mtvnn.py b/lib/svtplay_dl/service/mtvnn.py index 9d4f355..37ed8ab 100644 --- a/lib/svtplay_dl/service/mtvnn.py +++ b/lib/svtplay_dl/service/mtvnn.py @@ -10,6 +10,7 @@ from svtplay_dl.error import ServiceError from svtplay_dl.log import log from svtplay_dl.fetcher.rtmp import RTMP from svtplay_dl.fetcher.hls import hlsparse +from svtplay_dl.utils.urllib import urlparse # This is _very_ similar to mtvservices.. @@ -92,3 +93,47 @@ class Mtvnn(Service, OpenGraphThumbMixin): episodes.append("http://www.nickelodeon.se/serier/{0}-something/videos/{1}-something".format(programid, i)) n += 1 return episodes + + +class MtvMusic(Service, OpenGraphThumbMixin): + supported_domains = ['mtv.se'] + + def get(self): + data = self.get_urldata() + + if self.exclude(): + yield ServiceError("Excluding video") + return + + match = re.search('window.pagePlaylist = (.*);', data) + + if not match: + yield ServiceError("Can't find video info") + return + + try: + janson = json.loads(match.group(1)) + except: + yield ServiceError("Can't decode api request: {0}".format(match.group(1))) + return + + parse = urlparse(self.url) + wanted_id = parse.path.split("/")[-1].split("-")[0] + + for n in janson: + if wanted_id == str(n["id"]): + + mrssxmlurl = "http://media-utils.mtvnservices.com/services/MediaGenerator/mgid:arc:video:mtv.se:{0}?acceptMethods=hls".format(n["video_token"]) + hls_asset = self.http.request("get", mrssxmlurl) + xml = ET.XML(hls_asset.text) + + if xml.find("./video") is not None and xml.find("./video").find("item") is not None and \ + xml.find("./video").find("item").find("rendition") is not None and \ + xml.find("./video").find("item").find("rendition").find("src") is not None: + + hls_url = xml.find("./video").find("item").find("rendition").find("src").text + stream = hlsparse(self.options, self.http.request("get", hls_url), hls_url) + if stream: + + for key in list(stream.keys()): + yield stream[key]