Exemple #1
0
def filename(options, stream):
    if options.output:
        if is_py2:
            if platform.system() == "Windows":
                options.output = options.output.decode("latin1")
            else:
                options.output = options.output.decode("utf-8")
        options.output = options.output.replace('"', '').replace("'", "").rstrip('\\')
    if not options.output or os.path.isdir(options.output):
        error, data = stream.get_urldata()
        if error:
            log.error("Cant find that page")
            return False
        if data is None:
            return False
        match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S)
        if match:
            options.output_auto = True
            title_tag = decode_html_entities(match.group(1))
            if not options.output:
                options.output = filenamify(title_tag)
            else:
                # output is a directory
                options.output = os.path.join(options.output, filenamify(title_tag))

    if platform.system() == "Windows":
        # ugly hack. replace \ with / or add extra \ because c:\test\kalle.flv will add c:_tab_est\kalle.flv
        if options.output and options.output.find("\\") > 0:
            options.output = options.output.replace("\\", "/")
    return True
Exemple #2
0
    def outputfilename(self, data, filename):
        directory = os.path.dirname(filename)
        name = data["video"]["titlePagePath"]
        other = filenamify(data["video"]["title"])
        if "programVersionId" in data["video"]:
            vid = str(data["video"]["programVersionId"])
        else:
            vid = str(data["video"]["id"])
        if is_py2:
            id = hashlib.sha256(vid).hexdigest()[:7]
        else:
            id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        season = self.seasoninfo(data)
        title = name
        if season:
            title += ".%s" % season
        if other:
            title += ".%s" % other
        title += "-%s-svtplay" % id
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #3
0
def get_one_media(stream, options):
    if not options.output or os.path.isdir(options.output):
        data = stream.get_urldata()
        match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S)
        if match:
            options.output_auto = True
            title_tag = decode_html_entities(match.group(1))
            if not options.output:
                options.output = filenamify(title_tag)
            else:
                # output is a directory
                options.output = os.path.join(options.output, filenamify(title_tag))

    if platform.system() == "Windows":
        # ugly hack. replace \ with / or add extra \ because c:\test\kalle.flv will add c:_tab_est\kalle.flv
        if options.output.find("\\") > 0:
            options.output = options.output.replace("\\", "/")

    videos = []
    subs = []
    streams = stream.get(options)
    if streams:
        for i in streams:
            if isinstance(i, VideoRetriever):
                if options.preferred:
                    if options.preferred == i.name():
                        videos.append(i)
                else:
                    videos.append(i)
            if isinstance(i, subtitle):
                subs.append(i)

        if options.subtitle and options.output != "-":
            if subs:
                subs[0].download(copy.copy(options))
            if options.force_subtitle:
                return

        if len(videos) > 0:
            stream = select_quality(options, videos)
            try:
                stream.download()
            except UIException as e:
                if options.verbose:
                    raise e
                log.error(e.message)
                sys.exit(2)

            if options.thumbnail:
                if hasattr(stream, "get_thumbnail"):
                    log.info("thumb requested")
                    if options.output != "-":
                        log.info("getting thumbnail")
                        stream.get_thumbnail(options)
            else:
                log.info("no thumb requested")
        else:
            log.error("Can't find any streams for that url")
    else:
        log.error("Can't find any streams for that url")
Exemple #4
0
    def outputfilename(self, data, filename):
        directory = os.path.dirname(filename)
        name = data["video"]["titlePagePath"]
        other = filenamify(data["video"]["title"])
        if "programVersionId" in data["video"]:
            vid = str(data["video"]["programVersionId"])
        else:
            vid = str(data["video"]["id"])
        if is_py2:
            id = hashlib.sha256(vid).hexdigest()[:7]
        else:
            id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        season = self.seasoninfo(data)
        title = name
        if season:
            title += ".%s" % season
        if other:
            title += ".%s" % other
        title += "-%s-svtplay" % id
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #5
0
 def _autoname(self, jsondata):
     match = re.search('^([^/]+)/', jsondata["data"]["attributes"]["path"])
     show = match.group(1)
     season = jsondata["data"]["attributes"]["seasonNumber"]
     episode = jsondata["data"]["attributes"]["episodeNumber"]
     name = jsondata["data"]["attributes"]["name"]
     if is_py2:
         show = filenamify(show).encode("latin1")
     else:
         show = filenamify(show)
     return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(
         show, int(season), int(episode), name))
 def _autoname(self, jsondata):
     show = jsondata["data"][0]["video_metadata_show"]
     season = jsondata["data"][0]["season"]
     episode = jsondata["data"][0]["episode"]
     title = jsondata["data"][0]["title"]
     if is_py2:
         show = filenamify(show).encode("latin1")
         title = filenamify(title).encode("latin1")
     else:
         show = filenamify(show)
         title = filenamify(title)
     return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(show, int(season), int(episode), title))
Exemple #7
0
 def _autoname(self, jsondata):
     show = jsondata["data"][0]["video_metadata_show"]
     season = jsondata["data"][0]["season"]
     episode = jsondata["data"][0]["episode"]
     title = jsondata["data"][0]["title"]
     if is_py2:
         show = filenamify(show).encode("latin1")
         title = filenamify(title).encode("latin1")
     else:
         show = filenamify(show)
         title = filenamify(title)
     return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(
         show, int(season), int(episode), title))
Exemple #8
0
    def _autoname(self, jsondata):
        match = re.search('^([^/]+)/', jsondata["data"]["attributes"]["path"])
        show = match.group(1)
        season = jsondata["data"]["attributes"]["seasonNumber"]
        episode = jsondata["data"]["attributes"]["episodeNumber"]
        name = jsondata["data"]["attributes"]["name"]
        if is_py2:
            show = filenamify(show).encode("latin1")
            name = filenamify(name).encode("latin1")
        else:
            show = filenamify(show)

        return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(show, int(season), int(episode), name))
Exemple #9
0
    def _autoname(self, dataj):
        program = dataj["format_slug"]
        season = None
        episode = None
        title = None

        if "season" in dataj["format_position"]:
            if dataj["format_position"]["season"] > 0:
                season = dataj["format_position"]["season"]
        if season:
            if len(dataj["format_position"]["episode"]) > 0:
                episode = dataj["format_position"]["episode"]
            try:
                episode = int(episode)
            except ValueError:
                title = filenamify(episode)
                episode = None

        if dataj["type"] == "clip":
            # Removes the show name from the end of the filename
            # e.g. Showname.S0X.title instead of Showname.S07.title-showname
            match = re.search(r'(.+)-', dataj["title"])
            if match:
                title = filenamify(match.group(1))
            else:
                title = filenamify(dataj["title"])
            if "derived_from_id" in dataj:
                if dataj["derived_from_id"]:
                    parent_id = dataj["derived_from_id"]
                    parent_episode = self.http.request(
                        "get", "http://playapi.mtgx.tv/v3/videos/{0}".format(
                            parent_id))
                    if parent_episode.status_code != 403:  # if not geoblocked
                        datajparent = json.loads(parent_episode.text)
                        if not season and datajparent["format_position"][
                                "season"] > 0:
                            season = datajparent["format_position"]["season"]
                        if len(datajparent["format_position"]["episode"]) > 0:
                            episode = datajparent["format_position"]["episode"]

        name = filenamify(program)
        if season:
            name = "{0}.s{1:02d}".format(name, int(season))
        if episode:
            name = "{0}e{1:02d}".format(name, int(episode))
        if title:
            name = "{0}.{1}".format(name, title)

        return name
Exemple #10
0
    def _get_static_video(self, options, videoid):
        access = self._get_access_token(videoid)

        if options.output_auto:
            data = self.http.request(
                "get", "https://api.twitch.tv/kraken/videos/v%s" % videoid)
            if data.status_code == 404:
                yield ServiceError("Can't find the video")
                return
            info = json.loads(data.text)
            name = "twitch-%s-%s" % (info["channel"]["name"],
                                     filenamify(info["title"]))
            directory = os.path.dirname(options.output)
            if os.path.isdir(directory):
                name = os.path.join(directory, name)
            options.output = name

        if "token" not in access:
            raise TwitchUrlException('video', self.url)
        nauth = quote_plus(str(access["token"]))
        authsig = access["sig"]

        url = "http://usher.twitch.tv/vod/%s?nauth=%s&nauthsig=%s" % (
            videoid, nauth, authsig)

        streams = hlsparse(options, self.http.request("get", url), url)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Exemple #11
