Ejemplo n.º 1
0
    def get(self):
        data = self.get_urldata()

        match = re.search("window.pagePlaylist = (.*);", data)
        if not match:
            yield ServiceError("Can't find video info")
            return

        try:
            janson = json.loads(match.group(1))
        except Exception:
            yield ServiceError("Can't decode api request: {}".format(
                match.group(1)))
            return

        parse = urlparse(self.url)
        wanted_id = parse.path.split("/")[-1].split("-")[0]

        for n in janson:
            if wanted_id == str(n["id"]):

                mrssxmlurl = "http://media-utils.mtvnservices.com/services/MediaGenerator/" "mgid:arc:video:mtv.se:{}?acceptMethods=hls".format(
                    n["video_token"])
                hls_asset = self.http.request("get", mrssxmlurl)
                xml = ET.XML(hls_asset.text)

                if (xml.find("./video") is not None
                        and xml.find("./video").find("item") is not None
                        and xml.find("./video").find("item").find("rendition")
                        is not None and xml.find("./video").find("item").find(
                            "rendition").find("src") is not None):

                    hls_url = xml.find("./video").find("item").find(
                        "rendition").find("src").text
                    stream = hlsparse(self.config,
                                      self.http.request("get", hls_url),
                                      hls_url,
                                      output=self.output)

                    if stream:
                        for key in list(stream.keys()):
                            yield stream[key]
Ejemplo n.º 2
0
    def get(self):
        data = self.get_urldata()

        match = re.search(r"RP.vcdData = ({.*});</script>", data)
        if match:
            data = json.loads(match.group(1))
            for i in list(data["station"]["streams"].keys()):
                yield HTTP(copy.copy(self.config), data["station"]["streams"][i], i)
        else:
            yield ServiceError("Can't find stream info")
            return
Ejemplo n.º 3
0
    def get(self):
        urlp = urlparse(self.url)

        match = re.match(r'/(\w+)/([bcv])/(\d+)', urlp.path)
        if not match:
            if re.search("clips.twitch.tv", urlp.netloc):
                data = self._get_clips()
            else:
                data = self._get_channel(urlp)
        else:
            if match.group(2) in ["b", "c"]:
                yield ServiceError("This twitch video type is unsupported")
                return
            data = self._get_archive(match.group(3))
        try:
            for i in data:
                yield i
        except TwitchUrlException:
            yield ServiceError("This twitch video type is unsupported")
            return
Ejemplo n.º 4
0
    def get(self):
        data = self.get_urldata()

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

        match = re.search(r'href="(/sida/[\.\/=a-z0-9&;\?]+play(?:audio|episode)=\d+)"', data)
        if not match:
            yield ServiceError("Can't find audio info")
            return
        path = quote_plus(match.group(1))
        dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path
        data = self.http.request("get", dataurl).text
        playerinfo = json.loads(data)["playerInfo"]
        for i in playerinfo["AudioSources"]:
            url = i["Url"]
            if not url.startswith('http'):
                url = 'http:%s' % url
            yield HTTP(copy.copy(self.options), url, i["Quality"]/1000)
