示例#1
0
文件: imdb.py 项目: 0101/downloadar
    def _update_entry_imdb_info(self, entry, data=None):
        try:
            id=entry.content['imdb']['ID']
        except KeyError:
            return

        entry.imdb_id = id

        old_data = entry.content['imdb']
        imdb_data = data or IMDB.get(id=id)
        if not imdb_data:
            return

        # update title
        title = imdb_data.get('Title')
        if title:
            if entry.title:
                entry.content['release_name'] = entry.title
            entry.title = title

        # download a poster if we don't have it already
        poster_url = imdb_data.get('Poster')
        if (poster_url and (not entry.content.get('image') or
                            poster_url != old_data['Poster'])):

            # TODO: need to worry about different formats?
            filename = '%s.jpg' % id
            image_url = download_image(poster_url, join('imdb', filename))
            if image_url:
                entry.content['image'] = image_url

        entry.content['imdb'].update(imdb_data)
示例#2
0
 def _get_image_from_summary(self, entry):
     """
     Downloads first image from summary and sets it as entry.content.image
     """
     summary = entry.content.get("summary")
     if summary:
         bs = BeautifulSoup(summary)
         img = bs.find("img")
         if img:
             src = img.get("src")
             if src:
                 ext = src.split(".")[-1]
                 if 3 <= len(ext) <= 4:
                     filename = "%s.%s" % (entry.uid, ext)
                     image_url = download_image(src, join("cache", filename))
                     if image_url:
                         entry.content["image"] = image_url
                         # replace original image src so it loads faster
                         img["src"] = settings.STATIC_URL + image_url
                         entry.content["summary"] = unicode(bs)