Exemplo n.º 1
0
    def extract_source(self, url, quality=None):
        """
        Extract video url using YoutubeDL.

        The YoutubeDL module provides access to youtube-dl video stream extractor
        witch gives access to hundreds of sites.

        Quality is 0=SD, 1=720p, 2=1080p, 3=Highest Available

        .. seealso:: https://rg3.github.io/youtube-dl/supportedsites.html

        :param url: Url to fetch video for.
        :type url: str or unicode
        :param int quality: [opt] Override youtubeDL's quality setting.

        :returns: The extracted video url
        :rtype: str

        .. note::

            Unfortunately the kodi YoutubeDL module is python2 only.
            Hopefully it will be ported to python3 when kodi gets upgraded.
        """
        def ytdl_logger(record):
            if record.startswith("ERROR:"):
                # Save error rocord for raising later, outside of the callback
                # YoutubeDL ignores errors inside callbacks
                stored_errors.append(record[7:])

            self.log(record)
            return True

        # Setup YoutubeDL module
        from YDStreamExtractor import getVideoInfo, setOutputCallback
        setOutputCallback(ytdl_logger)
        stored_errors = []

        # Atempt to extract video source
        video_info = getVideoInfo(url, quality)
        if video_info:
            if video_info.hasMultipleStreams():
                # More than one stream found, Ask the user to select a stream
                return self.__source_selection(video_info)
            else:
                return video_info.streamURL()

        # Raise any stored errors
        elif stored_errors:
            raise RuntimeError(stored_errors[0])
Exemplo n.º 2
0
    def extract_source(self, url, quality=None, **params):
        """
        Extract video url using YoutubeDL.

        YoutubeDL provides access to hundreds of sites.

        Quality options are.
            * 0 = SD,
            * 1 = 720p,
            * 2 = 1080p,
            * 3 = Highest Available

        :param url: Url of the video source to extract the playable video from.
        :type url: str or unicode
        :param int quality: [opt] Override youtubeDL's quality setting.
        :param params: Optional Keyword arguments of youtube_dl parameters.

        :returns: The playable video url
        :rtype: str

        .. seealso::

            The list of supported sites can be found at:

            https://rg3.github.io/youtube-dl/supportedsites.html

        .. seealso::

            The list of available parameters can be found at.

            https://github.com/rg3/youtube-dl#options

        .. note::

            Unfortunately the kodi Youtube-DL module is python2 only.
            It should be ported to python3 when kodi switches to python 3 for version 19.
        """
        def ytdl_logger(record):
            if record.startswith("ERROR:"):
                # Save error rocord for raising later, outside of the callback
                # YoutubeDL ignores errors inside callbacks
                stored_errors.append("Youtube-DL: " + record[7:])

            self.log(record)
            return True

        # Setup YoutubeDL module
        from YDStreamExtractor import getVideoInfo, setOutputCallback, overrideParam
        setOutputCallback(ytdl_logger)
        stored_errors = []

        # Override youtube_dl parmeters
        for key, value in params.items():
            overrideParam(key, value)

        # Atempt to extract video source
        video_info = getVideoInfo(url, quality)
        if video_info:
            if video_info.hasMultipleStreams():
                # More than one stream found, Ask the user to select a stream
                return self._source_selection(video_info)
            else:
                return video_info.streamURL()

        # Raise any stored errors
        elif stored_errors:
            raise RuntimeError(stored_errors[0])
Exemplo n.º 3
0
    def extract_source(self, url, quality=None, **params):
        """
        Extract video URL using "YouTube.DL".

        YouTube.DL provides access to hundreds of sites.

        .. seealso::

            The list of supported sites can be found at:

            https://rg3.github.io/youtube-dl/supportedsites.html

        Quality options are.
            * 0 = SD,
            * 1 = 720p,
            * 2 = 1080p,
            * 3 = Highest Available

        :param str url: URL of the video source, where the playable video can be extracted from.
        :param int quality: [opt] Override YouTube.DL's quality setting.
        :param params: Optional "Keyword" arguments of YouTube.DL parameters.

        :returns: The playable video url
        :rtype: str

        .. seealso::

            The list of available parameters can be found at.

            https://github.com/rg3/youtube-dl#options

        .. note::

            Unfortunately the Kodi YouTube.DL module is Python 2 only. It should be
            ported to Python 3 when Kodi switches to Python 3 for version 19.
        """

        def ytdl_logger(record):
            if record.startswith("ERROR:"):
                # Save error rocord for raising later, outside of the callback
                # YoutubeDL ignores errors inside callbacks
                stored_errors.append("Youtube-DL: " + record[7:])

            self.log(record)
            return True

        # Setup YoutubeDL module
        # noinspection PyUnresolvedReferences
        from YDStreamExtractor import getVideoInfo, setOutputCallback, overrideParam
        setOutputCallback(ytdl_logger)
        stored_errors = []

        # Override youtube_dl parmeters
        for key, value in params.items():
            overrideParam(key, value)

        # Atempt to extract video source
        video_info = getVideoInfo(url, quality)
        if video_info:
            if video_info.hasMultipleStreams():
                # More than one stream found, Ask the user to select a stream
                video_info = self._source_selection(video_info)

            if video_info:
                # Content Lookup needs to be disabled for dailymotion videos to work
                if video_info.sourceName == "dailymotion":
                    self._extra_commands["setContentLookup"] = False

                return video_info.streamURL()

        # Raise any stored errors
        elif stored_errors:
            raise RuntimeError(stored_errors[0])