Ejemplo n.º 5
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]
Ejemplo n.º 6
0
def dashparse(options, res, url):
    streams = {}

    if not res:
        return None

    if res.status_code >= 400:
        streams[0] = ServiceError("Can't read DASH playlist. {0}".format(res.status_code))
        return streams
    xml = ET.XML(res.text)
    if "isoff-on-demand" in xml.attrib["profiles"]:
        try:
            baseurl = urljoin(url, xml.find("{urn:mpeg:dash:schema:mpd:2011}BaseURL").text)
        except AttributeError:
            streams[0] = ServiceError("Can't parse DASH playlist")
            return
        videofiles = xml.findall(".//{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType='video']/{urn:mpeg:dash:schema:mpd:2011}Representation")
        audiofiles = xml.findall(".//{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType='audio']/{urn:mpeg:dash:schema:mpd:2011}Representation")
        for i in audiofiles:
            audiourl = urljoin(baseurl, i.find("{urn:mpeg:dash:schema:mpd:2011}BaseURL").text)
            audiobitrate = float(i.attrib["bandwidth"]) / 1000
            for n in videofiles:
                bitrate = float(n.attrib["bandwidth"])/1000 + audiobitrate
                videourl = urljoin(baseurl, n.find("{urn:mpeg:dash:schema:mpd:2011}BaseURL").text)
                options.other = "mp4"
                streams[int(bitrate)] = DASH(copy.copy(options), videourl, bitrate, cookies=res.cookies, audio=audiourl)
    if "isoff-live" in xml.attrib["profiles"]:
        video = xml.findall(".//{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType='video']")
        if len(video) == 0:
            video = xml.findall(".//{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType='video/mp4']")
        audio = xml.findall(".//{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType='audio']")
        if len(audio) == 0:
            audio = xml.findall(".//{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType='audio/mp4']")
        videofiles = parsesegments(video, url)
        audiofiles = parsesegments(audio, url)
        for i in videofiles.keys():
            bitrate = (int(i) + int(list(audiofiles.keys())[0])) /1000
            options.other = "mp4"
            streams[int(bitrate)] = DASH(copy.copy(options), url, bitrate, cookies=res.cookies, audio=audiofiles[list(audiofiles.keys())[0]], files=videofiles[i])

    return streams
Ejemplo n.º 7
0
def hlsparse(options, res, url):
    streams = {}

    if res.status_code == 403 or res.status_code == 404:
        streams[0] = ServiceError("Can't read HLS playlist.")
        return streams
    files = (parsem3u(res.text))[1]

    for i in files:
        bitrate = float(i[1]["BANDWIDTH"])/1000
        streams[int(bitrate)] = HLS(copy.copy(options), _get_full_url(i[0], url), bitrate, cookies=res.cookies)
    return streams
Ejemplo n.º 8
0
    def get(self):
        match = re.search('data-hls="([^"]+)"', self.get_urldata())
        if not match:
            yield ServiceError("Cant find video info")
            return

        streams = hlsparse(self.options,
                           self.http.request("get", match.group(1)),
                           match.group(1))
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Ejemplo n.º 9
0
    def get(self):
        if not self.config.get("username") or not self.config.get("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

        basename = self._autoname(match.group(1))
        self.output["id"] = match.group(1)
        if basename is None:
            yield ServiceError("Cant find vid id for autonaming")
            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.config,
                                        self.http.request("get", i["url"]),
                                        i["url"],
                                        output=self.output)
                    if streams:
                        for n in list(streams.keys()):
                            yield streams[n]
                if i["mediaFormat"] == "webvtt":
                    yield subtitle(copy.copy(self.config), "wrst", i["url"])
        else:
            i = janson["playback"]["items"]["item"]
            if i["mediaFormat"] == "ism":
                streams = dashparse(self.config,
                                    self.http.request("get", i["url"]),
                                    i["url"],
                                    output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
Ejemplo n.º 10
0
    def get(self):
        if self.exclude():
            yield ServiceError("Excluding video")
            return

        # First, fint the video ID from the html document
        match = re.search("<meta name=\"programid\".*?content=\"([^\"]*)\"", self.get_urldata())
        if match:
            video_id = match.group(1)
        else:
            yield ServiceError("Can't find video id.")
            return

        # Get media element details
        dataurl = "http://v8.psapi.nrk.no/mediaelement/%s" % (video_id)
        data = self.http.request("get", dataurl).text
        data = json.loads(data)
        manifest_url = data["mediaUrl"]
        self.options.live = data["isLive"]
        if manifest_url is None:
            yield ServiceError(data["messageType"])
            return
        # Check if subtitles are available
        if data["subtitlesUrlPath"]:
            yield subtitle(copy.copy(self.options), "tt", data["subtitlesUrlPath"])

        hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8")
        data = self.http.request("get", hlsurl)
        if data.status_code == 403:
            yield ServiceError("Can't fetch the video because of geoblocking")
            return
        streams = hlsparse(self.options, data, hlsurl)
        for n in list(streams.keys()):
            yield streams[n]

        streams = hdsparse(copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}),
                           manifest_url)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Ejemplo n.º 11