0
    def get(self, options):
        match = re.search(r'data-videoid="([^"]+)"', self.get_urldata())
        if not match:
            parse = urlparse(self.url)
            match = re.search(r'video/(\d+)/', parse.fragment)
            if not match:
                log.error("Can't find video id")
                sys.exit(2)
        videoid = match.group(1)
        data = get_http_data("http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website" % videoid)
        jsondata = json.loads(data)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            title = "%s" % jsondata["title"]
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title
        if "hds" in jsondata["streamUrls"]:
            parse = urlparse(jsondata["streamUrls"]["hds"])
            manifest = "%s://%s%s?%s&hdcore=3.3.0" % (parse.scheme, parse.netloc, parse.path, parse.query)
            streams = hdsparse(copy.copy(options), manifest)
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
        if "hls" in jsondata["streamUrls"]:
            streams = hlsparse(jsondata["streamUrls"]["hls"])
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
        if "mp4" in jsondata["streamUrls"]:
            yield HTTP(copy.copy(options), jsondata["streamUrls"]["mp4"])
Exemple #12
0
    def _get_static_video(self, options, videoid):
        access = self._get_access_token(videoid)

        if options.output_auto:
            data = self.http.request("get", "https://api.twitch.tv/kraken/videos/v%s" % videoid)
            if data.status_code == 404:
                yield ServiceError("Can't find the video")
                return
            info = json.loads(data.text)
            name = "twitch-%s-%s" % (info["channel"]["name"], filenamify(info["title"]))
            directory = os.path.dirname(options.output)
            if os.path.isdir(directory):
                name = os.path.join(directory, name)
            options.output = name

        if "token" not in access:
            raise TwitchUrlException('video', self.url)
        nauth = quote_plus(str(access["token"]))
        authsig = access["sig"]

        url = "http://usher.twitch.tv/vod/%s?nauth=%s&nauthsig=%s" % (
            videoid, nauth, authsig)

        streams = hlsparse(options, self.http.request("get", url), url)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Exemple #13
0
    def outputfilename(self, data, filename, raw):
        directory = os.path.dirname(filename)
        if is_py2:
            id = hashlib.sha256(data["programVersionId"]).hexdigest()[:7]
        else:
            id = hashlib.sha256(data["programVersionId"].encode("utf-8")).hexdigest()[:7]

        datatitle = re.search('data-title="([^"]+)"', self.get_urldata())
        if not datatitle:
            return None
        datat = decode_html_entities(datatitle.group(1))
        name = self.name(datat)
        episode = self.seasoninfo(datat)
        if is_py2:
            name = name.encode("utf8")
        if episode:
            title = "{0}.{1}-{2}-svtplay".format(name, episode, id)
        else:
            title = "{0}-{1}-svtplay".format(name, id)
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #14
0
    def outputfilename(self, data, filename, raw):
        directory = os.path.dirname(filename)
        if is_py2:
            id = hashlib.sha256(data["programVersionId"]).hexdigest()[:7]
        else:
            id = hashlib.sha256(
                data["programVersionId"].encode("utf-8")).hexdigest()[:7]

        datatitle = re.search('data-title="([^"]+)"', self.get_urldata())
        if not datatitle:
            return None
        datat = decode_html_entities(datatitle.group(1))
        name = self.name(datat)
        episode = self.seasoninfo(datat)
        if is_py2:
            name = name.encode("utf8")
        if episode:
            title = "{0}.{1}-{2}-svtplay".format(name, episode, id)
        else:
            title = "{0}-{1}-svtplay".format(name, id)
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #15
0
    def _autoname(self, dataj):
        program = dataj["format_slug"]
        season = None
        episode = None
        title = None

        if "season" in dataj["format_position"]:
            if dataj["format_position"]["season"] > 0:
                season = dataj["format_position"]["season"]
        if season:
            if len(dataj["format_position"]["episode"]) > 0:
                episode = dataj["format_position"]["episode"]
            try:
                episode = int(episode)
            except ValueError:
                title = filenamify(episode)
                episode = None

        if dataj["type"] == "clip":
            #Removes the show name from the end of the filename
            #e.g. Showname.S0X.title instead of Showname.S07.title-showname
            match = re.search(r'(.+)-', dataj["title"])
            if match:
                title = filenamify(match.group(1))
            else:
                title = filenamify(dataj["title"])
            if "derived_from_id" in dataj:
                if dataj["derived_from_id"]:
                    parent_id = dataj["derived_from_id"]
                    parent_episode = self.http.request("get", "http://playapi.mtgx.tv/v3/videos/{0}".format(parent_id))
                    if  parent_episode.status_code != 403: #if not geoblocked
                        datajparent = json.loads(parent_episode.text)
                        if not season and datajparent["format_position"]["season"] > 0:
                            season = datajparent["format_position"]["season"]
                        if len(datajparent["format_position"]["episode"]) > 0:
                            episode = datajparent["format_position"]["episode"]

        name = filenamify(program)
        if season:
            name = "{0}.s{1:02d}".format(name, int(season))
        if episode:
            name = "{0}e{1:02d}".format(name, int(episode))
        if title:
            name = "{0}.{1}".format(name, title)

        return name
Exemple #16
0
 def _autoname(self, jsondata):
     show = jsondata["data"][0]["video_metadata_show"]
     season = jsondata["data"][0]["season"]
     episode = jsondata["data"][0]["episode"]
     title = jsondata["data"][0]["title"]
     if is_py2:
         show = show.encode("latin1")
         title = title.encode("latin1")
     return filenamify("{}.s{:02d}e{:02d}.{}".format(show, int(season), int(episode), title))
Exemple #17
0
 def _autoname(self, jsondata):
     show = jsondata["data"][0]["video_metadata_show"]
     season = jsondata["data"][0]["season"]
     episode = jsondata["data"][0]["episode"]
     title = jsondata["data"][0]["title"]
     if is_py2:
         show = show.encode("latin1")
         title = title.encode("latin1")
     return filenamify("{}.s{:02d}e{:02d}.{}".format(show, int(season), int(episode), title))
