Ejemplo n.º 1
0
    def fetch(self, cmd, img=False, timeout=10):
        try:
            host = htpc.settings.get('sickbeard_host', '')
            port = str(htpc.settings.get('sickbeard_port', ''))
            apikey = htpc.settings.get('sickbeard_apikey', '')
            ssl = 's' if htpc.settings.get('sickbeard_ssl', 0) else ''
            sickbeard_basepath = fix_basepath(
                htpc.settings.get('sickbeard_basepath', '/'))

            url = 'http' + ssl + '://' + host + ':' + str(
                port) + sickbeard_basepath + 'api/' + apikey + '/?cmd=' + cmd

            self.logger.debug('Fetching information from: %s' % url)

            if img is True:
                # Cache image
                return get_image(url)

            r = requests.get(url, timeout=timeout, verify=False)
            if r:
                r = r.json()

            return r
        except:
            self.logger.error('Unable to fetch information')
            return
Ejemplo n.º 2
0
 def GetThumb(self, thumb=None, h=None, w=None, o=100, mode=None):
     """ Parse thumb to get the url and send to htpc.proxy.get_image """
     url = self.url('/images/DefaultVideo.png')
     if thumb:
         url = self.url('/image/' + quote(thumb))
     self.logger.debug("Trying to fetch image via %s" % url)
     return get_image(url, h, w, o, mode, self.auth())
Ejemplo n.º 3
0
 def GetThumb(self, url=None, thumb=None, h=None, w=None, o=100):
     """ Parse thumb to get the url and send to htpc.proxy.get_image """
     self.logger.debug("Trying to fetch image via %s" % url)
     if url is None and thumb is None:
         # To stop if the image is missing
         return
     # Should never used thumb, to lazy to remove it
     if thumb:
         url = thumb
     return get_image(url, h, w, o)
Ejemplo n.º 4
0
 def GetThumb(self, url=None, thumb=None, h=None, w=None, o=100):
     """ Parse thumb to get the url and send to htpc.proxy.get_image """
     self.logger.debug("Trying to fetch image via %s", url)
     if url is None and thumb is None:
         # To stop if the image is missing
         return
     # Should never used thumb, to lazy to remove it
     if thumb:
         url = thumb
     return get_image(url, h, w, o)
Ejemplo n.º 5
0
    def GetImage(self, url, h=None, w=None, o=100, *args, **kwargs):
        # url can be a string or json
        working_url = None
        imgdir = os.path.join(htpc.DATADIR, 'images/')
        try:
            x = json.loads(url)
            if isinstance(x, list):
                tl = [(hashlib.md5(u).hexdigest(), u) for u in x]
                checkurl = []
                # check any of the images exist in the cache
                for i in tl:
                    if os.path.isfile(os.path.join(imgdir, i[0])):
                        #self.logger.debug('%s exist in cache, ignore the rest of the hashes %s' % (str(i[1]), str(tl)))
                        # dont bother checking any else if we have image
                        checkurl = []
                        working_url = i[1]
                        break
                    else:
                        checkurl.append(i)
                        continue

                if working_url:
                    return get_image(working_url, h, w, o)
                else:
                    # None of the imges existed in the cache
                    if checkurl:
                        for ii, i in enumerate(checkurl):
                            # verify that the download is ok before we try to cache it.
                            try:
                                r = requests.get(i[1], headers={'Cache-Control': 'private, max-age=0, no-cache, must-revalidate', 'Pragma': 'no-cache'})
                                if r.content:
                                    working_url = i[1]
                                    break

                            except Exception as e:
                                self.logger.error('Error: %s url: %s item: %s  loop n : %s  tuplelist %s' % (e, i[1], i, ii, str(tl)))

                        if working_url:
                            return get_image(working_url, h, w, o)

        except ValueError as e:
            if isinstance(url, basestring):
                return get_image(url, h, w, o)
Ejemplo n.º 6
0
    def fetch(self, cmd, img=False, timeout=20):
        try:
            host = striphttp(htpc.settings.get('sickrage_host', ''))
            port = str(htpc.settings.get('sickrage_port', ''))
            apikey = htpc.settings.get('sickrage_apikey', '')
            ssl = 's' if htpc.settings.get('sickrage_ssl', 0) else ''
            sickrage_basepath = fix_basepath(htpc.settings.get('sickrage_basepath', '/'))

            url = 'http%s://%s:%s%sapi/%s/?cmd=%s' % (ssl, host, port, sickrage_basepath, apikey, cmd)

            self.logger.debug('Fetching information from: %s' % url)

            if img is True:
                # Cache the images
                return get_image(url)

            res = requests.get(url, timeout=timeout, verify=False)
            return res.json()
        except Exception as e:
            self.logger.error('Unable to fetch information')
            self.logger.error(url)
            self.logger.error(e)
            return