0
    def get(self):
        urlp = urlparse(self.url)
        slugs = urlp.path.split('/')

        courseSlug = slugs[2]
        lessonSlug = slugs[3]

        login = self._login()
        if not login:
            yield ServiceError("Could not login")
            return

        data = self._getData()
        if data is None:
            yield ServiceError("Could not fetch data")
            return

        course = findCourse(data, courseSlug)

        if course is None:
            yield ServiceError("Could not find course")
            return

        lesson = findLesson(course, lessonSlug)

        if lesson is None:
            yield ServiceError("Could not find lesson")
            return

        self.output["id"] = lesson["videoAssetId"]
        self.output["title"] = lesson["title"]

        url = "https://playback-api.b17g.net/media/{}?service=tv4&device=browser&protocol=hls%2Cdash&drm=widevine".format(self.output["id"])

        videoDataRes = self.http.get(url)
        if videoDataRes.json()["playbackItem"]["type"] == "hls":
            streams = hlsparse(self.config, self.http.get(videoDataRes.json()["playbackItem"]["manifestUrl"]),
                               videoDataRes.json()["playbackItem"]["manifestUrl"], output=self.output)
            for n in list(streams.keys()):
                yield streams[n]
Ejemplo n.º 12
0
def _dashparse(config, text, url, output, cookies):
    streams = {}
    baseurl = None
    offset_sec = None
    duration_sec = None

    xml = ET.XML(text)

    if xml.find("./{urn:mpeg:dash:schema:mpd:2011}BaseURL") is not None:
        baseurl = xml.find("./{urn:mpeg:dash:schema:mpd:2011}BaseURL").text

    if "availabilityStartTime" in xml.attrib:
        availabilityStartTime = xml.attrib["availabilityStartTime"]
        publishTime = xml.attrib["publishTime"]

        datetime_start = parse_dates(availabilityStartTime)
        datetime_publish = parse_dates(publishTime)
        diff_publish = datetime_publish - datetime_start
        offset_sec = diff_publish.total_seconds()

        if "mediaPresentationDuration" in xml.attrib:
            mediaPresentationDuration = xml.attrib["mediaPresentationDuration"]
            duration_sec = (parse_dates(mediaPresentationDuration) -
                            datetime(1900, 1, 1)).total_seconds()

    temp = xml.findall(
        './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType="audio/mp4"]'
    )
    audiofiles = adaptionset(temp, url, baseurl, offset_sec, duration_sec)
    temp = xml.findall(
        './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType="video/mp4"]'
    )
    videofiles = adaptionset(temp, url, baseurl, offset_sec, duration_sec)

    if not audiofiles or not videofiles:
        streams[0] = ServiceError(
            "Found no Audiofiles or Videofiles to download.")
        return streams

    for i in videofiles.keys():
        bitrate = i + list(audiofiles.keys())[0]
        streams[bitrate] = DASH(copy.copy(config),
                                url,
                                bitrate,
                                cookies=cookies,
                                audio=audiofiles[list(
                                    audiofiles.keys())[0]]["files"],
                                files=videofiles[i]["files"],
                                output=output,
                                segments=videofiles[i]["segments"])

    return streams
