Beispiel #1
0
    def list_files(self):
        for enclosure in getattr(self.entry, 'enclosures', []):
            if not 'href' in enclosure:
                continue

            mimetype = get_mimetype(enclosure.get('type', ''),
                                    enclosure['href'])

            try:
                filesize = int(enclosure.get('length', None))
            except (TypeError, ValueError):
                filesize = None

            #TODO: optional: urls = tils.get_redirect_chain(enclosure['href'])
            urls = [enclosure['href']]
            yield (urls, mimetype, filesize)

        media_content = getattr(self.entry, 'media_content', [])
        for media in media_content:
            if not 'url' in media:
                continue

            mimetype = get_mimetype(media.get('type', ''), media['url'])

            try:
                filesize = int(media.get('fileSize', None))
            except (TypeError, ValueError):
                filesize = None

            #TODO: optional: urls = utils.get_redirect_chain(media['url'])
            urls = [media['url']]
            yield urls, mimetype, filesize
Beispiel #2
0
    def list_files(self):
        for enclosure in getattr(self.entry, 'enclosures', []):
            if not 'href' in enclosure:
                continue

            mimetype = get_mimetype(enclosure.get('type', ''),
                                    enclosure['href'])

            try:
                filesize = int(enclosure.get('length', None))
            except (TypeError, ValueError):
                filesize = None

            #TODO: optional: urls = tils.get_redirect_chain(enclosure['href'])
            urls = [enclosure['href']]
            yield (urls, mimetype, filesize)

        media_content = getattr(self.entry, 'media_content', [])
        for media in media_content:
            if not 'url' in media:
                continue

            mimetype = get_mimetype(media.get('type', ''), media['url'])

            try:
                filesize = int(media.get('fileSize', None))
            except (TypeError, ValueError):
                filesize = None

            #TODO: optional: urls = utils.get_redirect_chain(media['url'])
            urls = [media['url']]
            yield urls, mimetype, filesize
Beispiel #3
0
    def get_logo_inline(self):
        """ Fetches the feed's logo and returns its data URI """

        if not self.inline_logo:
            return None

        logo_url = self.get_logo_url()

        if not logo_url:
            return None

        try:
            url, content, last_mod_up, last_mod_utc, etag, content_type, \
                length = fetch_url(logo_url)

        except Exception as e:
            msg = 'could not fetch feed logo %(logo_url)s: %(msg)s' % \
                dict(logo_url=logo_url, msg=str(e))
            self.add_warning('fetch-logo', msg)
            logging.info(msg)
            return None

        # TODO: uncomment
        #if last_mod_up and mod_since_up and last_mod_up <= mod_since_up:
        #    return None

        mtype = mimetype.get_mimetype(None, url)

        transform_args = dict(size=self.scale_to, img_format=self.logo_format)

        if any(transform_args.values()):
            content, mtype = transform_image(content, mtype, **transform_args)

        return get_data_uri(content, mtype)
Beispiel #4
0
    def get_logo_inline(self):
        """ Fetches the feed's logo and returns its data URI """

        if not self.inline_logo:
            return None

        logo_url = self.get_logo_url()

        if not logo_url:
            return None

        try:
            url, content, last_mod_up, last_mod_utc, etag, content_type, \
                length = fetch_url(logo_url)

        except Exception as e:
            msg = 'could not fetch feed logo %(logo_url)s: %(msg)s' % \
                dict(logo_url=logo_url, msg=str(e))
            self.add_warning('fetch-logo', msg)
            logging.info(msg)
            return None

        # TODO: uncomment
        #if last_mod_up and mod_since_up and last_mod_up <= mod_since_up:
        #    return None

        mtype = mimetype.get_mimetype(None, url)

        transform_args = dict(size=self.scale_to, img_format=self.logo_format)

        if any(transform_args.values()):
            content, mtype = transform_image(content, mtype, **transform_args)

        return get_data_uri(content, mtype)
    def get_files(self):
        url = self.entry.get('url', None)
        # we don't want to leak the consumer key
        url = url.replace(settings.SOUNDCLOUD_CONSUMER_KEY, '')
        mimetype = get_mimetype(self.entry.get('mimetype', None), url)
        filesize = self.entry.get('length', None)

        yield File([url], mimetype, filesize)
Beispiel #6
0
    def list_files(self):
        if not self.url:
            return

        mimetype = get_mimetype(None, self.url)
        yield ([self.url], mimetype, None)