Exemple #18
0
    def get(self, options):
        parse = urlparse(self.url)
        if parse.hostname == "video.disney.se":
            match = re.search(r"Grill.burger=({.*}):", self.get_urldata())
            if not match:
                log.error("Can't find video info")
                return
            jsondata = json.loads(match.group(1))
            for n in jsondata["stack"]:
                if len(n["data"]) > 0:
                    for x in n["data"]:
                        if "flavors" in x:
                            for i in x["flavors"]:
                                if i["format"] == "mp4":
                                    yield HTTP(copy.copy(options), i["url"],
                                               i["bitrate"])
        else:
            match = re.search(r"uniqueId : '([^']+)'", self.get_urldata())
            if not match:
                log.error("Can't find video info")
                return
            uniq = match.group(1)
            match = re.search("entryId : '([^']+)'", self.get_urldata())
            entryid = match.group(1)
            match = re.search("partnerId : '([^']+)'", self.get_urldata())
            partnerid = match.group(1)
            match = re.search("uiConfId : '([^']+)'", self.get_urldata())
            uiconfid = match.group(1)


            url = "http://cdnapi.kaltura.com/html5/html5lib/v1.9.7.6/mwEmbedFrame.php?&wid=%s&uiconf_id=%s&entry_id=%s&playerId=%s&forceMobileHTML5=true&urid=1.9.7.6&callback=mwi" % \
            (partnerid, uiconfid, entryid, uniq)
            data = get_http_data(url)
            match = re.search(r"mwi\(({.*})\);", data)
            jsondata = json.loads(match.group(1))
            data = jsondata["content"]
            match = re.search(r"window.kalturaIframePackageData = ({.*});",
                              data)
            jsondata = json.loads(match.group(1))
            ks = jsondata["enviornmentConfig"]["ks"]
            if options.output_auto:
                name = jsondata["entryResult"]["meta"]["name"]
                directory = os.path.dirname(options.output)
                options.service = "disney"
                title = "%s-%s" % (name, options.service)
                title = filenamify(title)
                if len(directory):
                    options.output = "%s/%s" % (directory, title)
                else:
                    options.output = title

            url = "http://cdnapi.kaltura.com/p/%s/sp/%s00/playManifest/entryId/%s/format/applehttp/protocol/http/a.m3u8?ks=%s&referrer=aHR0cDovL3d3dy5kaXNuZXkuc2U=&" % (
                partnerid[1:], partnerid[1:], entryid, ks)
            redirect = check_redirect(url)
            streams = hlsparse(redirect)
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
Exemple #19
0
    def outputfilename(self, data, filename):
        if filename:
            directory = os.path.dirname(filename)
        else:
            directory = ""
        name = None
        if "programTitle" in data and data["programTitle"]:
            name = filenamify(data["programTitle"])
        elif "titleSlug" in data and data["titleSlug"]:
            name = filenamify(data["titleSlug"])
        other = filenamify(data["title"])

        if "programVersionId" in data:
            vid = str(data["programVersionId"])
        else:
            vid = str(data["id"])
        if is_py2:
            id = hashlib.sha256(vid).hexdigest()[:7]
        else:
            id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        elif name is None:
            name = other
            other = None
        season = self.seasoninfo(data)
        title = name
        if season:
            title += ".{}".format(season)
        if other:
            title += ".{}".format(other)
        if "accessService" in data:
            if data["accessService"] == "audioDescription":
                title += "-syntolkat"
            if data["accessService"] == "signInterpretation":
                title += "-teckentolkat"
        title += "-{}-{}".format(id, self.__class__.__name__.lower())
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #20
0
    def outputfilename(self, data, filename):
        if filename:
            directory = os.path.dirname(filename)
        else:
            directory = ""
        name = None
        if "programTitle" in data and data["programTitle"]:
            name = filenamify(data["programTitle"])
        elif "titleSlug" in data and data["titleSlug"]:
            name = filenamify(data["titleSlug"])
        other = filenamify(data["title"])

        if "programVersionId" in data:
            vid = str(data["programVersionId"])
        else:
            vid = str(data["id"])
        if is_py2:
            id = hashlib.sha256(vid).hexdigest()[:7]
        else:
            id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        elif name is None:
            name = other
            other = None
        season = self.seasoninfo(data)
        title = name
        if season:
            title += ".{}".format(season)
        if other:
            title += ".{}".format(other)
        if "accessService" in data:
            if data["accessService"] == "audioDescription":
                title += "-syntolkat"
            if data["accessService"] == "signInterpretation":
                title += "-teckentolkat"
        title += "-{}-{}".format(id, self.__class__.__name__.lower())
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #21
0
    def get(self):
        data = self.get_urldata()
        match = re.search(r"urPlayer.init\((.*)\);", data)
        if not match:
            yield ServiceError("Can't find json info")
            return

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        data = match.group(1)
        jsondata = json.loads(data)
        if len(jsondata["subtitles"]) > 0:
            for sub in jsondata["subtitles"]:
                if "label" in sub:
                    absurl = urljoin(self.url, sub["file"].split(",")[0])
                    if absurl.endswith("vtt"):
                        subtype = "wrst"
                    else:
                        subtype = "tt"
                    if self.options.get_all_subtitles:
                        yield subtitle(copy.copy(self.options), subtype,
                                       absurl, "-" + filenamify(sub["label"]))
                    else:
                        yield subtitle(copy.copy(self.options), subtype,
                                       absurl)

        if "streamer" in jsondata["streaming_config"]:
            basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
        else:
            url = jsondata["streaming_config"]["loadbalancer"]
            if url[:1] == "/":
                url = "https:{}".format(url)
            lbjson = self.http.request("get", url).text
            lbjson = json.loads(lbjson)
            basedomain = lbjson["redirect"]
        http = "https://{0}/{1}".format(basedomain, jsondata["file_http"])
        hd = None
        if len(jsondata["file_http_hd"]) > 0:
            http_hd = "https://{0}/{1}".format(basedomain,
                                               jsondata["file_http_hd"])
            hls_hd = "{0}{1}".format(
                http_hd,
                jsondata["streaming_config"]["http_streaming"]["hls_file"])
            hd = True
        hls = "{0}{1}".format(
            http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
        streams = hlsparse(self.options, self.http.request("get", hls), hls)
        for n in list(streams.keys()):
            yield streams[n]
        if hd:
            streams = hlsparse(self.options, self.http.request("get", hls_hd),
                               hls_hd)
            for n in list(streams.keys()):
                yield streams[n]
Exemple #22
0
    def get(self, options):
        parse = urlparse(self.url)
        if parse.hostname == "video.disney.se":
            match = re.search(r"Grill.burger=({.*}):", self.get_urldata())
            if not match:
                log.error("Can't find video info")
                return
            jsondata = json.loads(match.group(1))
            for n in jsondata["stack"]:
                if len(n["data"]) > 0:
                    for x in n["data"]:
                        if "flavors" in x:
                            for i in x["flavors"]:
                                if i["format"] == "mp4":
                                    yield HTTP(copy.copy(options), i["url"], i["bitrate"])
        else:
            match = re.search(r"uniqueId : '([^']+)'", self.get_urldata())
            if not match:
                log.error("Can't find video info")
                return
            uniq = match.group(1)
            match = re.search("entryId : '([^']+)'", self.get_urldata())
            entryid = match.group(1)
            match = re.search("partnerId : '([^']+)'", self.get_urldata())
            partnerid = match.group(1)
            match = re.search("uiConfId : '([^']+)'", self.get_urldata())
            uiconfid = match.group(1)


            url = "http://cdnapi.kaltura.com/html5/html5lib/v1.9.7.6/mwEmbedFrame.php?&wid=%s&uiconf_id=%s&entry_id=%s&playerId=%s&forceMobileHTML5=true&urid=1.9.7.6&callback=mwi" % \
            (partnerid, uiconfid, entryid, uniq)
            data = get_http_data(url)
            match = re.search(r"mwi\(({.*})\);", data)
            jsondata = json.loads(match.group(1))
            data = jsondata["content"]
            match = re.search(r"window.kalturaIframePackageData = ({.*});", data)
            jsondata = json.loads(match.group(1))
            ks = jsondata["enviornmentConfig"]["ks"]
            if options.output_auto:
                name = jsondata["entryResult"]["meta"]["name"]
                directory = os.path.dirname(options.output)
                options.service = "disney"
                title = "%s-%s" % (name, options.service)
                title = filenamify(title)
                if len(directory):
                    options.output = "%s/%s" % (directory, title)
                else:
                    options.output = title

            url = "http://cdnapi.kaltura.com/p/%s/sp/%s00/playManifest/entryId/%s/format/applehttp/protocol/http/a.m3u8?ks=%s&referrer=aHR0cDovL3d3dy5kaXNuZXkuc2U=&" % (partnerid[1:], partnerid[1:], entryid, ks)
            redirect  = check_redirect(url)
            streams = hlsparse(redirect)
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
Exemple #23
0
    def outputfilename(self, data, filename):
        if filename:
            directory = os.path.dirname(filename)
        else:
            directory = ""
        name = None
        if data["programTitle"]:
            name = filenamify(data["programTitle"])
        other = filenamify(data["title"])

        if "programVersionId" in data:
            vid = str(data["programVersionId"])
        else:
            vid = str(data["id"])
        if is_py2:
            id = hashlib.sha256(vid).hexdigest()[:7]
        else:
            id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        elif name is None:
            name = other
            other = None
        season = self.seasoninfo(data)
        title = name
        if season:
            title += ".%s" % season
        if other:
            title += ".%s" % other
        if data["accessServices"]["audioDescription"]:
            title += "-syntolkat"
        if data["accessServices"]["signInterpretation"]:
            title += "-teckentolkat"
        title += "-%s-svtplay" % id
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #24
0
    def outputfilename(self, data, filename):
        if filename:
            directory = os.path.dirname(filename)
        else:
            directory = ""
        name = None
        if data["programTitle"]:
            name = filenamify(data["programTitle"])
        other = filenamify(data["title"])

        if "programVersionId" in data:
            vid = str(data["programVersionId"])
        else:
            vid = str(data["id"])
        if is_py2:
            id = hashlib.sha256(vid).hexdigest()[:7]
        else:
            id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        elif name is None:
            name = other
            other = None
        season = self.seasoninfo(data)
        title = name
        if season:
            title += ".%s" % season
        if other:
            title += ".%s" % other
        if data["accessServices"]["audioDescription"]:
            title += "-syntolkat"
        if data["accessServices"]["signInterpretation"]:
            title += "-teckentolkat"
        title += "-%s-svtplay" % id
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #25
0
def outputfilename(data, filename, raw):
    directory = os.path.dirname(filename)
    name = data["statistics"]["folderStructure"]
    if name.find(".") > 0:
        name = name[:name.find(".")]
    match = re.search("^arkiv-", name)
    if match:
        name = name.replace("arkiv-", "")
    name = name.replace("-", ".")
    season = seasoninfo(raw)
    other = filenamify(data["context"]["title"])
    if season:
        title = "%s.%s.%s-%s-svtplay" % (name, season, other, data["videoId"])
    else:
        title = "%s.%s-%s-svtplay" % (name, other, data["videoId"])
    title = filenamify(title)
    if len(directory):
        output = os.path.join(directory, title)
    else:
        output = title
    return output
Exemple #26
0
 def _autoname(self, dataj):
     program = dataj["format_slug"]
     season = dataj["format_position"]["season"]
     episode = None
     if season:
         if len(dataj["format_position"]["episode"]) > 0:
             episode = dataj["format_position"]["episode"]
     name = filenamify(program)
     if season:
         name = "%s.s%s" % (name, season)
     if episode:
         name = "%se%s" % (name, episode)
     return name
Exemple #27
0
 def _autoname(self, dataj):
     program = dataj["format_slug"]
     season = dataj["format_position"]["season"]
     episode = None
     if season:
         if len(dataj["format_position"]["episode"]) > 0:
             episode = dataj["format_position"]["episode"]
     name = filenamify(program)
     if season:
         name = "{}.s{:02d}".format(name, int(season))
     if episode:
         name = "{}e{:02d}".format(name, int(episode))
     return name
Exemple #28
0
    def _get_static_video(self, options, videoid):
        access = self._get_access_token(videoid)

        if options.output_auto:
            info = json.loads(get_http_data("https://api.twitch.tv/kraken/videos/v%s" % videoid)[1])
            if info["description"]:
                options.output = "twitch-%s-%s_%s" % (info["channel"]["name"], filenamify(info["title"]), filenamify(info["description"]))
            else:
                options.output = "twitch-%s-%s" % (info["channel"]["name"], filenamify(info["title"]))

        if "token" not in access:
            raise JustinUrlException('video', self.url)
        nauth = quote_plus(str(access["token"]))
        authsig = access["sig"]

        url = "http://usher.twitch.tv/vod/%s?nauth=%s&nauthsig=%s" % (
            videoid, nauth, authsig)

        streams = hlsparse(url)
        if streams:
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
Exemple #29
0
def filename(stream):
    if stream.options.output:
        if is_py2:
            if platform.system() == "Windows":
                stream.options.output = stream.options.output.decode("latin1")
            else:
                stream.options.output = stream.options.output.decode("utf-8")
    if not stream.options.output or os.path.isdir(stream.options.output):
        data = ensure_unicode(stream.get_urldata())
        if data is None:
            return False
        match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S)
        if match:
            stream.options.output_auto = True
            title_tag = decode_html_entities(match.group(1))
            if not stream.options.output:
                stream.options.output = filenamify(title_tag)
            else:
                # output is a directory
                stream.options.output = os.path.join(stream.options.output, filenamify(title_tag))

    return True