Ejemplo n.º 13
0
    def get(self):
        match = re.search("_([A-Z0-9]+)$", self.url)
        if not match:
            yield ServiceError("Cant find video id.")
            return

        vid = match.group(1)
        res = self.http.get("http://www.riksdagen.se/api/videostream/get/%s" % vid)
        data = res.json()

        try:
            janson = data["videodata"][0]["streams"]["files"]
        except TypeError:
            yield ServiceError("Cant find video.")
            return

        for i in janson:
            if i["mimetype"] == "application/x-mpegurl":
                data2 = self.http.get(i["url"]).json()
                streams = hlsparse(self.config, self.http.request("get", data2["url"]), data2["url"], output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
Ejemplo n.º 14
0
    def _get_clips(self):
        match = re.search(r"quality_options: (\[[^\]]+\])", self.get_urldata())
        if not match:
            yield ServiceError("Can't find the video clip")
            return
        name = re.search(r'slug: "([^"]+)"', self.get_urldata()).group(1)
        brodcaster = re.search('broadcaster_login: "******"]+)"', self.get_urldata()).group(1)
        self.output["title"] = "twitch-{}".format(brodcaster)
        self.output["episodename"] = name

        dataj = json.loads(match.group(1))
        for i in dataj:
            yield HTTP(copy.copy(self.config), i["source"], i["quality"], output=self.output)
Ejemplo n.º 15
0
    def get(self):
        data = self.get_urldata()

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

        match = re.search('data-config-url="([^"]+)" data-fallback-url', data)
        if not match:
            yield ServiceError("Can't find video file for: %s" % self.url)
            return
        player_url = match.group(1).replace("&amp;", "&")
        player_data = self.http.request("get", player_url).text

        if player_data:
            jsondata = json.loads(player_data)
            avail_quality = jsondata["request"]["files"]["progressive"]
            for i in avail_quality:
                yield HTTP(copy.copy(self.options), i["url"], i["height"])
        else:
            yield ServiceError("Can't find any streams.")
            return
Ejemplo n.º 16
0
def hdsparse(options, res, manifest):
    streams = {}
    bootstrap = {}

    if not res:
        return None

    if res.status_code >= 400:
        streams[0] = ServiceError("Can't read HDS playlist. {0}".format(res.status_code))
        return streams
    data = res.text
    if is_py2 and isinstance(data, unicode):
        data = data.encode("utf-8")

    xml = ET.XML(data)

    if is_py2_old:
        bootstrapIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
        mediaIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}media")
    else:
        bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
        mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")

    if xml.find("{http://ns.adobe.com/f4m/1.0}drmAdditionalHeader") is not None:
        streams[0] = ServiceError("HDS DRM protected content.")
        return streams
    for i in bootstrapIter:
        if "id" in i.attrib:
            bootstrap[i.attrib["id"]] = i.text
        else:
            bootstrap["0"] = i.text
    parse = urlparse(manifest)
    querystring = parse.query
    manifest = "%s://%s%s" % (parse.scheme, parse.netloc, parse.path)
    for i in mediaIter:
        bootstrapid = bootstrap[i.attrib["bootstrapInfoId"]]
        streams[int(i.attrib["bitrate"])] = HDS(copy.copy(options), i.attrib["url"], i.attrib["bitrate"], manifest=manifest, bootstrap=bootstrapid,
                                                metadata=i.find("{http://ns.adobe.com/f4m/1.0}metadata").text, querystring=querystring, cookies=res.cookies)
    return streams
Ejemplo n.º 17
0
def dashparse(options, res, url):
    streams = {}

    if not res:
        return None

    if res.status_code >= 400:
        streams[0] = ServiceError("Can't read DASH playlist. {0}".format(
            res.status_code))
        return streams
    if len(res.text) < 1:
        streams[0] = ServiceError(
            "Can't read DASH playlist. {0}, size: {1}".format(
                res.status_code, len(res.text)))
        return
    xml = ET.XML(res.text)

    temp = xml.findall(
        './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType="audio/mp4"]'
    )
    audiofiles = adaptionset(temp, url)
    temp = xml.findall(
        './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType="video/mp4"]'
    )
    videofiles = adaptionset(temp, url)

    for i in videofiles.keys():
        bitrate = (int(i) + int(list(audiofiles.keys())[0]))
        options.other = "mp4"
        options.segments = videofiles[i]["segments"]
        streams[int(bitrate)] = DASH(copy.copy(options),
                                     url,
                                     bitrate,
                                     cookies=res.cookies,
                                     audio=audiofiles[list(
                                         audiofiles.keys())[0]]["files"],
                                     files=videofiles[i]["files"])

    return streams
