Exemplo n.º 1
0
 def fetch_channel(self, channel):
     # If we have a username or password, rebuild the url with them included
     # Note: using a HTTPBasicAuthHandler would be pain because we need to
     # know the realm. It can be done, but I think this method works, too
     url = channel.authenticate_url(channel.url)
     for handler in self.custom_handlers:
         custom_feed = handler.handle_url(url)
         if custom_feed is not None:
             return feedcore.Result(feedcore.CUSTOM_FEED, custom_feed)
     return self.fetch(url, channel.http_etag, channel.http_last_modified)
Exemplo n.º 2
0
    def fetch_episodes(cls, channel, max_episodes=0):
        """
		Used in gPodder 3.10.16 but not 3.10.1.

		Parameters
		----------
		channel      : gpodder.model.PodcastChannel
		max_episodes : int
		"""

        return feedcore.Result(feedcore.UPDATED_FEED,
                               cls.handle_url(channel.url, max_episodes))
Exemplo n.º 3
0
    def refresh(self, url, channel_url, max_episodes):
        """
        Fetch a channel or playlist contents.

        Doesn't yet fetch video entry informations, so we only get the video id and title.
        """

        # Duplicate a bit of the YoutubeDL machinery here because we only
        # want to parse the channel/playlist first, not to fetch video entries.
        # We call YoutubeDL.extract_info(process=False), so we
        # have to call extract_info again ourselves when we get a result of type 'url'.
        def extract_type(ie_result):
            result_type = ie_result.get('_type', 'video')
            if result_type not in ('url', 'playlist', 'multi_video'):
                raise Exception(
                    'Unsuported result_type: {}'.format(result_type))
            has_playlist = result_type in ('playlist', 'multi_video')
            return result_type, has_playlist

        opts = {
            'youtube_include_dash_manifest':
            False,  # only interested in video title and id
        }
        opts.update(self._ydl_opts)
        with youtube_dl.YoutubeDL(opts) as ydl:
            ie_result = ydl.extract_info(url, download=False, process=False)
            result_type, has_playlist = extract_type(ie_result)
            while not has_playlist:
                if result_type in ('url', 'url_transparent'):
                    ie_result['url'] = youtube_dl.utils.sanitize_url(
                        ie_result['url'])
                if result_type == 'url':
                    logger.debug("extract_info(%s) to get the video list",
                                 ie_result['url'])
                    # We have to add extra_info to the results because it may be
                    # contained in a playlist
                    ie_result = ydl.extract_info(
                        ie_result['url'],
                        download=False,
                        process=False,
                        ie_key=ie_result.get('ie_key'))
                result_type, has_playlist = extract_type(ie_result)
        cover_url = youtube.get_cover(
            channel_url)  # youtube-dl doesn't provide the cover url!
        description = youtube.get_channel_desc(
            channel_url)  # youtube-dl doesn't provide the description!
        return feedcore.Result(
            feedcore.UPDATED_FEED,
            YoutubeFeed(url, cover_url, description, max_episodes, ie_result,
                        self))
Exemplo n.º 4
0
 def handle_url(cls, url, max_episodes):
     m = cls.URL_REGEX.match(url)
     if m is not None:
         subdomain, username = m.groups()
         return feedcore.Result(feedcore.UPDATED_FEED,
                                cls(username, max_episodes))