Ejemplo n.º 7
0
    def fetch(self, path, banner=None, type=None, data=None):
        try:
            host = striphttp(htpc.settings.get('sonarr_host', ''))
            port = str(htpc.settings.get('sonarr_port', ''))
            sonarr_basepath = htpc.settings.get('sonarr_basepath', '/')
            ssl = 's' if htpc.settings.get('sonarr_ssl', True) else ''

            # Makes sure that the basepath is /whatever/
            sonarr_basepath = fix_basepath(sonarr_basepath)

            headers = {'X-Api-Key': htpc.settings.get('sonarr_apikey', '')}

            url = 'http%s://%s:%s%sapi/%s' % (ssl, host, port, sonarr_basepath, path)

            if banner:
                #  the path includes the basepath automaticly (if fetched from api command 'Series')
                # Cache the image in HTPC Manager aswell.
                return get_image(url, headers=headers)

            if type == 'post':
                r = requests.post(url, data=dumps(data), headers=headers, verify=False)
                return r.content

            elif type == 'put':
                r = requests.put(url, data=dumps(data), headers=headers, verify=False)
                return r.content

            elif type == 'delete':
                r = requests.delete(url, data=dumps(data), headers=headers, verify=False)
                return r.content

            else:
                r = requests.get(url, headers=headers, verify=False)
                return loads(r.text)

        except Exception as e:
            self.logger.error('Failed to fetch url=%s path=%s error %s' % (url, path, e))
Ejemplo n.º 8
0
    def fetch(self, cmd, img=False, timeout=10):
        try:
            host = htpc.settings.get('sickbeard_host', '')
            port = str(htpc.settings.get('sickbeard_port', ''))
            apikey = htpc.settings.get('sickbeard_apikey', '')
            ssl = 's' if htpc.settings.get('sickbeard_ssl', 0) else ''
            sickbeard_basepath = fix_basepath(htpc.settings.get('sickbeard_basepath', '/'))

            url = 'http' + ssl + '://' + host + ':' + str(port) + sickbeard_basepath + 'api/' + apikey + '/?cmd=' + cmd

            self.logger.debug('Fetching information from: %s' % url)

            if img is True:
                # Cache image
                return get_image(url)

            r = requests.get(url, timeout=timeout, verify=False)
            if r:
                r = r.json()

            return r
        except:
            self.logger.error('Unable to fetch information')
            return
Ejemplo n.º 9
0
    def thumb(self, url='', h=None, w=None, o=100, category=None, **kwargs):
        ''' If the indexer has a url, it uses that one to download if not it will try to
            find a url via fanart.tv or tvmaze
        '''
        fanart_results = []

        t = None
        # coverurl is missing..
        if 'tvrage' in kwargs:
            t = 'tvrage'
            _id = kwargs['tvrage']
            url = None
        elif 'thetvdb' in kwargs:
            t = 'thetvdb'
            _id = kwargs['thetvdb']
            url = None
        elif 'imdb' in kwargs:
            t = 'imdb'
            _id = kwargs['imdb']
            url = None

        # do http://omdbapi.com/ aswell?
        if t:
            if category:
                cat = category.split('>')[0].lower().strip()

                if cat == 'movie':
                    cat == 'movies'

            if cat in ('tv', 'movies'):
                imagetype = None

                if t in ('thetvdb', 'tvrage'):
                    imagetype = 'tvposter'

                elif t == 'imdb':
                    _id = 'tt%s' % _id
                    imagetype = 'movieposter'

                # lets try fanart.tv first
                if t in ('thetvdb', 'imdb'):
                    fanart_results = fan_art(_id, t=cat, wanted_art=imagetype)

                if len(fanart_results):
                    url = fanart_results[0]
                else:
                    tvmazecomp = {'tv': 'shows',
                                  'movies': 'movies'}
                    tvmaze_results = tvmaze(_id, t, tvmazecomp[cat])

                    if len(tvmaze_results):
                        url = tvmaze_results[0]

            elif cat == 'music':
                # todo?
                pass
            elif cat == 'games':
                pass

        if url:
            self.logger.debug('Downloading %s' % url)
            return get_image(url, h, w, o)