Ejemplo n.º 18
0
 def get(self):
     match = re.search(r"var initialMedia\s+= ({[^;]+);", self.get_urldata())
     if not match:
         yield ServiceError("Cant find any media on that page")
         return
     janson = json.loads(match.group(1))
     vid = janson["content_id"]
     if not janson["metaData"]:
         yield ServiceError("Can't find video on that page")
         return
     if "playbacks" in janson["metaData"]:
         for i in janson["metaData"]["playbacks"]:
             if "CLOUD" in i["name"]:
                 streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"])
                 if streams:
                     for n in list(streams.keys()):
                         yield streams[n]
     else:
         match = re.search(r"var mediaConfig\s+= ({[^;]+);", self.get_urldata())
         if not match:
             yield ServiceError("Cant find any media on that page")
             return
         janson = json.loads(match.group(1))
         try:
             apiurl = janson["vpm"]["mediaFramework"]["mediaFrameworkDomain"]
         except KeyError:
             yield ServiceError("Can't find api url")
             return
         filename = "{}?contentId={}&playbackScenario=HTTP_CLOUD_WIRED_WEB&format=json&platform=WEB_MEDIAPLAYER" "&_=1487455224334".format(
             janson["vpm"]["mediaFramework"]["mediaFrameworkEndPoint"],
             vid,
         )
         url = urljoin(apiurl, filename)
         res = self.http.get(url)
         janson = res.json()
         for i in janson["user_verified_event"][0]["user_verified_content"][0]["user_verified_media_item"]:
             streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output)
             for n in list(streams.keys()):
                 yield streams[n]
Ejemplo n.º 19
0
    def get(self):
        data = self.get_urldata()

        match = re.search('data-player-config="([^"]+)"', data)
        if not match:
            match = re.search('data-svpPlayer-video="([^"]+)"', data)
            if not match:
                yield ServiceError("Can't find video info")
                return
        data = json.loads(decode_html_entities(match.group(1)))
        streams = hlsparse(self.config, self.http.request("get", data["streamUrls"]["hls"]), data["streamUrls"]["hls"], output=self.output)
        for n in list(streams.keys()):
            yield streams[n]
Ejemplo n.º 20
0
    def _get_video(self, janson):
        if "subtitleReferences" in janson:
            for i in janson["subtitleReferences"]:
                if i["format"] == "webvtt" and "url" in i:
                    yield subtitle(copy.copy(self.config),
                                   "wrst",
                                   i["url"],
                                   output=self.output)

        if "videoReferences" in janson:
            if len(janson["videoReferences"]) == 0:
                yield ServiceError("Media doesn't have any associated videos.")
                return

            for i in janson["videoReferences"]:
                streams = None
                alt_streams = None
                alt = None
                query = parse_qs(urlparse(i["url"]).query)
                if "alt" in query and len(query["alt"]) > 0:
                    alt = self.http.get(query["alt"][0])

                if i["format"][:3] == "hls":
                    streams = hlsparse(self.config,
                                       self.http.request("get", i["url"]),
                                       i["url"],
                                       output=self.output)
                    if alt:
                        alt_streams = hlsparse(self.config,
                                               self.http.request(
                                                   "get", alt.request.url),
                                               alt.request.url,
                                               output=self.output)
                elif i["format"][:4] == "dash":
                    streams = dashparse(self.config,
                                        self.http.request("get", i["url"]),
                                        i["url"],
                                        output=self.output)
                    if alt:
                        alt_streams = dashparse(self.config,
                                                self.http.request(
                                                    "get", alt.request.url),
                                                alt.request.url,
                                                output=self.output)

                if streams:
                    for n in list(streams.keys()):
                        yield streams[n]
                if alt_streams:
                    for n in list(alt_streams.keys()):
                        yield alt_streams[n]
