def UpdateVideoItem(self, item): """Updates an existing MediaItem with more data. Arguments: item : MediaItem - the MediaItem that needs to be updated Returns: The original item with more data added to it's properties. Used to update none complete MediaItems (self.complete = False). This could include opening the item's URL to fetch more data and then process that data or retrieve it's real media-URL. The method should at least: * cache the thumbnail to disk (use self.noImage if no thumb is available). * set at least one MediaItemPart with a single MediaStream. * set self.complete = True. if the returned item does not have a MediaItemPart then the self.complete flag will automatically be set back to False. """ videoData = UriHandler.Open(item.url, proxy=self.proxy) if not videoData: return item videoData = JsonHelper(videoData) videoInfo = videoData.GetValue("data", "attributes") part = item.CreateNewEmptyMediaPart() # Somehow only this specific user-agent works (dunno why)! part.HttpHeaders[ "user-agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)" m3u8url = videoInfo["streaming"]["hls"]["url"] m3u8data = UriHandler.Open(m3u8url, self.proxy) for s, b, a in M3u8.GetStreamsFromM3u8(m3u8url, self.proxy, appendQueryString=False, mapAudio=True, playListData=m3u8data): item.complete = True if a: audioPart = a.split("-prog_index.m3u8", 1)[0] audioId = audioPart.rsplit("/", 1)[-1] s = s.replace("-prog_index.m3u8", "-{0}-prog_index.m3u8".format(audioId)) part.AppendMediaStream(s, b) vttUrl = M3u8.GetSubtitle(m3u8url, self.proxy, m3u8data) # https://dplaynordics-vod-80.akamaized.net/dplaydni/259/0/hls/243241001/1112635959-prog_index.m3u8?version_hash=bb753129&hdnts=st=1518218118~exp=1518304518~acl=/*~hmac=bdeefe0ec880f8614e14af4d4a5ca4d3260bf2eaa8559e1eb8ba788645f2087a vttUrl = vttUrl.replace("-prog_index.m3u8", "-0.vtt") part.Subtitle = SubtitleHelper.DownloadSubtitle(vttUrl, format='srt', proxy=self.proxy) return item
def GetSubtitle(streamId, proxy=None): subTitleUrl = "http://tt888.omroep.nl/tt888/%s" % (streamId, ) return SubtitleHelper.DownloadSubtitle(subTitleUrl, streamId + ".srt", format='srt', proxy=proxy)
def UpdateVideoItem(self, item): """Updates an existing MediaItem with more data. Arguments: item : MediaItem - the MediaItem that needs to be updated Returns: The original item with more data added to it's properties. Used to update none complete MediaItems (self.complete = False). This could include opening the item's URL to fetch more data and then process that data or retrieve it's real media-URL. The method should at least: * set at least one MediaItemPart with a single MediaStream. * set self.complete = True. if the returned item does not have a MediaItemPart then the self.complete flag will automatically be set back to False. """ Logger.Debug('Starting UpdateVideoItem for %s (%s)', item.name, self.channelName) # User-agent (and possible other headers), should be consistent over all M3u8 requests (See #864) headers = { # "User-Agent": AddonSettings.GetUserAgent(), "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)", # "Origin": "https://www.viafree.se" } if self.localIP: headers.update(self.localIP) if True: data = UriHandler.Open(item.url, proxy=self.proxy, additionalHeaders=headers or None) else: from debug.router import Router data = Router.GetVia("se", item.url, self.proxy) json = JsonHelper(data) # see if there was an srt already if item.MediaItemParts: part = item.MediaItemParts[0] if part.Subtitle and part.Subtitle.endswith(".vtt"): part.Subtitle = SubtitleHelper.DownloadSubtitle( part.Subtitle, format="webvtt", proxy=self.proxy) else: part.Subtitle = SubtitleHelper.DownloadSubtitle( part.Subtitle, format="dcsubtitle", proxy=self.proxy) else: part = item.CreateNewEmptyMediaPart() for q in ("high", 3500), ("hls", 2700), ("medium", 2100): url = json.GetValue("streams", q[0]) Logger.Trace(url) if not url: continue if ".f4m" in url: # Kodi does not like the f4m streams continue if url.startswith("http") and ".m3u8" in url: for s, b in M3u8.GetStreamsFromM3u8(url, self.proxy, headers=headers): part.AppendMediaStream(s, b) if not part.MediaStreams and "manifest.m3u8": Logger.Warning( "No streams found in %s, trying alternative with 'master.m3u8'", url) url = url.replace("manifest.m3u8", "master.m3u8") for s, b in M3u8.GetStreamsFromM3u8(url, self.proxy, headers=headers): part.AppendMediaStream(s, b) # check for subs # https://mtgxse01-vh.akamaihd.net/i/201703/13/DCjOLN_1489416462884_427ff3d3_,48,260,460,900,1800,2800,.mp4.csmil/master.m3u8?__b__=300&hdnts=st=1489687185~exp=3637170832~acl=/*~hmac=d0e12e62c219d96798e5b5ef31b11fa848724516b255897efe9808c8a499308b&cc1=name=Svenska%20f%C3%B6r%20h%C3%B6rselskadade~default=no~forced=no~lang=sv~uri=https%3A%2F%2Fsubstitch.play.mtgx.tv%2Fsubtitle%2Fconvert%2Fxml%3Fsource%3Dhttps%3A%2F%2Fcdn-subtitles-mtgx-tv.akamaized.net%2Fpitcher%2F20xxxxxx%2F2039xxxx%2F203969xx%2F20396967%2F20396967-swt.xml%26output%3Dm3u8 # https://cdn-subtitles-mtgx-tv.akamaized.net/pitcher/20xxxxxx/2039xxxx/203969xx/20396967/20396967-swt.xml&output=m3u8 if "uri=" in url and not part.Subtitle: Logger.Debug("Extracting subs from M3u8") subUrl = url.rsplit("uri=")[-1] subUrl = HtmlEntityHelper.UrlDecode(subUrl) subData = UriHandler.Open(subUrl, proxy=self.proxy) # subUrl = None subs = filter(lambda line: line.startswith("http"), subData.split("\n")) # for line in subData.split("\n"): # if line.startswith("http"): # subUrl = line # break if subs: part.Subtitle = SubtitleHelper.DownloadSubtitle( subs[0], format='webvtt', proxy=self.proxy) elif url.startswith("rtmp"): # rtmp://mtgfs.fplive.net/mtg/mp4:flash/sweden/tv3/Esport/Esport/swe_skillcompetition.mp4.mp4 oldUrl = url if not url.endswith(".flv") and not url.endswith(".mp4"): url += '.mp4' if "/mp4:" in url: # in this case we need to specifically set the path # url = url.replace('/mp4:', '//') -> don't do this, but specify the path server, path = url.split("mp4:", 1) url = "%s playpath=mp4:%s" % (server, path) if oldUrl != url: Logger.Debug("Updated URL from - to:\n%s\n%s", oldUrl, url) url = self.GetVerifiableVideoUrl(url) part.AppendMediaStream(url, q[1]) else: part.AppendMediaStream(url, q[1]) part.HttpHeaders.update(headers) if part.MediaStreams: item.complete = True Logger.Trace("Found mediaurl: %s", item) return item
def UpdateVideoItem(self, item): """Updates an existing MediaItem with more data. Arguments: item : MediaItem - the MediaItem that needs to be updated Returns: The original item with more data added to it's properties. Used to update none complete MediaItems (self.complete = False). This could include opening the item's URL to fetch more data and then process that data or retrieve it's real media-URL. The method should at least: * cache the thumbnail to disk (use self.noImage if no thumb is available). * set at least one MediaItemPart with a single MediaStream. * set self.complete = True. if the returned item does not have a MediaItemPart then the self.complete flag will automatically be set back to False. """ Logger.Debug('Starting UpdateVideoItem for %s (%s)', item.name, self.channelName) url = item.url if self.localIP: item.HttpHeaders.update(self.localIP) if ".m3u8" not in item.url: data = UriHandler.Open(url, proxy=self.proxy, additionalHeaders=item.HttpHeaders) json = JsonHelper(data) url = json.GetValue("mediaUrl") if url is None: Logger.Warning("Could not find mediaUrl in %s", item.url) return f4mNeedle = "/manifest.f4m" if f4mNeedle in url: Logger.Info("Found F4m stream. Converting to M3u8.") url = url[:url.index(f4mNeedle)].replace("/z/", "/i/").replace("http:", "https:") url = "%s/master.m3u8" % (url, ) # are there subs? They are added as URL parameter part = item.CreateNewEmptyMediaPart() subMatches = Regexer.DoRegex('https*%3a%2f%2.+master.m3u8', url) if subMatches: subUrl = HtmlEntityHelper.UrlDecode(subMatches[0]) Logger.Info("Item has subtitles: %s", subUrl) subTitle = SubtitleHelper.DownloadSubtitle(subUrl, format="m3u8srt", proxy=self.proxy) if subTitle: part.Subtitle = subTitle for s, b in M3u8.GetStreamsFromM3u8(url, self.proxy, headers=item.HttpHeaders): item.complete = True # s = self.GetVerifiableVideoUrl(s) part.AppendMediaStream(s, b) if self.localIP: part.HttpHeaders.update(self.localIP) return item