Exemple #30
0
 def _autoname(self, dataj):
     program = dataj["format_slug"]
     season = dataj["format_position"]["season"]
     episode = None
     if season:
         if len(dataj["format_position"]["episode"]) > 0:
             episode = dataj["format_position"]["episode"]
     name = filenamify(program)
     if season:
         name = "%s.s%s" % (name, season)
     if episode:
         name = "%se%s" % (name, episode)
     return name
Exemple #31
0
def filename(stream):
    if stream.options.output:
        if is_py2:
            if platform.system() == "Windows":
                stream.options.output = stream.options.output.decode("latin1")
            else:
                stream.options.output = stream.options.output.decode("utf-8")
    if not stream.options.output or os.path.isdir(stream.options.output):
        data = ensure_unicode(stream.get_urldata())
        if data is None:
            return False
        match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S)
        if match:
            stream.options.output_auto = True
            title_tag = decode_html_entities(match.group(1))
            if not stream.options.output:
                stream.options.output = filenamify(title_tag)
            else:
                # output is a directory
                stream.options.output = os.path.join(stream.options.output, filenamify(title_tag))

    return True
Exemple #32
0
    def get(self):
        data = self.get_urldata()
        match = re.search(r"urPlayer.init\((.*)\);", data)
        if not match:
            yield ServiceError("Can't find json info")
            return

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        data = match.group(1)
        jsondata = json.loads(data)
        if len(jsondata["subtitles"]) > 0:
            for sub in jsondata["subtitles"]:
                if "label" in sub:
                    if self.options.get_all_subtitles:
                        yield subtitle(copy.copy(self.options), "tt",
                                       sub["file"].split(",")[0],
                                       "-" + filenamify(sub["label"]))
                    else:
                        yield subtitle(copy.copy(self.options), "tt",
                                       sub["file"].split(",")[0])

        if "streamer" in jsondata["streaming_config"]:
            basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
        else:
            lbjson = self.http.request(
                "get", jsondata["streaming_config"]["loadbalancer"]).text
            lbjson = json.loads(lbjson)
            basedomain = lbjson["redirect"]
        http = "http://%s/%s" % (basedomain, jsondata["file_http"])
        hd = None
        if len(jsondata["file_http_hd"]) > 0:
            http_hd = "http://%s/%s" % (basedomain, jsondata["file_http_hd"])
            hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]
                               ["http_streaming"]["hls_file"])
            hd = True
        hls = "%s%s" % (
            http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
        streams = hlsparse(self.options, self.http.request("get", hls), hls)
        for n in list(streams.keys()):
            yield streams[n]
        if hd:
            streams = hlsparse(self.options, self.http.request("get", hls_hd),
                               hls_hd)
            for n in list(streams.keys()):
                yield streams[n]
Exemple #33
0
    def get(self):

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        parse = urlparse(self.url)

        if not parse.path.startswith("/video"):
            yield ServiceError("Can't find video info")
            return

        wanted_id = parse.path[7:]
        current_time = int(
            (datetime.utcnow() - datetime.utcfromtimestamp(0)).total_seconds()
            * 1000)

        api_url = "https://www.atgplay.se/api/{0}/video/{1}".format(
            current_time, wanted_id)
        video_assets = self.http.request("get", api_url)

        try:
            janson = json.loads(video_assets.text)
        except json.decoder.JSONDecodeError:
            yield ServiceError("Can't decode api request: {0}".format(
                video_assets.text))
            return

        if "title" in janson:
            directory = os.path.dirname(self.options.output)
            title = filenamify(janson["title"])
            self.options.output = os.path.join(directory, title)

        if "urls" in janson:
            for i in janson["urls"]:
                stream = None
                if "m3u" == i:
                    stream = hlsparse(
                        self.options,
                        self.http.request("get", janson["urls"]["m3u"]),
                        janson["urls"]["m3u"])

                if stream:
                    for key in list(stream.keys()):
                        yield stream[key]
Exemple #34
0
    def get(self, options):
        error, data = self.get_urldata()
        if error:
            log.error("Can't get the page")
            return
        match = re.search(r'data-videoid="([^"]+)"', data)
        if not match:
            parse = urlparse(self.url)
            match = re.search(r'video/(\d+)/', parse.fragment)
            if not match:
                log.error("Can't find video file for: %s", self.url)
                return
        videoid = match.group(1)
        error, data = get_http_data("http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website" % videoid)
        if error:
            log.error("Cant get video info")
            return
        jsondata = json.loads(data)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            title = "%s" % jsondata["title"]
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        if self.exclude(options):
            return

        if "hds" in jsondata["streamUrls"]:
            streams = hdsparse(copy.copy(options), jsondata["streamUrls"]["hds"])
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
        if "hls" in jsondata["streamUrls"]:
            streams = hlsparse(jsondata["streamUrls"]["hls"])
            for n in list(streams.keys()):
                yield HLS(copy.copy(options), streams[n], n)
        if "mp4" in jsondata["streamUrls"]:
            yield HTTP(copy.copy(options), jsondata["streamUrls"]["mp4"])
Exemple #35
0
    def get(self):
        data = self.get_urldata()

        parse = urlparse(self.url)
        match = re.search(r'^/([a-z]{2})/', parse.path)
        if not match:
            yield ServiceError("Cant county code")
            return

        res = self.http.get(
            "http://www.pokemon.com/api/pokemontv/channels?region={0}".format(
                match.group(1)))
        janson = res.json()
        match = re.search('data-video-season="([0-9]+)"', data)
        season = match.group(1)
        match = re.search('data-video-episode="([0-9]+)"', data)
        episode = match.group(1)

        for i in janson:
            for n in i["media"]:
                if season == n["season"] and episode == n["episode"]:
                    stream = n["stream_url"]

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            basename = os.path.basename(self.options.output)
            title = "pokemon.s{0}e{1}-{2}".format(season, episode, basename)
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        streams = hlsparse(self.options, self.http.request("get", stream),
                           stream)
        for n in list(streams.keys()):
            yield streams[n]
Exemple #36
0
    def get(self):
        data = self.get_urldata()

        parse = urlparse(self.url)
        match = re.search(r'^/([a-z]{2})/', parse.path)
        if not match:
            yield ServiceError("Cant county code")
            return

        res = self.http.get("http://www.pokemon.com/api/pokemontv/channels?region={0}".format(match.group(1)))
        janson = res.json()
        match = re.search('data-video-season="([0-9]+)"', data)
        season = match.group(1)
        match = re.search('data-video-episode="([0-9]+)"', data)
        episode = match.group(1)

        for i in janson:
            for n in i["media"]:
                if season == n["season"] and episode == n["episode"]:
                    stream = n["stream_url"]

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            basename = os.path.basename(self.options.output)
            title = "pokemon.s{0}e{1}-{2}".format(season, episode, basename)
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        streams = hlsparse(self.options, self.http.request("get", stream), stream)
        for n in list(streams.keys()):
            yield streams[n]
Exemple #37
0
    def get(self):

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        parse = urlparse(self.url)

        if not parse.path.startswith("/video"):
            yield ServiceError("Can't find video info")
            return

        wanted_id = parse.path[7:]
        current_time = int((datetime.utcnow() - datetime.utcfromtimestamp(0)).total_seconds() * 1000)

        api_url = "https://www.atgplay.se/api/{0}/video/{1}".format(current_time, wanted_id)
        video_assets = self.http.request("get", api_url)

        try:
            janson = json.loads(video_assets.text)
        except json.decoder.JSONDecodeError:
            yield ServiceError("Can't decode api request: {0}".format(video_assets.text))
            return

        if "title" in janson:
            directory = os.path.dirname(self.options.output)
            title = filenamify(janson["title"])
            self.options.output = os.path.join(directory, title)

        if "urls" in janson:
            for i in janson["urls"]:
                stream = None
                if "m3u" == i:
                    stream = hlsparse(self.options, self.http.request("get", janson["urls"]["m3u"]), janson["urls"]["m3u"])

                if stream:
                    for key in list(stream.keys()):
                            yield stream[key]
Exemple #38
0
    def outputfilename(self, data, filename, raw):
        directory = os.path.dirname(filename)
        if "statistics" in data:
            name = data["statistics"]["folderStructure"]
            if name.find(".") > 0:
                name = name[:name.find(".")]
            match = re.search("^arkiv-", name)
            if match:
                name = name.replace("arkiv-", "")
            name = filenamify(name.replace("-", "."))
            other = filenamify(data["context"]["title"])
            id = data["videoId"]
        else:
            name = data["programTitle"]
            if not name:
                match = re.search('data-title="([^"]+)"', raw)
                if match:
                    name = filenamify(match.group(1).replace(" - ", "."))
                other = None
            else:
                if name.find(".") > 0:
                    name = name[:name.find(".")]
                name = filenamify(name.replace(" - ", "."))
                other = filenamify(data["episodeTitle"])
            if is_py2:
                id = hashlib.sha256(data["programVersionId"]).hexdigest()[:7]
            else:
                id = hashlib.sha256(
                    data["programVersionId"].encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        season = self.seasoninfo(raw)
        title = name
        if season:
            title += ".%s" % season
        if other:
            title += ".%s" % other
        title += "-%s-svtplay" % id
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #39
0
    def get(self):
        data = self.get_urldata()
        match = re.search(r'data-videoid="([^"]+)"', data)
        if not match:
            parse = urlparse(self.url)
            match = re.search(r'video/(\d+)/', parse.fragment)
            if not match:
                yield ServiceError("Can't find video file for: %s" % self.url)
                return
        videoid = match.group(1)
        data = self.http.request("get", "http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website" % videoid).text
        jsondata = json.loads(data)

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            title = "%s" % jsondata["title"]
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "hds" in jsondata["streamUrls"]:
            streams = hdsparse(self.options, self.http.request("get", jsondata["streamUrls"]["hds"], params={"hdcore": "3.7.0"}), jsondata["streamUrls"]["hds"])
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
        if "hls" in jsondata["streamUrls"]:
            streams = hlsparse(self.options, self.http.request("get", jsondata["streamUrls"]["hls"]), jsondata["streamUrls"]["hls"])
            for n in list(streams.keys()):
                yield streams[n]
        if "mp4" in jsondata["streamUrls"]:
            yield HTTP(copy.copy(self.options), jsondata["streamUrls"]["mp4"])
Exemple #40
0
    def outputfilename(self, data, filename, raw):
        directory = os.path.dirname(filename)
        if "statistics" in data:
            name = data["statistics"]["folderStructure"]
            if name.find(".") > 0:
                name = name[:name.find(".")]
            match = re.search("^arkiv-", name)
            if match:
                name = name.replace("arkiv-", "")
            name = filenamify(name.replace("-", "."))
            other = filenamify(data["context"]["title"])
            id = data["videoId"]
        else:
            name = data["programTitle"]
            if not name:
                match = re.search('data-title="([^"]+)"', raw)
                if match:
                    name = filenamify(match.group(1).replace(" - ", "."))
                other = None
            else:
                if name.find(".") > 0:
                    name = name[:name.find(".")]
                name = filenamify(name.replace(" - ", "."))
                other = filenamify(data["episodeTitle"])
            if is_py2:
                id = hashlib.sha256(data["programVersionId"]).hexdigest()[:7]
            else:
                id = hashlib.sha256(data["programVersionId"].encode("utf-8")).hexdigest()[:7]

        if name == other:
            other = None
        season = self.seasoninfo(raw)
        title = name
        if season:
            title += ".%s" % season
        if other:
            title += ".%s" % other
        title += "-%s-svtplay" % id
        title = filenamify(title)
        if len(directory):
            output = os.path.join(directory, title)
        else:
            output = title
        return output
Exemple #41
0
    def get(self, options):
        data = self.get_urldata()

        vid = findvid(self.url, data)
        if vid is None:
            yield ServiceError("Can't find video id for %s" % self.url)
            return

        if options.username and options.password:
            work = self._login(options.username, options.password)
            if isinstance(work, Exception):
                yield work
                return

        url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid
        data = self.http.request("get", url, cookies=self.cookies)
        if data.status_code == 401:
            xml = ET.XML(data.content)
            code = xml.find("code").text
            if code == "SESSION_NOT_AUTHENTICATED":
                yield ServiceError("Can't access premium content")
            elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION":
                yield ServiceError("Can't downoad this video because of geoblocked.")
            else:
                yield ServiceError("Can't find any info for that video")
            return
        if data.status_code == 404:
            yield ServiceError("Can't find the video api")
            return
        xml = ET.XML(data.content)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            if xml.find("live").text != "false":
                options.live = True
        if xml.find("drmProtected").text == "true":
            yield ServiceError("We cant download DRM protected content from this site.")
            return

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "tv4play"
            basename = self._autoname(vid)
            if basename is None:
                yield ServiceError("Cant find vid id for autonaming")
                return
            title = "%s-%s-%s" % (basename, vid, options.service)
            title = filenamify(title)
            if len(directory):
                options.output = os.path.join(directory, title)
            else:
                options.output = title

        if self.exclude(options):
            yield ServiceError("Excluding video")
            return

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if "rtmp" in base.scheme:
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    options.other = "-W %s -y %s" % (swf, i.find("url").text)
                    yield RTMP(copy.copy(options), i.find("base").text, i.find("bitrate").text)
                elif parse.path[len(parse.path)-3:len(parse.path)] == "f4m":
                    streams = hdsparse(options, self.http.request("get", i.find("url").text, params={"hdcore": "3.7.0"}), i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "smi":
                yield subtitle(copy.copy(options), "smi", i.find("url").text)

        url = "http://premium.tv4play.se/api/web/asset/%s/play?protocol=hls" % vid
        data = self.http.request("get", url, cookies=self.cookies).content
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(options, self.http.request("get", i.find("url").text), i.find("url").text)
                    for n in list(streams.keys()):
                        yield streams[n]
Exemple #42
0
    def get(self):
        parse = urlparse(self.url)
        if parse.hostname == "video.disney.se" or parse.hostname == "disneyjunior.disney.se":
            data = self.get_urldata()

            if self.exclude():
                yield ServiceError("Excluding video")
                return

            match = re.search(r"Grill.burger=({.*}):", data)
            if not match:
                yield ServiceError("Can't find video info")
                return
            jsondata = json.loads(match.group(1))
            for n in jsondata["stack"]:
                if len(n["data"]) > 0:
                    for x in n["data"]:
                        if "flavors" in x:
                            for i in x["flavors"]:
                                if i["format"] == "mp4":
                                    res = self.http.get(i["url"])
                                    match = re.search(
                                        'button primary" href="([^"]+)"',
                                        res.text)
                                    if match:
                                        yield HTTP(copy.copy(self.options),
                                                   match.group(1),
                                                   i["bitrate"])
        else:
            data = self.get_urldata()
            match = re.search(r"uniqueId : '([^']+)'", data)
            if not match:
                yield ServiceError("Can't find video info")
                return
            uniq = match.group(1)
            match = re.search("entryId : '([^']+)'", self.get_urldata())
            entryid = match.group(1)
            match = re.search("partnerId : '([^']+)'", self.get_urldata())
            partnerid = match.group(1)
            match = re.search("uiConfId : '([^']+)'", self.get_urldata())
            uiconfid = match.group(1)

            match = re.search("json : ({.*}}),", self.get_urldata())
            jsondata = json.loads(match.group(1))
            parse = urlparse(self.url)
            if len(parse.fragment) > 0:
                entry = parse.fragment[parse.fragment.rindex("/") + 1:]
                if entry in jsondata["idlist"]:
                    entryid = jsondata["idlist"][entry]
                else:
                    yield ServiceError("Cant find video info")
                    return
            if self.options.output_auto:
                for i in jsondata["playlists"][0]["playlist"]:
                    if entryid in i["id"]:
                        title = i["longId"]
                        break

                directory = os.path.dirname(self.options.output)
                self.options.service = "disney"
                title = "%s-%s" % (title, self.options.service)
                title = filenamify(title)
                if len(directory):
                    self.options.output = os.path.join(directory, title)
                else:
                    self.options.output = title

            url = "http://cdnapi.kaltura.com/html5/html5lib/v1.9.7.6/mwEmbedFrame.php?&wid=%s&uiconf_id=%s&entry_id=%s&playerId=%s&forceMobileHTML5=true&urid=1.9.7.6&callback=mwi" % \
            (partnerid, uiconfid, entryid, uniq)
            data = self.http.request("get", url).text
            match = re.search(r"mwi\(({.*})\);", data)
            jsondata = json.loads(match.group(1))
            data = jsondata["content"]
            match = re.search(r"window.kalturaIframePackageData = ({.*});",
                              data)
            jsondata = json.loads(match.group(1))
            ks = jsondata["enviornmentConfig"]["ks"]
            if self.options.output_auto:
                name = jsondata["entryResult"]["meta"]["name"]
                directory = os.path.dirname(self.options.output)
                self.options.service = "disney"
                title = "%s-%s" % (name, self.options.service)
                title = filenamify(title)
                if len(directory):
                    self.options.output = os.path.join(directory, title)
                else:
                    self.options.output = title

            if self.exclude():
                return

            url = "http://cdnapi.kaltura.com/p/%s/sp/%s00/playManifest/entryId/%s/format/applehttp/protocol/http/a.m3u8?ks=%s&referrer=aHR0cDovL3d3dy5kaXNuZXkuc2U=&" % (
                partnerid[1:], partnerid[1:], entryid, ks)
            redirect = self.http.check_redirect(url)
            streams = hlsparse(self.options,
                               self.http.request("get", redirect), redirect)
            for n in list(streams.keys()):
                yield streams[n]
Exemple #43
0
    def get(self):
        data = self.http.get("https://www.sportlib.se/sportlib/login").text
        match = re.search('src="(/app[^"]+)">', data)
        if not match:
            yield ServiceError("Can't find url for login info")
            return

        url = urljoin("https://www.sportlib.se", match.group(1))
        data = self.http.get(url).text
        match = re.search('CLIENT_SECRET:"([^"]+)"', data)
        if not match:
            yield ServiceError("Cant fint login info")
            return
        cs = match.group(1)
        match = re.search('CLIENT_ID:"([^"]+)"', data)
        if not match:
            yield ServiceError("Cant fint login info")
            return
        cid = match.group(1)
        res = self.http.get("https://core.oz.com/channels?slug=sportlib&org=www.sportlib.se")
        janson = res.json()
        sid = janson["data"][0]["id"]

        data = {"client_id": cid, "client_secret": cs, "grant_type": "password",
                "username": self.options.username, "password": self.options.password}
        res = self.http.post("https://core.oz.com/oauth2/token?channelId={}".format(sid), data=data)
        if res.status_code > 200:
            yield ServiceError("Wrong username / password?")
            return
        janson = res.json()
        token_type = janson["token_type"].title()
        access_token = janson["access_token"]

        parse = urlparse(self.url)
        match = re.search("video/([-a-fA-F0-9]+)", parse.path)
        if not match:
            yield ServiceError("Cant find video id")
            return
        vid = match.group(1)

        headers = {"content-type": "application/json", "authorization": "{} {}".format(token_type, access_token)}
        url = "https://core.oz.com/channels/{}/videos/{}?include=collection,streamUrl".format(sid, vid)
        res = self.http.get(url, headers=headers)
        janson = res.json()
        cookiename = janson["data"]["streamUrl"]["cookieName"]
        token = janson["data"]["streamUrl"]["token"]
        hlsplaylist = janson["data"]["streamUrl"]["cdnUrl"]

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            title = filenamify(janson["data"]["title"])
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        # get cookie
        postjson = {"name": cookiename, "value": token}
        res = self.http.post("https://playlist.oz.com/cookie", json=postjson)
        cookies = res.cookies
        streams = hlsparse(self.options, self.http.request("get", hlsplaylist), hlsplaylist, keycookie=cookies)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Exemple #44
0
 def test(self):
     for inp, ref in self.test_values:
         self.assertEqual(filenamify(inp), ref)
    def get(self):
        data = self.get_urldata()
        match = re.search(r"urPlayer.init\((.*)\);", data)
        if not match:
            yield ServiceError("Can't find json info")
            return

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        data = match.group(1)
        jsondata = json.loads(data)
        if len(jsondata["subtitles"]) > 0:
            for sub in jsondata["subtitles"]:
                if "label" in sub:
                    absurl = urljoin(self.url, sub["file"].split(",")[0])
                    if absurl.endswith("vtt"):
                        subtype = "wrst"
                    else:
                        subtype = "tt"
                    if self.options.get_all_subtitles:
                        yield subtitle(copy.copy(self.options), subtype, absurl, "-" + filenamify(sub["label"]))
                    else:
                        yield subtitle(copy.copy(self.options), subtype, absurl)

        if "streamer" in jsondata["streaming_config"]:
            basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
        else:
            lbjson = self.http.request("get", jsondata["streaming_config"]["loadbalancer"]).text
            lbjson = json.loads(lbjson)
            basedomain = lbjson["redirect"]
        http = "http://%s/%s" % (basedomain, jsondata["file_http"])
        hd = None
        if len(jsondata["file_http_hd"]) > 0:
            http_hd = "http://%s/%s" % (basedomain, jsondata["file_http_hd"])
            hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"])
            hd = True
        hls = "%s%s" % (http, jsondata["streaming_config"]["http_streaming"]["hls_file"])
        streams = hlsparse(self.options, self.http.request("get", hls), hls)
        for n in list(streams.keys()):
            yield streams[n]
        if hd:
            streams = hlsparse(self.options, self.http.request("get", hls_hd), hls_hd)
            for n in list(streams.keys()):
                yield streams[n]
Exemple #46
0
    def get(self):
        if not self.options.username or not self.options.password:
            yield ServiceError("You need username and password to download things from this site.")
            return

        token, message = self._login()
        if not token:
            yield ServiceError(message)
            return

        res = self.http.get(self.url)
        match = re.search('data-asset-id="([^"]+)"', res.text)
        if not match:
            yield ServiceError("Can't find video id")
            return

        tld = self._gettld()
        url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}/play.json?protocol=VUDASH".format(tld, match.group(1))
        res = self.http.get(url, headers={"authorization": "Bearer {0}".format(token)})
        janson = res.json()
        if "error" in janson:
            yield ServiceError("This video is geoblocked")
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "cmore"
            basename = self._autoname(match.group(1))
            if basename is None:
                yield ServiceError("Cant find vid id for autonaming")
                return
            title = "{0}-{1}-{2}".format(basename, match.group(1), self.options.service)
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        if "drmProtected" in janson["playback"]:
            if janson["playback"]["drmProtected"]:
                yield ServiceError("DRM protected. Can't do anything")
                return

        if isinstance(janson["playback"]["items"]["item"], list):
            for i in janson["playback"]["items"]["item"]:
                if i["mediaFormat"] == "ism":
                    streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"])
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                if i["mediaFormat"] == "webvtt":
                    yield subtitle(copy.copy(self.options), "wrst", i["url"])
        else:
            i = janson["playback"]["items"]["item"]
            if i["mediaFormat"] == "ism":
                streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"])
                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
Exemple #47
0
 def _autoname(self, jsondata):
     show = jsondata["data"][0]["video_metadata_show"]
     season = jsondata["data"][0]["season"]
     episode = jsondata["data"][0]["episode"]
     title = jsondata["data"][0]["title"]
     return filenamify("%s.s%se%s.%s" % (show, season, episode, title))
Exemple #48
0
    def get(self):
        data = self.get_urldata()

        vid = findvid(self.url, data)
        if vid is None:
            yield ServiceError("Can't find video id for %s" % self.url)
            return

        # if self.options.username and self.options.password:
        # work = self._login(self.options.username, self.options.password)
        # if isinstance(work, Exception):
        # yield work
        # return

        url = "http://prima.tv4play.se/api/web/asset/%s/play" % vid
        data = self.http.request("get", url, cookies=self.cookies)
        if data.status_code == 401:
            xml = ET.XML(data.content)
            code = xml.find("code").text
            if code == "SESSION_NOT_AUTHENTICATED":
                yield ServiceError("Can't access premium content")
            elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION":
                yield ServiceError(
                    "Can't download this video because of geoblock.")
            else:
                yield ServiceError("Can't find any info for that video")
            return
        if data.status_code == 404:
            yield ServiceError("Can't find the video api")
            return
        xml = ET.XML(data.content)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            if xml.find("live").text != "false":
                self.options.live = True
        if xml.find("drmProtected").text == "true":
            yield ServiceError(
                "We cant download DRM protected content from this site.")
            return
        if xml.find("playbackStatus").text == "NOT_STARTED":
            yield ServiceError("Can't download something that is not started")
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "tv4play"
            basename = self._autoname(vid)
            if basename is None:
                yield ServiceError("Cant find vid id for autonaming")
                return
            title = "%s-%s-%s" % (basename, vid, self.options.service)
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if "rtmp" in base.scheme:
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    self.options.other = "-W %s -y %s" % (swf,
                                                          i.find("url").text)
                    yield RTMP(copy.copy(self.options),
                               i.find("base").text,
                               i.find("bitrate").text)
                elif parse.path[len(parse.path) - 3:len(parse.path)] == "f4m":
                    streams = hdsparse(
                        self.options,
                        self.http.request("get",
                                          i.find("url").text,
                                          params={"hdcore": "3.7.0"}),
                        i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "webvtt":
                yield subtitle(copy.copy(self.options), "wrst",
                               i.find("url").text)

        url = "https://prima.tv4play.se/api/web/asset/%s/play?protocol=hls3" % vid
        data = self.http.request("get", url, cookies=self.cookies).content
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(
                        self.options,
                        self.http.request("get",
                                          i.find("url").text),
                        i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
Exemple #49
0
    def get(self, options):
        match = re.search(r".*video/([0-9]+)", self.url)
        if not match:
            yield ServiceError("Can't find video file")
            return

        video_id = match.group(1)
        if options.username and options.password:
            # get session cookie
            data = self.http.request("get", "http://www.kanal5play.se/", cookies=self.cookies)
            authurl = "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % \
                      (options.username, options.password)
            data = self.http.request("get", authurl, cookies=data.cookies).text
            match = re.search(r"({.*})\);", data)
            jsondata = json.loads(match.group(1))
            if jsondata["success"] is False:
                yield ServiceError(jsondata["message"])
                return
            authToken = jsondata["userData"]["auth"]
            self.cookies = {"authToken": authToken}
            options.cookies = self.cookies

        url = "http://www.kanal5play.se/api/getVideo?format=FLASH&videoId=%s" % video_id
        data = self.http.request("get", url, cookies=self.cookies).text
        data = json.loads(data)
        options.cookies = self.cookies
        if not options.live:
            options.live = data["isLive"]

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "kanal5"

            title = "%s-s%s-%s-%s-%s" % (data["program"]["name"], data["seasonNumber"], data["episodeText"], data["id"], options.service)
            title = filenamify(title)
            if len(directory):
                options.output = os.path.join(directory, title)
            else:
                options.output = title

        if self.exclude(options):
            yield ServiceError("Excluding video")
            return

        if data["hasSubtitle"]:
            yield subtitle(copy.copy(options), "json", "http://www.kanal5play.se/api/subtitles/%s" % video_id)

        if options.force_subtitle:
            return

        show = True
        if "streams" in data.keys():
            for i in data["streams"]:
                if i["drmProtected"]:
                    yield ServiceError("We cant download drm files for this site.")
                    return
                steambaseurl = data["streamBaseUrl"]
                bitrate = i["bitrate"]
                if bitrate > 1000:
                    bitrate = bitrate / 1000
                options2 = copy.copy(options)
                options2.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", i["source"])
                options2.live = True
                yield RTMP(options2, steambaseurl, bitrate)

            url = "http://www.kanal5play.se/api/getVideo?format=IPAD&videoId=%s" % video_id
            data = self.http.request("get", url, cookies=self.cookies)
            data = json.loads(data.text)
            if "reasonsForNoStreams" in data:
                show = False
            if "streams" in data.keys():
                for i in data["streams"]:
                    streams = hlsparse(i["source"], self.http.request("get", i["source"]).text)
                    for n in list(streams.keys()):
                        yield HLS(copy.copy(options), streams[n], n)
        if "reasonsForNoStreams" in data and show:
            yield ServiceError(data["reasonsForNoStreams"][0])
Exemple #50
0
    def get(self):
        parse = urlparse(self.url)
        self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1)

        if not self._token():
            log.error("Something went wrong getting token for requests")

        if self.options.username and self.options.password:
            premium = self._login()
            if not premium:
                log.warning("Wrong username/password.")

        channel = False
        if "kanaler" in parse.path:
            match = re.search("kanaler/([^/]+)$", parse.path)
            path = "/channels/{}".format(match.group(1))
            url = "https://disco-api.{}/content{}".format(self.domain, path)
            channel = True
            self.options.live = True
        else:
            match = re.search("(videos|videoer)/(.*)$", parse.path)
            url = "https://disco-api.{}/content/videos/{}".format(
                self.domain, match.group(2))
        res = self.http.get(
            url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"})
        janson = res.json()
        if "errors" in janson:
            yield ServiceError("Cant find any videos on this url")
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "dplay"
            if channel:
                name = filenamify(janson["data"]["attributes"]["name"])
            else:
                name = self._autoname(janson)
            if name is None:
                yield ServiceError("Cant find vid id for autonaming")
                return
            title = "{0}-{1}-{2}".format(name, janson["data"]["id"],
                                         self.options.service)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        api = "https://disco-api.{}/playback/videoPlaybackInfo/{}".format(
            self.domain, janson["data"]["id"])
        res = self.http.get(api)
        if res.status_code > 400:
            yield ServiceError("You dont have permission to watch this")
            return
        streams = hlsparse(
            self.options,
            self.http.request(
                "get",
                res.json()["data"]["attributes"]["streaming"]["hls"]["url"]),
            res.json()["data"]["attributes"]["streaming"]["hls"]["url"],
            httpobject=self.http)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Exemple #51
0
    def get(self, options):
        match = re.search(r".*video/([0-9]+)", self.url)
        if not match:
            log.error("Can't find video file")
            return

        video_id = match.group(1)
        if options.username and options.password:
            # get session cookie
            data = get_http_data("http://www.kanal5play.se/", cookiejar=self.cj)
            authurl = "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % \
                      (options.username, options.password)
            data = get_http_data(authurl)
            match = re.search(r"({.*})\);", data)
            jsondata = json.loads(match.group(1))
            if jsondata["success"] is False:
                log.error(jsondata["message"])
                return
            authToken = jsondata["userData"]["auth"]
            cc = Cookie(version=0, name='authToken',
                        value=authToken,
                        port=None, port_specified=False,
                        domain='www.kanal5play.se',
                        domain_specified=True,
                        domain_initial_dot=True, path='/',
                        path_specified=True, secure=False,
                        expires=None, discard=True, comment=None,
                        comment_url=None, rest={'HttpOnly': None})
            self.cj.set_cookie(cc)

        url = "http://www.kanal5play.se/api/getVideo?format=FLASH&videoId=%s" % video_id
        data = json.loads(get_http_data(url, cookiejar=self.cj))
        options.cookiejar = self.cj
        if not options.live:
            options.live = data["isLive"]
        if data["hasSubtitle"]:
            yield subtitle_json("http://www.kanal5play.se/api/subtitles/%s" % video_id)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "kanal5"

            title = "%s-s%s-%s-%s-%s" % (data["program"]["name"], data["seasonNumber"], data["episodeText"], data["id"], options.service)
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        if options.force_subtitle:
            return

        if "streams" in data:
            for i in data["streams"]:
                if i["drmProtected"]:
                    log.error("We cant download drm files for this site.")
                    return
                steambaseurl = data["streamBaseUrl"]
                bitrate = i["bitrate"]
                if bitrate > 1000:
                    bitrate = bitrate / 1000
                options2 = copy.copy(options)
                options2.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", i["source"])
                options2.live = True
                yield RTMP(options2, steambaseurl, bitrate)

            url = "http://www.kanal5play.se/api/getVideo?format=IPAD&videoId=%s" % video_id
            data = json.loads(get_http_data(url, cookiejar=self.cj))
            if "streams" in data.keys():
                for i in data["streams"]:
                    streams = hlsparse(i["source"])
                    for n in list(streams.keys()):
                        yield HLS(copy.copy(options), streams[n], n)
        if "reasonsForNoStreams" in data:
            log.error(data["reasonsForNoStreams"][0])
Exemple #52
0
    def get(self, options):
        parse = urlparse(self.url)
        if "tv4play.se" in self.url:
            try:
                vid = parse_qs(parse.query)["video_id"][0]
            except KeyError:
                log.error("Can't find video file")
                sys.exit(2)
        else:
            match = re.search(r"\"vid\":\"(\d+)\",", self.get_urldata())
            if match:
                vid = match.group(1)
            else:
                match = re.search(r"-(\d+)$", self.url)
                if match:
                    vid = match.group(1)
                else:
                    log.error("Can't find video id")
                    sys.exit(2)

        url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            if xml.find("live").text != "false":
                options.live = True
        if xml.find("drmProtected").text == "true":
            log.error("DRM protected content.")
            sys.exit(2)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "tv4play"
            title = "%s-%s-%s" % (options.output, vid, options.service)
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if base.scheme == "rtmp":
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    options.other = "-W %s -y %s" % (swf, i.find("url").text)
                    yield RTMP(copy.copy(options), i.find("base").text, i.find("bitrate").text)
                elif parse.path[len(parse.path)-3:len(parse.path)] == "f4m":
                    query = ""
                    if i.find("url").text[-1] != "?":
                        query = "?"
                    manifest = "%s%shdcore=2.8.0&g=hejsan" % (i.find("url").text, query)
                    streams = hdsparse(copy.copy(options), manifest)
                    for n in list(streams.keys()):
                        yield streams[n]
            elif i.find("mediaFormat").text == "smi":
                yield subtitle_smi(i.find("url").text)

        url = "http://premium.tv4play.se/api/web/asset/%s/play?protocol=hls" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(i.find("url").text)
                    for n in list(streams.keys()):
                        yield HLS(copy.copy(options), streams[n], n)
 def test(self):
     for inp, ref in self.test_values:
         self.assertEqual(filenamify(inp), ref)
Exemple #54
0
    def get(self):

        parse = urlparse(self.url)
        if parse.path[:8] == "/kanaler":

            end_time_stamp = (datetime.utcnow() - timedelta(seconds=20)).replace(microsecond=0)
            start_time_stamp = end_time_stamp - timedelta(minutes=1)

            url = "https://bbr-l2v.akamaized.net/live/{0}/master.m3u8?in={1}&out={2}?".format(parse.path[9:],
                                                                                              start_time_stamp.isoformat(),
                                                                                              end_time_stamp.isoformat())

            self.options.live = True
            self.options.hls_time_stamp = True
            streams = hlsparse(self.options, self.http.request("get", url), url)
            if streams:
                for n in list(streams.keys()):
                    yield streams[n]
            return

        data = self.get_urldata()

        vid = findvid(self.url, data)
        if not vid:
            yield ServiceError("Can't find video id for {0}.".format(self.url))
            return

        url = "http://prima.tv4play.se/api/web/asset/{0}/play".format(vid)
        data = self.http.request("get", url, cookies=self.cookies)
        if data.status_code == 401:
            xml = ET.XML(data.content)
            code = xml.find("code").text
            if code == "SESSION_NOT_AUTHENTICATED":
                yield ServiceError("Can't access premium content")
            elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION":
                yield ServiceError("Can't download this video because of geoblock.")
            else:
                yield ServiceError("Can't find any info for that video.")
            return
        if data.status_code == 404:
            yield ServiceError("Can't find the video api.")
            return
        xml = ET.XML(data.content)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            self.options.live = (xml.find("live").text != "false")
        if xml.find("drmProtected").text == "true":
            yield ServiceError("We can't download DRM protected content from this site.")
            return
        if xml.find("playbackStatus").text == "NOT_STARTED":
            yield ServiceError("Can't download something that is not started.")
            return

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            self.options.service = "tv4play"
            basename = self._autoname(vid)
            if not basename:
                yield ServiceError("Cant find vid id for autonaming.")
                return
            title = "{0}-{1}-{2}".format(basename, vid, self.options.service)
            title = filenamify(title)
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        if self.exclude():
            yield ServiceError("Excluding video.")
            return

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if "rtmp" in base.scheme:
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    self.options.other = "-W {0} -y {1}".format(swf, i.find("url").text)
                    yield RTMP(copy.copy(self.options), i.find("base").text, i.find("bitrate").text)
                elif parse.path[len(parse.path) - 3:len(parse.path)] == "f4m":
                    streams = hdsparse(self.options, self.http.request("get", i.find("url").text,
                                                                       params={"hdcore": "3.7.0"}), i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "webvtt":
                yield subtitle(copy.copy(self.options), "wrst", i.find("url").text)

        url = "https://prima.tv4play.se/api/web/asset/{0}/play?protocol=hls3".format(vid)
        data = self.http.request("get", url, cookies=self.cookies).content
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(self.options, self.http.request("get", i.find("url").text), i.find("url").text)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
Exemple #55
0
 def _autoname(self, jsondata):
     show = jsondata["data"][0]["video_metadata_show"]
     season = jsondata["data"][0]["season"]
     episode = jsondata["data"][0]["episode"]
     title = jsondata["data"][0]["title"]
     return filenamify("%s.s%se%s.%s" % (show, season, episode, title))
Exemple #56
0
    def get(self):
        data = self.http.get("https://www.sportlib.se/sportlib/login").text
        match = re.search('src="(/app[^"]+)">', data)
        if not match:
            yield ServiceError("Can't find url for login info")
            return

        url = urljoin("https://www.sportlib.se", match.group(1))
        data = self.http.get(url).text
        match = re.search('CLIENT_SECRET:"([^"]+)"', data)
        if not match:
            yield ServiceError("Cant fint login info")
            return
        cs = match.group(1)
        match = re.search('CLIENT_ID:"([^"]+)"', data)
        if not match:
            yield ServiceError("Cant fint login info")
            return
        cid = match.group(1)
        res = self.http.get(
            "https://core.oz.com/channels?slug=sportlib&org=www.sportlib.se")
        janson = res.json()
        sid = janson["data"][0]["id"]

        data = {
            "client_id": cid,
            "client_secret": cs,
            "grant_type": "password",
            "username": self.options.username,
            "password": self.options.password
        }
        res = self.http.post(
            "https://core.oz.com/oauth2/token?channelId={}".format(sid),
            data=data)
        if res.status_code > 200:
            yield ServiceError("Wrong username / password?")
            return
        janson = res.json()
        token_type = janson["token_type"].title()
        access_token = janson["access_token"]

        parse = urlparse(self.url)
        match = re.search("video/([-a-fA-F0-9]+)", parse.path)
        if not match:
            yield ServiceError("Cant find video id")
            return
        vid = match.group(1)

        headers = {
            "content-type": "application/json",
            "authorization": "{} {}".format(token_type, access_token)
        }
        url = "https://core.oz.com/channels/{}/videos/{}?include=collection,streamUrl".format(
            sid, vid)
        res = self.http.get(url, headers=headers)
        janson = res.json()
        cookiename = janson["data"]["streamUrl"]["cookieName"]
        token = janson["data"]["streamUrl"]["token"]
        hlsplaylist = janson["data"]["streamUrl"]["cdnUrl"]

        if self.options.output_auto:
            directory = os.path.dirname(self.options.output)
            title = filenamify(janson["data"]["title"])
            if len(directory):
                self.options.output = os.path.join(directory, title)
            else:
                self.options.output = title

        # get cookie
        postjson = {"name": cookiename, "value": token}
        res = self.http.post("https://playlist.oz.com/cookie", json=postjson)
        cookies = res.cookies
        streams = hlsparse(self.options,
                           self.http.request("get", hlsplaylist),
                           hlsplaylist,
                           keycookie=cookies)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Exemple #57
0
    def get(self, options):
        parse = urlparse(self.url)
        if "tv4play.se" in self.url:
            try:
                vid = parse_qs(parse.query)["video_id"][0]
            except KeyError:
                log.error("Can't find video file")
                sys.exit(2)
        else:
            match = re.search(r"\"vid\":\"(\d+)\",", self.get_urldata())
            if match:
                vid = match.group(1)
            else:
                match = re.search(r"-(\d+)$", self.url)
                if match:
                    vid = match.group(1)
                else:
                    log.error("Can't find video id")
                    sys.exit(2)

        url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))

        if xml.find("live").text:
            if xml.find("live").text != "false":
                options.live = True
        if xml.find("drmProtected").text == "true":
            log.error("DRM protected content.")
            sys.exit(2)

        if options.output_auto:
            directory = os.path.dirname(options.output)
            options.service = "tv4play"
            title = "%s-%s-%s" % (options.output, vid, options.service)
            title = filenamify(title)
            if len(directory):
                options.output = "%s/%s" % (directory, title)
            else:
                options.output = title

        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                base = urlparse(i.find("base").text)
                parse = urlparse(i.find("url").text)
                if base.scheme == "rtmp":
                    swf = "http://www.tv4play.se/flash/tv4playflashlets.swf"
                    options.other = "-W %s -y %s" % (swf, i.find("url").text)
                    yield RTMP(copy.copy(options), i.find("base").text, i.find("bitrate").text)
                elif parse.path[len(parse.path)-3:len(parse.path)] == "f4m":
                    query = ""
                    if i.find("url").text[-1] != "?":
                        query = "?"
                    manifest = "%s%shdcore=2.8.0&g=hejsan" % (i.find("url").text, query)
                    streams = hdsparse(copy.copy(options), manifest)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
            elif i.find("mediaFormat").text == "smi":
                yield subtitle_smi(i.find("url").text)

        url = "http://premium.tv4play.se/api/web/asset/%s/play?protocol=hls" % vid
        data = get_http_data(url)
        xml = ET.XML(data)
        ss = xml.find("items")
        if is_py2_old:
            sa = list(ss.getiterator("item"))
        else:
            sa = list(ss.iter("item"))
        for i in sa:
            if i.find("mediaFormat").text == "mp4":
                parse = urlparse(i.find("url").text)
                if parse.path.endswith("m3u8"):
                    streams = hlsparse(i.find("url").text)
                    for n in list(streams.keys()):
                        yield HLS(copy.copy(options), streams[n], n)