Ejemplo n.º 21
0
    def get(self):
        data = self.get_urldata()

        match = re.search(r'id="(bcPl[^"]+)"', data)
        if not match:
            yield ServiceError("Can't find flash id.")
            return
        flashid = match.group(1)

        match = re.search(r'playerID" value="([^"]+)"', self.get_urldata())
        if not match:
            yield ServiceError("Can't find playerID")
            return
        playerid = match.group(1)

        match = re.search(r'playerKey" value="([^"]+)"', self.get_urldata())
        if not match:
            yield ServiceError("Can't find playerKey")
            return
        playerkey = match.group(1)

        match = re.search(r'videoPlayer" value="([^"]+)"', self.get_urldata())
        if not match:
            yield ServiceError("Can't find videoPlayer info")
            return
        videoplayer = match.group(1)

        dataurl = (
            "http://c.brightcove.com/services/viewer/htmlFederated?flashID={}&playerID={}&playerKey={}"
            "&isVid=true&isUI=true&dynamicStreaming=true&@videoPlayer={}".format(flashid, playerid, playerkey, videoplayer)
        )
        data = self.http.request("get", dataurl).content
        match = re.search(r"experienceJSON = ({.*});", data)
        if not match:
            yield ServiceError("Can't find json data")
            return
        jsondata = json.loads(match.group(1))
        renditions = jsondata["data"]["programmedContent"]["videoPlayer"]["mediaDTO"]["renditions"]

        if jsondata["data"]["publisherType"] == "PREMIUM":
            yield ServiceError("Premium content")
            return

        for i in renditions:
            if i["defaultURL"].endswith("f4m"):
                streams = hdsparse(
                    copy.copy(self.config), self.http.request("get", i["defaultURL"], params={"hdcore": "3.7.0"}), i["defaultURL"], output=self.output
                )
                for n in list(streams.keys()):
                    yield streams[n]

            if i["defaultURL"].endswith("m3u8"):
                streams = hlsparse(self.config, self.http.request("get", i["defaultURL"]), i["defaultURL"], output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]

            if i["defaultURL"].endswith("mp4"):
                yield HTTP(copy.copy(self.config), i["defaultURL"], i["encodingRate"] / 1024, output=self.output)
Ejemplo n.º 22
0
def hlsparse(options, res, url):
    streams = {}

    if not res:
        return None

    if res.status_code > 400:
        streams[0] = ServiceError("Can't read HLS playlist. {0}".format(
            res.status_code))
        return streams
    files = (parsem3u(res.text))[1]

    for i in files:
        try:
            bitrate = float(i[1]["BANDWIDTH"]) / 1000
        except KeyError:
            streams[0] = ServiceError("Can't read HLS playlist")
            return streams
        streams[int(bitrate)] = HLS(copy.copy(options),
                                    _get_full_url(i[0], url),
                                    bitrate,
                                    cookies=res.cookies)
    return streams
