Esempio n. 1
0
    def _get_streams(self):
        #self.session.set_option('hls-live-edge', 10)
        self.session.http.headers.update({'User-Agent': useragents.CHROME})
        res = self.session.http.get(self.url)
        #log.debug(res.text)

        try:
            UUID = self._joada_re.search(res.text).group(1)
            log.debug("Found UUID: %s" % UUID)
            address = "https://deliverys2.joada.net/contents/encodings/live/%s/master.m3u8" % str(
                UUID)

        except Exception as e:
            log.debug(str(e))
            return

        return {
            "rtsp_stream":
            FFMPEGMuxer(self.session,
                        *(address, ),
                        is_muxed=False,
                        format='mpegts',
                        vcodec='copy',
                        acodec='copy')
        }
Esempio n. 2
0
    def _get_streams(self):
        #self.session.set_option('hls-live-edge', 10)
        self.session.http.headers.update({'User-Agent': useragents.ANDROID})
        res = self.session.http.get(self.url)
        log.trace("Responce:\n %s" % res.text)
        log.debug("Cookies:\n %s" % cookiesToString(res.cookies))
        self.url = self._url2_re.search(res.text).group(1)
        res = self.session.http.get(self.url)
        log.trace("Responce:\n %s" % res.text)
        log.debug("Cookies:\n %s" % cookiesToString(res.cookies))
        try:
            address = self._addr_re.search(res.text).group(1)
            log.debug("Found address: %s" % address)
        except Exception as e:
            log.debug(str(e))
            #log.debug("For responce:\n %s" % res.text)
            return

        return {
            "rtsp_stream":
            FFMPEGMuxer(self.session,
                        *(address, ),
                        is_muxed=False,
                        format='mpegts',
                        vcodec='copy',
                        acodec='copy')
        }
Esempio n. 3
0
    def _get_streams(self):
        #self.session.set_option('hls-live-edge', 10)
        self.session.http.headers.update({'User-Agent': useragents.CHROME})
        res = self.session.http.get(self.url)
        #log.debug(res.text)

        try:
            address = self._addr_re.search(res.text).group(1)
            if not address.startswith('https:') or not address.startswith(
                    'http:'):
                address = 'https:' + address
            log.debug("Found address: %s" % address)
        except Exception as e:
            log.debug(str(e))
            return

        return {
            "rtsp_stream":
            FFMPEGMuxer(self.session,
                        *(address, ),
                        is_muxed=False,
                        format='mpegts',
                        vcodec='copy',
                        acodec='copy')
        }
Esempio n. 4
0
    def _get_streams(self):
        log.debug("ffmpegCMDplugin._get_streams() >>>")
        params = self.url.split('ffmpeg|')[1].split('|')
        url = params.pop(0)
        log.debug("\t url: %s" % url)
        #params in url
        formatVal = "matroska"
        vcodecVal = 'copy'
        acodecVal = 'copy'
        ffmpegParams = {}
        if len(params) > 0:
            log.debug("\t ffmpeg params: {0}".format(' '.join(params)))
            for param in params:
                if param.startswith('format='): formatVal = param.split('=')[1]
                if param.startswith('vcodec='): vcodecVal = param.split('=')[1]
                if param.startswith('acodec='): acodecVal = param.split('=')[1]
        else:
            log.debug("\t additional ffmpeg params NOT provided")

        return {
            "ffmpeg_stream":
            FFMPEGMuxer(self.session,
                        *(url, ),
                        is_muxed=False,
                        format=formatVal,
                        vcodec=vcodecVal,
                        acodec=acodecVal,
                        extraParams=ffmpegParams)
        }
Esempio n. 5
0
    def _get_streams(self):
        self.session.set_option('hls-live-edge', 10)
        res = self.session.http.get(self.url)
        playlist_m = self._playlist_re.search(res.text)

        if playlist_m:
            log.debug("Found: '%s'" % playlist_m.group(1))
            return {
                "rtsp_stream":
                FFMPEGMuxer(self.session,
                            *(playlist_m.group(1), ),
                            is_muxed=False)
            }
        else:
            log.debug("Could not find stream data")
