예제 #1
0
    def get_cover(self,
                  filename,
                  cover_url,
                  feed_url,
                  title,
                  username=None,
                  password=None,
                  download=False):
        # Detection of "all episodes" podcast
        if filename == self.ALL_EPISODES_ID:
            return self.get_cover_all_episodes()

        # Return already existing files
        for extension in self.EXTENSIONS:
            if os.path.exists(filename + extension):
                return filename + extension

        # If allowed to download files, do so here
        if download:
            # YouTube-specific cover art image resolver
            youtube_cover_url = youtube.get_real_cover(feed_url)
            if youtube_cover_url is not None:
                cover_url = youtube_cover_url

            if not cover_url:
                return self._fallback_filename(title)

            # We have to add username/password, because password-protected
            # feeds might keep their cover art also protected (bug 1521)
            if username is not None and password is not None:
                cover_url = util.url_add_authentication(
                    cover_url, username, password)

            try:
                logger.info('Downloading cover art: %s', cover_url)
                data = util.urlopen(cover_url, timeout=self.TIMEOUT).read()
            except Exception, e:
                logger.warn('Cover art download failed: %s', e)
                return self._fallback_filename(title)

            try:
                extension = None

                for filetype, check in self.SUPPORTED_EXTENSIONS.items():
                    if check(data):
                        extension = filetype
                        break

                if extension is None:
                    msg = 'Unknown file type: %s (%r)' % (cover_url, data[:6])
                    raise ValueError(msg)

                # Successfully downloaded the cover art - save it!
                fp = open(filename + extension, 'wb')
                fp.write(data)
                fp.close()

                return filename + extension
            except Exception, e:
                logger.warn('Cannot save cover art', exc_info=True)
예제 #2
0
    def get_cover(self, filename, cover_url, feed_url, title,
            username=None, password=None, download=False):
        # Detection of "all episodes" podcast
        if filename == self.ALL_EPISODES_ID:
            return self.get_cover_all_episodes()

        # Return already existing files
        for extension in self.EXTENSIONS:
            if os.path.exists(filename + extension):
                return filename + extension

        # If allowed to download files, do so here
        if download:
            # YouTube-specific cover art image resolver
            youtube_cover_url = youtube.get_real_cover(feed_url)
            if youtube_cover_url is not None:
                cover_url = youtube_cover_url

            if not cover_url:
                return self._fallback_filename(title)

            # We have to add username/password, because password-protected
            # feeds might keep their cover art also protected (bug 1521)
            if username is not None and password is not None:
                cover_url = util.url_add_authentication(cover_url,
                        username, password)

            try:
                logger.info('Downloading cover art: %s', cover_url)
                data = util.urlopen(cover_url).read()
            except Exception, e:
                logger.warn('Cover art download failed: %s', e)
                return self._fallback_filename(title)

            try:
                extension = None

                for filetype, check in self.SUPPORTED_EXTENSIONS.items():
                    if check(data):
                        extension = filetype
                        break

                if extension is None:
                    msg = 'Unknown file type: %s (%r)' % (cover_url, data[:6])
                    raise ValueError(msg)

                # Successfully downloaded the cover art - save it!
                fp = open(filename + extension, 'wb')
                fp.write(data)
                fp.close()

                return filename + extension
            except Exception, e:
                logger.warn('Cannot save cover art', exc_info=True)
예제 #3
0
    def get_default_cover(self, channel):
        # "randomly" choose a cover based on the podcast title
        basename = 'podcast-%d.png' % (hash(channel.title) % 5)
        filename = os.path.join(gpodder.images_folder, basename)
        return gtk.gdk.pixbuf_new_from_file(filename)

    def __get_cover(self, channel, url, async=False, avoid_downloading=False):
        if not async and avoid_downloading and not os.path.exists(
                channel.cover_file):
            return (channel.url, self.get_default_cover(channel))

        if not os.path.exists(channel.cover_file):
            if url is None:
                url = channel.image

            new_url = youtube.get_real_cover(channel.url)
            if new_url is not None:
                url = new_url

            if url is None and channel.link is not None and \
                    channel.link.startswith('http://'):
                # Try to use the favicon of the linked website's host
                split_result = urlparse.urlsplit(channel.link)
                scheme, netloc, path, query, fragment = split_result
                path = '/favicon.ico'
                query = ''
                split_result = (scheme, netloc, path, query, fragment)
                url = urlparse.urlunsplit(split_result)
                log('Trying favicon: %s', url, sender=self)

            if url is not None:
예제 #4
0
    def get_default_cover(self, channel):
        # "randomly" choose a cover based on the podcast title
        basename = "podcast-%d.png" % (hash(channel.title) % 5)
        filename = os.path.join(gpodder.images_folder, basename)
        return gtk.gdk.pixbuf_new_from_file(filename)

    def __get_cover(self, channel, url, async=False, avoid_downloading=False):
        if not async and avoid_downloading and not os.path.exists(channel.cover_file):
            return (channel.url, self.get_default_cover(channel))

        if not os.path.exists(channel.cover_file):
            if url is None:
                url = channel.cover_url

            new_url = youtube.get_real_cover(channel.url)
            if new_url is not None:
                url = new_url

            if url is None and channel.link is not None and channel.link.startswith("http://"):
                # Try to use the favicon of the linked website's host
                split_result = urlparse.urlsplit(channel.link)
                scheme, netloc, path, query, fragment = split_result
                path = "/favicon.ico"
                query = ""
                split_result = (scheme, netloc, path, query, fragment)
                url = urlparse.urlunsplit(split_result)
                logger.debug("Trying favicon: %s", url)

            if url is not None:
                image_data = None