Ejemplo n.º 23
0
    def get(self):
        parse = urlparse(self.url)
        if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se":
            if parse.path[:6] != "/video" and parse.path[:6] != "/klipp" and parse.path[:8] != "/kanaler":
                yield ServiceError("This mode is not supported anymore. Need the url with the video.")
                return

        query = parse_qs(parse.query)
        self.access = None
        if "accessService" in query:
            self.access = query["accessService"]

        urldata = self.get_urldata()

        if parse.path[:8] == "/kanaler":
            match = re.search('data-video-id="([\\w-]+)"', urldata)

            if not match:
                yield ServiceError("Can't find video info.")
                return

            _url = urljoin(URL_VIDEO_API, match.group(1))
            res = self.http.get(_url)
            try:
                janson = res.json()
            except json.decoder.JSONDecodeError:
                yield ServiceError("Can't decode api request: {}".format(res.request.url))
                return
            videos = self._get_video(janson)
            self.config.set("live", True)
            yield from videos
            return

        match = re.search(r"__svtplay_apollo'] = ({.*});", urldata)
        if not match:
            yield ServiceError("Can't find video info.")
            return

        janson = json.loads(match.group(1))
        self.visibleid = self._get_visibleid(janson)
        if not self.visibleid:
            yield ServiceError("Can't find video id")
            return

        vid = janson[self.visibleid]["videoSvtId"]

        self.outputfilename(janson)
        self.extrametadata(janson, self.visibleid)

        res = self.http.get(URL_VIDEO_API + vid)
        try:
            janson = res.json()
        except json.decoder.JSONDecodeError:
            yield ServiceError("Can't decode api request: {}".format(res.request.url))
            return
        videos = self._get_video(janson)
        yield from videos
Ejemplo n.º 24
0
    def get(self):
        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/{}/video/{}".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: {}".format(
                video_assets.text))
            return

        if "title" in janson:
            self.output["title"] = janson["title"]

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

                    for key in list(stream.keys()):
                        yield stream[key]