Esempio n. 6
0
    def _get_streams(self):
        #self.session.set_option('hls-live-edge', 10)
        self.session.http.headers.update({'User-Agent': useragents.CHROME})
        res = self.session.http.get(self.url)
        #log.debug(res.text)
        address = None

        #linki bezposrednie
        _addrs = [
            re.compile(r'[ ]*data-video-url-rtmp="([^"]+)"'),
            re.compile(r'[ ]*data-video-url-mp4="([^"]+)"'),
            re.compile(r'[ ]*data-video-url-hls="([^"]+)"')
        ]
        for _addr in _addrs:
            _addr = _addr.search(res.text)
            if not _addr is None and _addr.group(1) <> '':
                address = _addr.group(1)
                break

        #adres z linkiem
        if address is None:
            _addr = re.compile(r'[ ]* data-video-url-endpoint="([^"]+)"')
            _addr = _addr.search(res.text)
            if not _addr is None and _addr.group(1) <> '':
                res = self.session.http.get(_addr.group(1))
                log.debug("res: %s" % res.text)
                address = re.compile(r'.*"(http[^"]+)"')
                address = address.search(res.text).group(1)
                address = address.replace('\/', '/')

        log.debug("Found address: %s" % address)

        return {
            "rtsp_stream":
            FFMPEGMuxer(self.session,
                        *(address, ),
                        is_muxed=False,
                        format='mpegts',
                        vcodec='copy',
                        acodec='copy')
        }
Esempio n. 7
0
    def _get_streams(self):
        self.session.set_option('hls-live-edge', 10)
        res = self.session.http.get(self.url)
        #log.debug(res.text)

        try:
            address = self._addr_re.search(res.text).group(1)
            log.debug("Found address: %s" % address)

            streamID = self._stID_re.search(res.text).group(1)
            log.debug("Found streamID: %s" % streamID)

            fullURL = '%s/streams/%s/stream.m3u8' % (address, streamID)
            log.debug("Built URL: %s" % fullURL)
        except Exception as e:
            log.debug(str(e))
            return

        return {
            "rtsp_stream": FFMPEGMuxer(self.session,
                                       *(fullURL, ),
                                       is_muxed=False)
        }
Esempio n. 8
0
    def _get_streams(self):
        self.session.http.headers.update({'User-Agent': useragents.CHROME})
        res = self.session.http.get(self.url)

        try:
            address = self._addr_re.search(res.text).group(1)
            if len(address) == '':
                log.debug("NO address within response: %s" % res.text)
            else:
                log.debug("Found address: %s" % address)
        except Exception as e:
            log.debug(str(e))
            return

        return {
            "rtsp_stream":
            FFMPEGMuxer(self.session,
                        *(address, ),
                        is_muxed=False,
                        format='mpegts',
                        vcodec='copy',
                        acodec='copy')
        }
