Пример #1
0
    def google_image(self, query):
        """Fetch the first image of a Google image query"""
        additionnalkw = "+dvd+movie+cover"
        query = "+".join(query.split(" ")) + additionnalkw
        query = "/ajax/services/search/images?q=%s&v=1.0&imgsz=medium"%(query)
        query = query.encode("utf-8")
        headers = {
            'Host': "ajax.googleapis.com",
            'Accept-Charset': "utf-8"
            }
        headers.update(HEADERS)

        r = self.request("GET",
                         query,
                         headers=headers,
                         server="ajax.googleapis.com")
        try:
            r = json.loads(r, "utf-8")
            if 'responseData' in r:
                response = r['responseData']
                if 'results' in response:
                    results = response['results']
                    if len(results) > 0:
                        first = results[0]
                        if 'url' in first:
                                return FileTools.download_image(first['url'])
        except Exception as e:
            print >> sys.stderr, "Error while fetching cover : %s."%(e)

        return ""
Пример #2
0
    def google_image(self, query):
        """Fetch the first image of a Google image query"""
        additionnalkw = "+dvd+movie+cover"
        query = "+".join(query.split(" ")) + additionnalkw
        query = "/ajax/services/search/images?q=%s&v=1.0&imgsz=medium" % (
            query)
        query = query.encode("utf-8")
        headers = {'Host': "ajax.googleapis.com", 'Accept-Charset': "utf-8"}
        headers.update(HEADERS)

        r = self.request("GET",
                         query,
                         headers=headers,
                         server="ajax.googleapis.com")
        try:
            r = json.loads(r, "utf-8")
            if 'responseData' in r:
                response = r['responseData']
                if 'results' in response:
                    results = response['results']
                    if len(results) > 0:
                        first = results[0]
                        if 'url' in first:
                            return FileTools.download_image(first['url'])
        except Exception as e:
            print >> sys.stderr, "Error while fetching cover : %s." % (e)

        return ""
Пример #3
0
 def __init__(self, movie_name=u"", imdb_link=u"",
              description=u"", cover=u"", year=""):
     self._title = movie_name.strip()
     self._imdb_link = imdb_link
     self._description = description
     self._cover = cover
     if cover != u"":
         url = urlparse.urlparse(cover)
         if url.scheme == "http":
             self._cover = FileTools.download_image(cover)
     self._year = year
Пример #4
0
 def __init__(self,
              movie_name=u"",
              imdb_link=u"",
              description=u"",
              cover=u"",
              year=""):
     self._title = movie_name.strip()
     self._imdb_link = imdb_link
     self._description = description
     self._cover = cover
     if cover != u"":
         url = urlparse.urlparse(cover)
         if url.scheme == "http":
             self._cover = FileTools.download_image(cover)
     self._year = year