Ejemplo n.º 25
0
    def get(self):
        data = self.get_urldata()

        match = re.search(r'"([^"]+geo.php)"', data)
        if match:
            data = self.http.request("get", match.group(1)).content
            match = re.search(r"punktur=\(([^ ]+)\)", data)
            if match:
                janson = json.loads(match.group(1))
                self.config.get("live", checklive(janson["result"][1]))
                streams = hlsparse(self.config,
                                   self.http.request("get",
                                                     janson["result"][1]),
                                   janson["result"][1],
                                   output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
            else:
                yield ServiceError("Can't find json info")
        else:
            match = re.search(r'<source [^ ]*[ ]*src="([^"]+)" ',
                              self.get_urldata())
            if not match:
                yield ServiceError("Can't find video info for: %s" % self.url)
                return
            if match.group(1).endswith("mp4"):
                yield HTTP(copy.copy(self.config),
                           match.group(1),
                           800,
                           output=self.output)
            else:
                m3u8_url = match.group(1)
                self.config.set("live", checklive(m3u8_url))
                yield HLS(copy.copy(self.config),
                          m3u8_url,
                          800,
                          output=self.output)
Ejemplo n.º 26
0
    def get(self):
        match = re.search(r"[\/-](\d+)$", self.url)
        if not match:
            yield ServiceError("Cant find video id")
            return
        self.output["id"] = match.group(1)

        match = re.search("data-program-format='([^']+)'", self.get_urldata())
        if not match:
            yield ServiceError("Cant find program name")
            return
        self.output["title"] = match.group(1)

        match = re.search('img alt="([^"]+)" class="video-image responsive"',
                          self.get_urldata())
        if not match:
            yield ServiceError("Cant find title of the video")
            return
        self.output["episodename"] = match.group(1)

        url = "https://playback-api.b17g.net/media/{}?service=tv4&device=browser&protocol=hls%2Cdash&drm=widevine".format(
            self.output["id"])
        res = self.http.request("get", url, cookies=self.cookies)
        if res.status_code > 200:
            yield ServiceError(
                "Can't play this because the video is geoblocked.")
            return
        if res.json()["playbackItem"]["type"] == "hls":
            streams = hlsparse(
                self.config,
                self.http.request("get",
                                  res.json()["playbackItem"]["manifestUrl"]),
                res.json()["playbackItem"]["manifestUrl"],
                output=self.output,
            )
            for n in list(streams.keys()):
                yield streams[n]
Ejemplo n.º 27
0
    def get(self):
        data = self.get_urldata()

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

        match = re.search(
            r'script async defer src="(//content.youplay.se[^"]+)"', data)
        if not match:
            yield ServiceError("Cant find video info for {0}".format(self.url))
            return

        data = self.http.request("get",
                                 "http:{0}".format(match.group(1)).content)
        match = re.search(r'decodeURIComponent\("([^"]+)"\)\)', data)
        if not match:
            yield ServiceError("Can't decode video info")
            return
        data = unquote_plus(match.group(1))
        match = re.search(r"videoData = ({[^;]+});", data)
        if not match:
            yield ServiceError("Cant find video info for {0}".format(self.url))
            return
        # fix broken json.
        regex = re.compile(r"\s(\w+):")
        data = regex.sub(r"'\1':", match.group(1))
        data = data.replace("'", "\"")
        j = re.sub(r"{\s*(\w)", r'{"\1', data)
        j = j.replace("\n", "")
        j = re.sub(r'",\s*}', '"}', j)
        jsondata = json.loads(j)
        for i in jsondata["episode"]["sources"]:
            match = re.search(r"mp4_(\d+)", i)
            if match:
                yield HTTP(copy.copy(self.options),
                           jsondata["episode"]["sources"][i], match.group(1))
Ejemplo n.º 28
0
    def get(self):
        vid = None
        data = self.get_urldata()

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

        match = re.search(r'video url-([^"]+)', data)
        if not match:
            match = re.search(r'embed.jsp\?([^"]+)"', self.get_urldata())
            if not match:
                yield ServiceError("Can't find video id")
                return
            vid = match.group(1)
        if not vid:
            path = unquote_plus(match.group(1))
            data = self.http.request("get",
                                     "http://www.svd.se%s" % path).content
            match = re.search(r'embed.jsp\?([^"]+)', data)
            if not match:
                yield ServiceError("Can't find video id")
                return
            vid = match.group(1)

        url = "http://ljsp.lwcdn.com/web/public/item.json?type=video&%s" % decode_html_entities(
            vid)
        data = self.http.request("get", url).text
        jdata = json.loads(data)
        videos = jdata["videos"][0]["media"]["streams"]
        for i in videos:
            if i["name"] == "auto":
                hls = "%s%s" % (jdata["videos"][0]["media"]["base"], i["url"])
        streams = hlsparse(self.options, self.http.request("get", hls), hls)
        if streams:
            for n in list(streams.keys()):
                yield streams[n]
Ejemplo n.º 29
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"])
Ejemplo n.º 30
0
    def get(self):
        match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"',
                          self.get_urldata())
        if not match:
            yield ServiceError("Can't find json info")
            return

        data = unescape(match.group(1))
        jsondata = json.loads(data)

        res = self.http.get(
            "https://streaming-loadbalancer.ur.se/loadbalancer.json")
        loadbalancer = res.json()["redirect"]

        for streaminfo in jsondata["currentProduct"]["streamingInfo"].keys():
            stream = jsondata["currentProduct"]["streamingInfo"][streaminfo]
            if streaminfo == "raw":
                url = "https://{}/{}playlist.m3u8".format(
                    loadbalancer, stream["sd"]["location"])
                streams = hlsparse(self.config,
                                   self.http.request("get", url),
                                   url,
                                   output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
                url = "https://{}/{}playlist.m3u8".format(
                    loadbalancer, stream["hd"]["location"])
                streams = hlsparse(self.config,
                                   self.http.request("get", url),
                                   url,
                                   output=self.output)
                for n in list(streams.keys()):
                    yield streams[n]
            if not (self.config.get("get_all_subtitles")) and (
                    stream["default"]):
                yield subtitle(copy.copy(self.config),
                               "tt",
                               stream["tt"]["location"],
                               output=self.output)

            if self.config.get("get_all_subtitles") and "tt" in stream:
                label = stream["tt"]["language"]
                if stream["tt"]["scope"] != "complete":
                    label = "{}-{}".format(label, stream["tt"]["scope"])
                yield subtitle(copy.copy(self.config),
                               "tt",
                               stream["tt"]["location"],
                               label,
                               output=self.output)