Esempio n. 9
0
    def parse_variant_playlist(cls,
                               session_,
                               url,
                               name_key="name",
                               name_prefix="",
                               check_streams=False,
                               force_restart=False,
                               name_fmt=None,
                               start_offset=0,
                               duration=None,
                               **request_params):
        """Attempts to parse a variant playlist and return its streams.

        :param url: The URL of the variant playlist.
        :param name_key: Prefer to use this key as stream name, valid keys are:
                         name, pixels, bitrate.
        :param name_prefix: Add this prefix to the stream names.
        :param check_streams: Only allow streams that are accessible.
        :param force_restart: Start at the first segment even for a live stream
        :param name_fmt: A format string for the name, allowed format keys are
                         name, pixels, bitrate.
        """
        locale = session_.localization
        # Backwards compatibility with "namekey" and "nameprefix" params.
        name_key = request_params.pop("namekey", name_key)
        name_prefix = request_params.pop("nameprefix", name_prefix)
        audio_select = session_.options.get("hls-audio-select") or []

        res = session_.http.get(url, exception=IOError, **request_params)

        try:
            parser = cls._get_variant_playlist(res)
        except ValueError as err:
            raise IOError("Failed to parse playlist: {0}".format(err))

        streams = {}
        for playlist in filter(lambda p: not p.is_iframe, parser.playlists):
            names = dict(name=None, pixels=None, bitrate=None)
            audio_streams = []
            fallback_audio = []
            default_audio = []
            preferred_audio = []
            for media in playlist.media:
                if media.type == "VIDEO" and media.name:
                    names["name"] = media.name
                elif media.type == "AUDIO":
                    audio_streams.append(media)
            for media in audio_streams:
                # Media without a uri is not relevant as external audio
                if not media.uri:
                    continue

                if not fallback_audio and media.default:
                    fallback_audio = [media]

                # if the media is "audoselect" and it better matches the users preferences, use that
                # instead of default
                if not default_audio and (
                        media.autoselect
                        and locale.equivalent(language=media.language)):
                    default_audio = [media]

                # select the first audio stream that matches the users explict language selection
                if (('*' in audio_select or media.language in audio_select
                     or media.name in audio_select) or
                    ((not preferred_audio or media.default) and locale.explicit
                     and locale.equivalent(language=media.language))):
                    preferred_audio.append(media)

            # final fallback on the first audio stream listed
            fallback_audio = fallback_audio or (len(audio_streams)
                                                and audio_streams[0].uri
                                                and [audio_streams[0]])

            if playlist.stream_info.resolution:
                width, height = playlist.stream_info.resolution
                names["pixels"] = "{0}p".format(height)

            if playlist.stream_info.bandwidth:
                bw = playlist.stream_info.bandwidth

                if bw >= 1000:
                    names["bitrate"] = "{0}k".format(int(bw / 1000.0))
                else:
                    names["bitrate"] = "{0}k".format(bw / 1000.0)

            if name_fmt:
                stream_name = name_fmt.format(**names)
            else:
                stream_name = (names.get(name_key) or names.get("name")
                               or names.get("pixels") or names.get("bitrate"))

            if not stream_name:
                continue
            if name_prefix:
                stream_name = "{0}{1}".format(name_prefix, stream_name)

            if stream_name in streams:  # rename duplicate streams
                stream_name = "{0}_alt".format(stream_name)
                num_alts = len(
                    list(
                        filter(lambda n: n.startswith(stream_name),
                               streams.keys())))

                # We shouldn't need more than 2 alt streams
                if num_alts >= 2:
                    continue
                elif num_alts > 0:
                    stream_name = "{0}{1}".format(stream_name, num_alts + 1)

            if check_streams:
                try:
                    session_.http.get(playlist.uri, **request_params)
                except KeyboardInterrupt:
                    raise
                except Exception:
                    continue

            external_audio = preferred_audio or default_audio or fallback_audio

            if external_audio and FFMPEGMuxer.is_usable(session_):
                external_audio_msg = u", ".join([
                    u"(language={0}, name={1})".format(x.language,
                                                       (x.name or "N/A"))
                    for x in external_audio
                ])
                log.debug(
                    u"Using external audio tracks for stream {0} {1}".format(
                        stream_name, external_audio_msg))

                stream = MuxedHLSStream(
                    session_,
                    video=playlist.uri,
                    audio=[x.uri for x in external_audio if x.uri],
                    force_restart=force_restart,
                    start_offset=start_offset,
                    duration=duration,
                    **request_params)
            else:
                stream = cls(session_,
                             playlist.uri,
                             force_restart=force_restart,
                             start_offset=start_offset,
                             duration=duration,
                             **request_params)
            streams[stream_name] = stream

        return streams