def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {'api-key': 'YTc2MGMyMTEzYTM1OTk5NzFiN2FjMWU0OWUzMTAyMGQ='.decode('base64')}
        if not self.fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': self.fanart_tv_user})

        for i in range(0, total): self.list[i].update({'metacache': False})

        self.list = metacache.fetch(self.list, self.lang, self.user)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if self.meta: metacache.insert(self.meta)

        self.list = [i for i in self.list if not i['tvdb'] == '0']

        if self.fanart_tv_user == '':
            for i in self.list: i.update({'clearlogo': '0', 'clearart': '0'})
Exemple #2
0
    def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {'api-key': '04cd6efd5628ec6082644538a6045bdc'}
        if not self.fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': self.fanart_tv_user})

        for i in range(0, total): self.list[i].update({'metacache': False})

        self.list = metacache.fetch(self.list, self.lang, self.user)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if self.meta: metacache.insert(self.meta)

        self.list = [i for i in self.list if not i['imdb'] == '0']

        self.list = metacache.local(self.list, self.tm_img_link, 'poster3', 'fanart2')

        if self.fanart_tv_user == '':
            for i in self.list: i.update({'clearlogo': '0', 'clearart': '0'})
Exemple #3
0
	def worker(self):
		if not control.setting('metadata') == 'true': return

		self.imdb_info_link = 'http://www.omdbapi.com/?i=%s&plot=full&r=json'
		self.tvmaze_info_link = 'http://api.tvmaze.com/lookup/shows?thetvdb=%s'
		self.lang = 'en'

		self.meta = []
		total = len(self.list)
		if total == 0: return

		for i in range(0, total):
			self.list[i].update({'metacache': False})

		self.list = metacache.fetch(self.list, self.lang)

		multi = [i['imdb'] for i in self.list]
		multi = [x for y,x in enumerate(multi) if x not in multi[:y]]
		if len(multi) == 1:
				self.movie_info(0) ; self.tv_info(0)
				if self.meta: metacache.insert(self.meta)

		for i in range(0, total): self.list[i].update({'metacache': False})
		self.list = metacache.fetch(self.list, self.lang)

		for r in range(0, total, 50):
			threads = []
			for i in range(r, r+50):
				if i <= total: threads.append(workers.Thread(self.movie_info, i))
				if i <= total: threads.append(workers.Thread(self.tv_info, i))
			[i.start() for i in threads]
			[i.join() for i in threads]

			if self.meta:
				metacache.insert(self.meta)
Exemple #4
0
    def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {'api-key': 'ZDY5NTRkYTk2Yzg4ODFlMzdjY2RkMmQyNTlmYjk1MzQ='.decode('base64')}
        if not self.fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': self.fanart_tv_user})

        for i in range(0, total): self.list[i].update({'metacache': False})

        self.list = metacache.fetch(self.list, self.lang, self.user)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if self.meta: metacache.insert(self.meta)

        self.list = [i for i in self.list if not i['imdb'] == '0']

        self.list = metacache.local(self.list, self.tm_img_link, 'poster3', 'fanart2')

        if self.fanart_tv_user == '':
            for i in self.list: i.update({'clearlogo': '0', 'clearart': '0'})
Exemple #5
0
    def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {'api-key': 'db10619c97af83891690f4cfd7205d62'}
        if not self.fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': self.fanart_tv_user})

        for i in range(0, total):
            self.list[i].update({'metacache': False})

        self.list = metacache.fetch(self.list, self.lang, self.user)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r + 40):
                if i <= total:
                    threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if self.meta:
                metacache.insert(self.meta)

        self.list = [i for i in self.list if not i['imdb'] == '0']

        self.list = metacache.local(self.list, self.tm_img_link, 'poster3', 'fanart2')

        if self.fanart_tv_user == '':
            for i in self.list:
                i.update({'clearlogo': '0', 'clearart': '0'})
Exemple #6
0
    def worker(self):
        if not control.setting('metadata') == 'true': return

        self.imdb_info_link = 'http://www.omdbapi.com/?i=%s&plot=full&r=json'
        self.tvmaze_info_link = 'http://api.tvmaze.com/lookup/shows?thetvdb=%s'
        self.lang = 'en'

        self.meta = []
        total = len(self.list)
        if total == 0: return

        for i in range(0, total): self.list[i].update({'metacache': False})
        self.list = metacache.fetch(self.list, self.lang)

        multi = [i['imdb'] for i in self.list]
        multi = [x for y,x in enumerate(multi) if x not in multi[:y]]
        if len(multi) == 1:
                self.movie_info(0) ; self.tv_info(0)
                if self.meta: metacache.insert(self.meta)

        for i in range(0, total): self.list[i].update({'metacache': False})
        self.list = metacache.fetch(self.list, self.lang)

        for r in range(0, total, 50):
            threads = []
            for i in range(r, r+50):
                if i <= total: threads.append(workers.Thread(self.movie_info, i))
                if i <= total: threads.append(workers.Thread(self.tv_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

        if self.meta: metacache.insert(self.meta)
    def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {'api-key': 'YTc2MGMyMTEzYTM1OTk5NzFiN2FjMWU0OWUzMTAyMGQ='.decode('base64')}
        if not self.fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': self.fanart_tv_user})

        for i in range(0, total): self.list[i].update({'metacache': False})

        self.list = metacache.fetch(self.list, self.lang, self.user)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if self.meta: metacache.insert(self.meta)

        self.list = [i for i in self.list if not i['tvdb'] == '0']

        if self.fanart_tv_user == '':
            for i in self.list: i.update({'clearlogo': '0', 'clearart': '0'})
Exemple #8
0
    def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {'api-key': 'NDZkZmMyN2M1MmE0YTc3MjY3NWQ4ZTMyYjdiY2E2OGU='.decode('base64')}
        if not self.fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': self.fanart_tv_user})

        for i in range(0, total): self.list[i].update({'metacache': False})

        self.list = metacache.fetch(self.list, self.lang, self.user)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if self.meta: metacache.insert(self.meta)

        self.list = [i for i in self.list if not i['imdb'] == '0']

        self.list = metacache.local(self.list, self.tm_img_link, 'poster3', 'fanart2')

        if self.fanart_tv_user == '':
            for i in self.list: i.update({'clearlogo': '0', 'clearart': '0'})
Exemple #9
0
    def worker(self, level=1):
        self.meta = []
        total = len(self.list)

        self.fanart_tv_headers = {}
        fanart_tv_level = 'user'
        fanart_tv_user = control.setting('fanart.tv.user')
        self.fanart_tv_headers.update({'api-key': 'YTc2MGMyMTEzYTM1OTk5NzFiN2FjMWU0OWUzMTAyMGQ='.decode('base64')})
        if level == 1 and not fanart_tv_user == '':
            self.fanart_tv_headers.update({'client-key': fanart_tv_user})
            #try: fanart_tv_level = json.loads(client.request(self.fanart_tv_level_link, headers=self.fanart_tv_headers))['level']
            #except: pass

        for i in range(0, total): self.list[i].update({'metacache': False})
        self.list = metacache.fetch(self.list, self.lang)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            if len(self.meta) > 0: metacache.insert(self.meta)

        if fanart_tv_level == 'user':
            for i in self.list: i.update({'poster2': '0', 'fanart2': '0', 'banner2': '0', 'clearlogo': '0', 'clearart': '0'})

        self.list = [i for i in self.list if not i['tvdb'] == '0']
Exemple #10
0
 def worker(self):
     self.meta = []
     total = len(self.list)
     for i in range(0, total):
         self.list[i].update({'metacache': False})
     self.list = metacache.fetch(self.list, self.lang)
     for r in range(0, total, 40):
         threads = []
         for i in range(r, r + 40):
             if i <= total:
                 threads.append(workers.Thread(self.super_info, i))
         [i.start() for i in threads]
         [i.join() for i in threads]
         if len(self.meta) > 0:
             metacache.insert(self.meta)
     self.list = [i for i in self.list]
Exemple #11
0
    def worker(self):
        self.meta = []
        total = len(self.list)

        for i in range(0, total): self.list[i].update({'metacache': False})
        self.list = metacache.fetch(self.list, self.lang)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

        self.list = [i for i in self.list if not i['imdb'] == '0']

        if len(self.meta) > 0: metacache.insert(self.meta)
Exemple #12
0
    def worker(self, level=1):
        self.meta = []
        total = len(self.boxset_list)

        for i in range(0, total):
            self.boxset_list[i].update({'metacache': False})
        self.boxset_list = metacache.fetch(self.boxset_list, 'en')

        for r in range(0, total, 100):
            threads = []
            for i in range(r, r + 100):
                if i <= total:
                    threads.append(workers.Thread(self.super_info, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

        self.boxset_list = [i for i in self.boxset_list]

        if len(self.meta) > 0:
            metacache.insert(self.meta)
Exemple #13
0
    def get(self): 
        channels = [('01', 'Sky Premiere', '77'), ('02', 'Sky Classics', '69'), ('03', 'Sky Greats', '76'), ('04', 'Sky Family', '72'), ('05', 'Sky Action', '68'), ('06', 'Sky Comedy', '70'), ('07', 'Sky Drama', '71'), ('08', 'Sky Sci Fi', '78'), ('09', 'Sky Indie', '75'), ('10', 'Film4', '43'), ('11', 'TCM', '89')] 
        
        for i in channels:
            dt = datetime.datetime.now()
            if dt.time() < datetime.time(12):
                when = 'am'
            else:
                when = 'pm'
            content = self.getContent('http://tv.fopii.com/tvlisting%s.html' % i[2])
            onnow = re.findall('<span class="txts">%s</span></td><td width="100%s">(.*?)</td>' % (when, '%'), content,re.MULTILINE | re.DOTALL)
            try:
                if '<a' in onnow[-1]:
                    title = onnow[-2].encode('utf-8')
                else:  
                    title = onnow[-1].encode('utf-8')   	
            except:
                title = ' No Data'
            self.list.append({'title': title, 'channel': i[1], 'year': '0', 'genre': '0', 'duration': '0', 'rating': '0', 'votes': '0', 'mpaa': '0', 'director': '0', 'writer': '0', 'cast': '0', 'plot': '0', 'tagline': '0', 'code': title, 'imdb': title, 'tmdb': '0', 'poster': '0'})
            	
        self.meta = []
        total = len(self.list)
        for i in range(0, total): self.list[i].update({'metacache': False})
        self.list = metacache.fetch(self.list, self.lang)

        for r in range(0, total, 40):
            threads = []
            for i in range(r, r+40):
                if i <= total: threads.append(workers.Thread(self.items_list, i))
            [i.start() for i in threads]
            [i.join() for i in threads]

            
            
        self.list = [i for i in self.list if not i['imdb'] == '0']

        if len(self.meta) > 0: metacache.insert(self.meta)

        
        self.channelDirectory(self.list)
        return self.list
        def items_list(i):
            try:
                next, title, year, tmdb, poster, fanart, premiered, rating, votes, plot, tagline = i[
                    'next'], i['title'], i['year'], i['tmdb'], i['poster'], i[
                        'fanart'], i['premiered'], i['rating'], i['votes'], i[
                            'plot'], i['tagline']

                url = self.tmdb_info_link % tmdb
                item = get_request(url)

                tvdb = str(item.get('external_ids').get('tvdb_id', '0'))
                if tvdb == '' or tvdb is None or tvdb == 'None':
                    tvdb = '0'

                imdb = item.get('external_ids').get('imdb_id', '0')
                if imdb == '' or imdb is None or imdb == 'None':
                    imdb = '0'

                genre = []
                for x in item['genres']:
                    genre.append(x.get('name'))
                if genre == []: genre = 'NA'

                duration = str(item.get('episode_run_time', '0')[0])

                try:
                    mpaa = [
                        x['rating'] for x in item['content_ratings']['results']
                        if x['iso_3166_1'] == 'US'
                    ][0]
                except:
                    try:
                        mpaa = item['content_ratings'][0]['rating']
                    except:
                        mpaa = 'NR'

                status = item.get('status', '0')

                try:
                    studio = item.get('networks', None)[0]['name']
                except:
                    studio = '0'

                credits = item['credits']
                director = writer = '0'
                for person in credits['crew']:
                    if 'Director' in person['job']:
                        director = ', '.join([
                            director['name'].encode('utf-8')
                            for director in credits['crew']
                            if director['job'].lower() == 'director'
                        ])
                    if person['job'] in [
                            'Writer', 'Screenplay', 'Author', 'Novel'
                    ]:
                        writer = ', '.join([
                            writer['name'].encode('utf-8')
                            for writer in credits['crew']
                            if writer['job'].lower() in
                            ['writer', 'screenplay', 'author', 'novel']
                        ])

                castandart = []
                for person in item['credits']['cast']:
                    try:
                        try:
                            castandart.append({
                                'name':
                                person['name'].encode('utf-8'),
                                'role':
                                person['character'].encode('utf-8'),
                                'thumbnail':
                                ((poster_path + person.get('profile_path'))
                                 if person.get('profile_path') is not None else
                                 '0')
                            })
                        except:
                            castandart.append({
                                'name':
                                person['name'],
                                'role':
                                person['character'],
                                'thumbnail':
                                ((poster_path + person.get('profile_path'))
                                 if person.get('profile_path') is not None else
                                 '0')
                            })
                    except:
                        castandart = []
                    if len(castandart) == 150: break

                values = {
                    'content': 'tvshow',
                    'title': title,
                    'originaltitle': title,
                    'year': year,
                    'premiered': premiered,
                    'studio': studio,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'status': status,
                    'director': director,
                    'writer': writer,
                    'castandart': castandart,
                    'plot': plot,
                    'tagline': tagline,
                    'code': tmdb,
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': tvdb,
                    'poster': poster,
                    'poster2': '0',
                    'banner': '0',
                    'banner2': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': fanart,
                    'metacache': False,
                    'next': next
                }

                meta = {
                    'tmdb': tmdb,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'lang': self.lang,
                    'user': API_key,
                    'item': values
                }

                if disable_fanarttv != 'true':
                    from resources.lib.indexers import fanarttv
                    extended_art = cache.get(fanarttv.get_tvshow_art, 168,
                                             tvdb)
                    if extended_art is not None:
                        values.update(extended_art)
                        meta.update(values)

                values = dict(
                    (k, v) for k, v in values.iteritems() if v != '0')
                self.list.append(values)

                if 'next' in meta.get('item'):
                    del meta['item']['next']

                self.meta.append(meta)
                metacache.insert(self.meta)
            except:
                pass
        def items_list(i):
            try:
                next, title, originaltitle, year, tmdb, poster, fanart, premiered, rating, votes, plot, tagline = i[
                    'next'], i['title'], i['originaltitle'], i['year'], i[
                        'tmdb'], i['poster'], i['fanart'], i['premiered'], i[
                            'rating'], i['votes'], i['plot'], i['tagline']

                url = self.tmdb_info_link % tmdb
                item = get_request(url)

                imdb = item.get('imdb_id', '0')
                if imdb == '' or imdb is None or imdb == 'None':
                    imdb = '0'

                # try:
                # studio = item.get('production_companies', None)[0]['name']
                # except:
                # studio = '0'

                genre = []
                for x in item['genres']:
                    genre.append(x.get('name'))
                if genre == []: genre = 'NA'

                duration = str(item.get('runtime', '0'))

                mpaa = item['release_dates']['results']
                mpaa = [x for x in mpaa if x['iso_3166_1'] == 'US']
                try:
                    mpaa = mpaa[0].get('release_dates')[-1].get(
                        'certification')
                    if not mpaa:
                        mpaa = mpaa[0].get('release_dates')[0].get(
                            'certification')
                        if not mpaa:
                            mpaa = mpaa[0].get('release_dates')[1].get(
                                'certification')
                    mpaa = str(mpaa)
                except:
                    mpaa = '0'

                credits = item['credits']
                director = writer = '0'
                for person in credits['crew']:
                    if 'Director' in person['job']:
                        director = ', '.join([
                            director['name'].encode('utf-8')
                            for director in credits['crew']
                            if director['job'].lower() == 'director'
                        ])
                    if person['job'] in [
                            'Writer', 'Screenplay', 'Author', 'Novel'
                    ]:
                        writer = ', '.join([
                            writer['name'].encode('utf-8')
                            for writer in credits['crew']
                            if writer['job'].lower() in
                            ['writer', 'screenplay', 'author', 'novel']
                        ])

                castandart = []
                for person in item['credits']['cast']:
                    try:
                        try:
                            castandart.append({
                                'name':
                                person['name'].encode('utf-8'),
                                'role':
                                person['character'].encode('utf-8'),
                                'thumbnail':
                                ((poster_path + person.get('profile_path'))
                                 if person.get('profile_path') is not None else
                                 '0')
                            })
                        except:
                            castandart.append({
                                'name':
                                person['name'],
                                'role':
                                person['character'],
                                'thumbnail':
                                ((poster_path + person.get('profile_path'))
                                 if person.get('profile_path') is not None else
                                 '0')
                            })
                    except:
                        castandart = []
                    if len(castandart) == 150: break

                try:
                    trailer = [
                        i for i in item['videos']['results']
                        if i['site'] == 'YouTube'
                    ][0]['key']
                    trailer = control.trailer % trailer
                except:
                    trailer = ''

                values = {
                    'content': 'movie',
                    'title': title,
                    'originaltitle': originaltitle,
                    'year': year,
                    'premiered': premiered,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'director': director,
                    'writer': writer,
                    'castandart': castandart,
                    'plot': plot,
                    'tagline': tagline,
                    'code': tmdb,
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'poster': poster,
                    'poster2': '0',
                    'poster3': '0',
                    'banner': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'fanart3': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': fanart,
                    'trailer': trailer,
                    'metacache': False,
                    'next': next
                }

                meta = {
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'lang': self.lang,
                    'user': API_key,
                    'item': values
                }

                if disable_fanarttv != 'true':
                    from resources.lib.indexers import fanarttv
                    extended_art = cache.get(fanarttv.get_movie_art, 168, imdb,
                                             tmdb)
                    if extended_art is not None:
                        values.update(extended_art)
                        meta.update(values)

                values = dict(
                    (k, v) for k, v in values.iteritems() if v != '0')
                self.list.append(values)

                if 'next' in meta.get('item'):
                    del meta['item']['next']

                self.meta.append(meta)
                metacache.insert(self.meta)
            except:
                log_utils.error()
                pass
Exemple #16
0
        def items_list(i):
            # if i['metacache']: return
            try:
                tvmaze = i
                url = self.tvmaze_info_link % i
                item = get_request(url)
                content = item.get('type', '0').lower()
                title = item.get('name')
                title = py_tools.ensure_str(title)
                tvshowtitle = title

                premiered = item.get('premiered', '0')
                try:
                    year = re.search(r"(\d{4})", premiered).group(1)
                except:
                    year = '0'

                imdb = item.get('externals').get('imdb', '0')
                if not imdb or imdb == 'None': imdb = '0'
                tvdb = str(item.get('externals').get('thetvdb', '0'))
                if not tvdb or tvdb == 'None': tvdb = '0'
                # TVMaze does not have tmdb_id in api
                tmdb = '0'

                studio = item.get('network', {}) or item.get('webChannel', {})
                studio = studio.get('name', '0')
                genre = []
                for i in item['genres']:
                    genre.append(i.title())
                if genre == []: genre = 'NA'
                duration = str(item.get('runtime', '0'))
                rating = str(item.get('rating').get('average', '0'))
                plot = client.cleanHTML(item.get('summary', '0'))
                plot = py_tools.ensure_str(plot)
                status = item.get('status', '0')

                castandart = []
                for person in item['_embedded']['cast']:
                    try:
                        # try:
                        # castandart.append({'name': person['person']['name'].encode('utf-8'), 'role': person['character']['name'].encode('utf-8'), 'thumbnail': (person['person']['image']['original'] if person['person']['image']['original'] is not None else '0')})
                        # except:
                        # castandart.append({'name': person['person']['name'], 'role': person['character']['name'], 'thumbnail': (person['person']['image']['medium'] if person['person']['image']['medium'] is not None else '0')})
                        castandart.append({
                            'name':
                            person['person']['name'],
                            'role':
                            person['character']['name'],
                            'thumbnail':
                            (person['person']['image']['medium']
                             if person['person']['image']['medium'] is not None
                             else '0')
                        })
                    except:
                        castandart = []
                    if len(castandart) == 150: break

                image = item.get('image')
                poster = image.get('original',
                                   '0') if image is not None else '0'
                fanart = '0'
                banner = '0'
                mpaa = '0'
                votes = '0'
                airday = '0'
                airtime = '0'

                # self.list = metacache.fetch(self.list, self.lang, self.user)
                # if self.list['metacache'] is True:
                # raise Exception()

                if (imdb == '0' or tmdb == '0') and tvdb != '0':
                    from resources.lib.modules import trakt
                    trakt_ids = trakt.IdLookup('tvdb', tvdb, 'show')
                    if trakt_ids:
                        if imdb == '0':
                            imdb = str(trakt_ids.get('imdb', '0'))
                            if not imdb or imdb == 'None': imdb = '0'
                        if tmdb == '0':
                            tmdb = str(trakt_ids.get('tmdb', '0'))
                            if not tmdb or tmdb == 'None': tmdb = '0'

                if tvdb == '0' and imdb != '0':  # Check TVDb by IMDB_ID for missing tvdb_id
                    try:
                        tvdb = cache.get(tvdb_v1.getSeries_ByIMDB, 96,
                                         tvshowtitle, year, imdb)
                    except:
                        tvdb = '0'

                if tvdb == '0':  # Check TVDb by seriesname for missing tvdb_id
                    try:
                        ids = cache.get(tvdb_v1.getSeries_ByName, 96,
                                        tvshowtitle, year)
                        if ids: tvdb = ids.get(tvdb, '0') or '0'
                    except:
                        tvdb = '0'
                        log_utils.error()

                if tvdb == '0': raise Exception()
                try:
                    url = self.tvdb_info_link % (tvdb, self.lang)
                    # item3 = requests.get(url).content ## maybe switch to client.request # test .content vs. .text
                    item3 = requests.get(url).text  # test .content vs. .text
                    # item3 = py_tools.six_decode(item3)
                except:
                    item3 = None

                if item3:
                    if poster == '0':
                        poster = client.parseDOM(item3, 'poster')[0]
                        poster = '%s%s' % (self.tvdb_image,
                                           poster) if poster else '0'

                    fanart = client.parseDOM(item3, 'fanart')[0]
                    fanart = '%s%s' % (self.tvdb_image,
                                       fanart) if fanart else '0'

                    banner = client.parseDOM(item3, 'banner')[0]
                    banner = '%s%s' % (self.tvdb_image,
                                       banner) if banner else '0'

                    mpaa = client.parseDOM(item3, 'ContentRating')[0] or '0'

                    if duration == '0':
                        duration = client.parseDOM(item3, 'Runtime')[0] or '0'

                    if rating == '0':
                        rating = client.parseDOM(item3, 'Rating')[0] or '0'
                    votes = client.parseDOM(item3, 'RatingCount')[0] or '0'

                    if status == '0':
                        status = client.parseDOM(item3, 'Status')[0] or '0'

                    if premiered == '0':
                        premiered = client.parseDOM(item3,
                                                    'FirstAired')[0] or '0'
                    if year == '0':
                        try:
                            year = re.compile(r'(\d{4})').findall(premiered)[0]
                        except:
                            year = '0'

                    if not plot:
                        plot = client.parseDOM(item3, 'Overview')[0] or '0'
                        plot = client.replaceHTMLCodes(plot)

                    airday = client.parseDOM(item3, 'Airs_DayOfWeek')[0] or '0'
                    airtime = client.parseDOM(item3, 'Airs_Time')[0] or '0'

                item = {}
                item = {
                    'content': content,
                    'tvshowtitle': tvshowtitle,
                    'title': title,
                    'originaltitle': title,
                    'year': year,
                    'premiered': premiered,
                    'studio': studio,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'castandart': castandart,
                    'plot': plot,
                    'tagline': '0',
                    'status': status,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'tmdb': tmdb,
                    'tvmaze': tvmaze,
                    'airday': airday,
                    'airtime': airtime,
                    'poster': poster,
                    'poster2': '0',
                    'banner': banner,
                    'banner2': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': fanart,
                    'metacache': False,
                    'next': next
                }

                meta = {}
                meta = {
                    'tmdb': tmdb,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'lang': self.lang,
                    'user': self.user,
                    'item': item
                }

                if self.disable_fanarttv != 'true':
                    from resources.lib.indexers import fanarttv
                    extended_art = cache.get(fanarttv.get_tvshow_art, 168,
                                             tvdb)
                    if extended_art:
                        item.update(extended_art)
                        meta.update(item)

                if (self.disable_fanarttv == 'true' and
                    (poster == '0' or fanart == '0')) or (
                        self.disable_fanarttv != 'true' and
                        ((poster == '0' and item.get('poster2') == '0') or
                         (fanart == '0' and item.get('fanart2') == '0'))):
                    from resources.lib.indexers.tmdb import TVshows
                    tmdb_art = TVshows().get_art(tmdb)
                    if tmdb_art:
                        item.update(tmdb_art)
                        if item.get('landscape', '0') == '0':
                            landscape = item.get('fanart3', '0')
                            item.update({'landscape': landscape})
                        meta.update(item)

                item = dict(
                    (k, v) for k, v in control.iteritems(item) if v != '0')
                self.list.append(item)

                if 'next' in meta.get('item'):
                    del meta['item']['next']

                self.meta.append(meta)
                metacache.insert(self.meta)
            except:
                log_utils.error()
Exemple #17
0
	def imdb_list(self, url):
		try:
			for i in re.findall('date\[(\d+)\]', url):
				url = url.replace('date[%s]' % i, (self.datetime - datetime.timedelta(days = int(i))).strftime('%Y-%m-%d'))

			def imdb_watchlist_id(url):
				return client.parseDOM(client.request(url), 'meta', ret='content', attrs = {'property': 'pageId'})[0]
			if url == self.imdbwatchlist_link:
				url = cache.get(imdb_watchlist_id, 8640, url)
				url = self.imdblist_link % url
			elif url == self.imdbwatchlist2_link:
				url = cache.get(imdb_watchlist_id, 8640, url)
				url = self.imdblist2_link % url
			result = client.request(url)
			result = result.replace('\n', ' ')
			result = result.decode('iso-8859-1').encode('utf-8')

			items = client.parseDOM(result, 'div', attrs = {'class': '.+? lister-item'}) + client.parseDOM(result, 'div', attrs = {'class': 'lister-item .+?'})
			items += client.parseDOM(result, 'div', attrs = {'class': 'list_item.+?'})
		except:
			return

		try:
			# HTML syntax error, " directly followed by attribute name. Insert space in between. parseDOM can otherwise not handle it.
			result = result.replace('"class="lister-page-next', '" class="lister-page-next')

			# next = client.parseDOM(result, 'a', ret='href', attrs = {'class': '.+?ister-page-nex.+?'})
			next = client.parseDOM(result, 'a', ret='href', attrs = {'class': 'lister-page-next.+?'})

			if len(next) == 0:
				next = client.parseDOM(result, 'div', attrs = {'class': 'pagination'})[0]
				next = zip(client.parseDOM(next, 'a', ret='href'), client.parseDOM(next, 'a'))
				next = [i[0] for i in next if 'Next' in i[1]]

			next = url.replace(urlparse(url).query, urlparse(next[0]).query)
			next = client.replaceHTMLCodes(next)
			next = next.encode('utf-8')
		except:
			next = ''

		for item in items:
			try:
				title = client.parseDOM(item, 'a')[1]
				title = client.replaceHTMLCodes(title)
				title = title.encode('utf-8')

				originaltitle = title

				year = client.parseDOM(item, 'span', attrs = {'class': 'lister-item-year.+?'})
				year = re.findall('(\d{4})', year[0])[0]
				year = year.encode('utf-8')

				try: show = '–'.decode('utf-8') in str(year).decode('utf-8') or '-'.decode('utf-8') in str(year).decode('utf-8')
				except: show = False
				if show: raise Exception() # Some lists contain TV shows.

				if int(year) > int((self.datetime).strftime('%Y')): raise Exception()

				try: mpaa = client.parseDOM(item, 'span', attrs = {'class': 'certificate'})[0]
				except: mpaa = '0'
				if mpaa == '' or mpaa == 'NOT_RATED': mpaa = '0'
				mpaa = mpaa.replace('_', '-')
				mpaa = client.replaceHTMLCodes(mpaa)
				mpaa = mpaa.encode('utf-8')

				imdb = client.parseDOM(item, 'a', ret='href')[0]
				imdb = re.findall('(tt\d*)', imdb)[0]
				imdb = imdb.encode('utf-8')

				# parseDOM cannot handle elements without a closing tag.
				# try: poster = client.parseDOM(item, 'img', ret='loadlate')[0]
				# except: poster = '0'
				try:
					from bs4 import BeautifulSoup
					html = BeautifulSoup(item, "html.parser")
					poster = html.find_all('img')[0]['loadlate']
				except:
					poster = '0'

				if '/nopicture/' in poster: poster = '0'
				poster = re.sub('(?:_SX|_SY|_UX|_UY|_CR|_AL)(?:\d+|_).+?\.', '_SX500.', poster)
				poster = client.replaceHTMLCodes(poster)
				poster = poster.encode('utf-8')

				try: genre = client.parseDOM(item, 'span', attrs = {'class': 'genre'})[0]
				except: genre = '0'
				genre = ' / '.join([i.strip() for i in genre.split(',')])
				if genre == '': genre = '0'
				genre = client.replaceHTMLCodes(genre)
				genre = genre.encode('utf-8')

				try: duration = re.findall('(\d+?) min(?:s|)', item)[-1]
				except: duration = '0'
				duration = duration.encode('utf-8')

				rating = '0'
				try: rating = client.parseDOM(item, 'span', attrs = {'class': 'rating-rating'})[0]
				except:
					try: rating = client.parseDOM(rating, 'span', attrs = {'class': 'value'})[0]
					except:
						try: rating = client.parseDOM(item, 'div', ret='data-value', attrs = {'class': '.*?imdb-rating'})[0]
						except: pass
				if rating == '' or rating == '-': rating = '0'
				if rating == '0':
					try:
						rating = client.parseDOM(item, 'span', attrs = {'class': 'ipl-rating-star__rating'})[0]
						if rating == '' or rating == '-': rating = '0'
					except: pass
				rating = client.replaceHTMLCodes(rating)
				rating = rating.encode('utf-8')

				votes = '0'
				try: votes = client.parseDOM(item, 'span', attrs = {'name': 'nv'})[0]
				except:
					try: votes = client.parseDOM(item, 'div', ret='title', attrs = {'class': '.*?rating-list'})[0]
					except:
						try: votes = re.findall('\((.+?) vote(?:s|)\)', votes)[0]
						except: pass
				if votes == '': votes = '0'
				votes = client.replaceHTMLCodes(votes)
				votes = votes.encode('utf-8')

				try: director = re.findall('Director(?:s|):(.+?)(?:\||</div>)', item)[0]
				except: director = '0'
				director = client.parseDOM(director, 'a')
				director = ' / '.join(director)
				if director == '': director = '0'
				director = client.replaceHTMLCodes(director)
				director = director.encode('utf-8')

				try: cast = re.findall('Stars(?:s|):(.+?)(?:\||</div>)', item)[0]
				except: cast = '0'
				cast = client.replaceHTMLCodes(cast)
				cast = cast.encode('utf-8')
				cast = client.parseDOM(cast, 'a')
				if cast == []: cast = '0'

				plot = '0'
				try: plot = client.parseDOM(item, 'p', attrs = {'class': 'text-muted'})[0]
				except:
					try: plot = client.parseDOM(item, 'div', attrs = {'class': 'item_description'})[0]
					except: pass
				plot = plot.rsplit('<span>', 1)[0].strip()
				plot = re.sub('<.+?>|</.+?>', '', plot)
				if plot == '': plot = '0'
				if plot == '0':
					try:
						plot = client.parseDOM(item, 'div', attrs = {'class': 'lister-item-content'})[0]
						plot = re.sub('<p\s*class="">', '<p class="plot_">', plot)
						plot = client.parseDOM(plot, 'p', attrs = {'class': 'plot_'})[0]
						plot = re.sub('<.+?>|</.+?>', '', plot)
						if plot == '': plot = '0'
					except: pass
				plot = client.replaceHTMLCodes(plot)
				plot = plot.encode('utf-8')

				tagline = '0'

				item = {}
				item = {'content': 'movie', 'title': title, 'originaltitle': originaltitle, 'year': year, 'premiered': premiered,
						'studio': '0', 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa,
						'director': director, 'writer': writer, 'cast': cast, 'plot': plot, 'tagline': tagline, 'code': tmdb,
						'imdb': imdb, 'tmdb': tmdb, 'tvdb': '0', 'poster': poster, 'poster2': '0', 'poster3': '0', 'banner': '0',
						'fanart': '0', 'fanart2': '0', 'fanart3': '0', 'clearlogo': '0', 'clearart': '0', 'landscape': '0',
						'metacache': False, 'next': next}
				meta = {}
				meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': '0', 'lang': self.lang, 'user': self.tmdb_key, 'item': item}

				if disable_fanarttv != 'true':
					from resources.lib.indexers import fanarttv
					extended_art = cache.get(fanarttv.get_movie_art, 168, imdb, tmdb)
					if extended_art:
						item.update(extended_art)
						meta.update(item)

				self.list.append(item)
				self.meta.append(meta)
				metacache.insert(self.meta)
			except:
				pass
		return self.list
Exemple #18
0
    def tmdb_collections_list(self, url):
        try:
            result = self.get_request(url)
            items = result['items']
        except:
            return
        next = ''
        for item in items:
            try:
                media_type = item['media_type']

                title = (item.get('title')).encode('utf-8')
                if not media_type == 'movie':
                    title = (item.get('name')).encode('utf-8')

                try:
                    originaltitle = (
                        item.get('original_title')).encode('utf-8')
                except:
                    originaltitle = title

                year = item['release_date']
                year = re.compile('(\d{4})').findall(year)[0]
                year = year.encode('utf-8')

                tmdb = item['id']
                tmdb = re.sub('[^0-9]', '', str(tmdb))
                tmdb = tmdb.encode('utf-8')

                poster = item.get('poster_path')
                if not poster == '' and not poster is None:
                    poster = ('%s%s' %
                              (self.tmdb_poster, poster)).encode('utf-8')
                else:
                    poster = '0'

                fanart = item.get('backdrop_path')
                if not fanart == '' and not fanart is None:
                    fanart = ('%s%s' %
                              (self.tmdb_fanart, fanart)).encode('utf-8')
                else:
                    fanart = '0'

                premiered = item['release_date']
                try:
                    premiered = re.compile('(\d{4}-\d{2}-\d{2})').findall(
                        premiered)[0]
                except:
                    premiered = '0'
                premiered = premiered.encode('utf-8')

                try:
                    rating = str(item['vote_average']).encode('utf-8')
                except:
                    rating = '0'

                try:
                    votes = str(format(int(item['vote_count']),
                                       ',d')).encode('utf-8')
                except:
                    votes = '0'

                plot = (item.get('overview')).encode('utf-8')

                try:
                    tagline = item['tagline']
                    if tagline == '' or tagline == '0' or tagline is None:
                        tagline = re.compile('[.!?][\s]{1,2}(?=[A-Z])').split(
                            plot)[0]
                    tagline = tagline.encode('utf-8')
                except:
                    tagline = '0'

                ##--TMDb additional info
                url = self.tmdb_info_link % tmdb
                item = self.get_request(url)

                imdb = item['external_ids']['imdb_id']
                if imdb == '' or imdb is None: imdb = '0'
                imdb = imdb.encode('utf-8')

                # studio = item['production_companies']
                # try: studio = [x['name'] for x in studio][0]
                # except: studio = '0'
                # if studio == '' or studio is None: studio = '0'
                # studio = studio.encode('utf-8')

                genre = item['genres']
                try:
                    genre = [x['name'] for x in genre]
                except:
                    genre = '0'
                genre = ' / '.join(genre)
                genre = genre.encode('utf-8')
                if not genre: genre = 'NA'

                try:
                    duration = str(item['runtime'])
                except:
                    duration = '0'
                if duration == '' or duration is None or duration == 'N/A':
                    duration = '0'
                duration = duration.encode('utf-8')

                mpaa = item['release_dates']['results']
                mpaa = [i for i in mpaa if i['iso_3166_1'] == 'US']
                try:
                    mpaa = mpaa[0].get('release_dates')[-1].get(
                        'certification')
                    if not mpaa:
                        mpaa = mpaa[0].get('release_dates')[0].get(
                            'certification')
                        if not mpaa:
                            mpaa = mpaa[0].get('release_dates')[1].get(
                                'certification')
                    mpaa = str(mpaa).encode('utf-8')
                except:
                    mpaa = '0'

                director = item['credits']['crew']
                try:
                    director = [
                        x['name'] for x in director
                        if x['job'].encode('utf-8') == 'Director'
                    ]
                except:
                    director = '0'
                if director == '' or director is None or director == []:
                    director = '0'
                director = ' / '.join(director)
                director = director.encode('utf-8')

                writer = item['credits']['crew']
                try:
                    writer = [
                        x['name'] for x in writer if x['job'].encode('utf-8')
                        in ['Writer', 'Screenplay']
                    ]
                except:
                    writer = '0'
                try:
                    writer = [
                        x for n, x in enumerate(writer) if x not in writer[:n]
                    ]
                except:
                    writer = '0'
                if writer == '' or writer is None or writer == []:
                    writer = '0'
                writer = ' / '.join(writer)
                writer = writer.encode('utf-8')

                cast = item['credits']['cast']
                try:
                    cast = [(x['name'].encode('utf-8'),
                             x['character'].encode('utf-8')) for x in cast]
                except:
                    cast = []

                item = {}
                item = {
                    'content': 'movie',
                    'title': title,
                    'originaltitle': originaltitle,
                    'year': year,
                    'premiered': premiered,
                    'studio': '0',
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'director': director,
                    'writer': writer,
                    'cast': cast,
                    'plot': plot,
                    'tagline': tagline,
                    'code': tmdb,
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'poster': poster,
                    'poster2': '0',
                    'poster3': '0',
                    'banner': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'fanart3': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': '0',
                    'metacache': False,
                    'next': next
                }
                meta = {}
                meta = {
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'lang': self.lang,
                    'user': self.tmdb_key,
                    'item': item
                }

                # fanart_thread = threading.Thread
                if not self.disable_fanarttv == 'true':
                    from resources.lib.indexers import fanarttv
                    extended_art = fanarttv.get_movie_art(imdb, tmdb)
                    if not extended_art is None:
                        item.update(extended_art)
                        meta.update(item)

                self.list.append(item)
                self.meta.append(meta)
                metacache.insert(self.meta)

            except:
                pass
        return self.list
Exemple #19
0
        def items_list(i):
            try:
                url = self.tvmaze_info_link % i
                item = client.request(url, timeout='20', error=True)
                item = json.loads(item)

                content = item.get('type', '0').lower()

                try:
                    title = (item.get('name')).encode('utf-8')
                except:
                    title = item.get('name')

                premiered = item.get('premiered', '0')

                year = str(item.get('premiered', '0'))
                year = re.search(r"(\d{4})", year).group(1)

                imdb = item.get('externals').get('imdb', '0')
                if imdb == '' or imdb is None or imdb == 'None':
                    imdb = '0'

                tvdb = str(item.get('externals').get('thetvdb', '0'))
                if tvdb == '' or tvdb is None or tvdb == 'None':
                    tvdb = '0'

                # TVMaze does not have tmdb in api
                tmdb = '0'

                studio = item.get('network', {}) or item.get('webChannel', {})
                studio = studio.get('name', '0')

                genre = []
                for i in item['genres']:
                    genre.append(i.title())
                if genre == []: genre = 'NA'

                duration = str(item.get('runtime', '0'))

                rating = str(item.get('rating').get('average', '0'))

                plot = item.get('summary', '0')
                plot = re.sub('<.+?>|</.+?>|\n', '', plot)

                status = item.get('status', '0')

                castandart = []
                for person in item['_embedded']['cast']:
                    try:
                        try:
                            castandart.append({
                                'name':
                                person['person']['name'].encode('utf-8'),
                                'role':
                                person['character']['name'].encode('utf-8'),
                                'thumbnail':
                                (person['person']['image']['original']
                                 if person['person']['image']['original']
                                 is not None else '0')
                            })
                        except:
                            castandart.append({
                                'name':
                                person['person']['name'],
                                'role':
                                person['character']['name'],
                                'thumbnail':
                                (person['person']['image']['medium']
                                 if person['person']['image']['medium']
                                 is not None else '0')
                            })
                    except:
                        castandart = []
                        pass
                    if len(castandart) == 200: break

                poster = item.get('image').get('original')
                fanart = '0'
                banner = '0'
                mpaa = '0'
                votes = '0'

                ###--Check TVDb for missing info
                # self.list = metacache.fetch(self.list, self.lang, self.user)
                # if self.list['metacache'] is True:
                # raise Exception()
                if tvdb == '0' and imdb != '0':
                    url = self.tvdb_by_imdb % imdb
                    result = client.request(url)
                    try:
                        tvdb = client.parseDOM(result, 'seriesid')[0]
                    except:
                        tvdb = '0'

                if tvdb == '0' or imdb == '0':
                    url = self.tvdb_by_query % (urllib.quote_plus(title))
                    item2 = client.request(url, timeout='20', error=True)
                    item2 = re.sub(r'[^\x00-\x7F]+', '', item2)
                    item2 = client.replaceHTMLCodes(item2)
                    item2 = client.parseDOM(item2, 'Series')

                    if tvdb == '0':
                        tvdb = client.parseDOM(item2, 'seriesid')[0] or '0'

                    if imdb == '0':
                        imdb = client.parseDOM(item2, 'IMDB_ID')[0] or '0'

                try:
                    if self.tvdb_key == '' or tvdb == '0':
                        raise Exception()
                    url = self.tvdb_info_link % (tvdb, self.lang)
                    item3 = client.request(url, timeout='20', error=True)
                except:
                    item3 = None

                if item3 is not None:
                    if poster == '0':
                        poster = client.parseDOM(item3, 'poster')[0]
                        if poster != '' or poster is not None:
                            poster = self.tvdb_image + poster

                    fanart = client.parseDOM(item3, 'fanart')[0]
                    if fanart != '' or fanart is not None:
                        fanart = self.tvdb_image + fanart

                    banner = client.parseDOM(item3, 'banner')[0]
                    if banner != '' or banner is not None:
                        banner = self.tvdb_image + banner

                    mpaa = client.parseDOM(item3, 'ContentRating')[0] or '0'

                    if duration == '0':
                        duration = client.parseDOM(item3, 'Runtime')[0] or '0'

                    if rating == '0':
                        rating = client.parseDOM(item3, 'Rating')[0] or '0'

                    votes = client.parseDOM(item3, 'RatingCount')[0] or '0'

                    if status == '0':
                        status = client.parseDOM(item3, 'Status')[0] or '0'

                    if year == '0':
                        year = client.parseDOM(item3, 'FirstAired')[0]
                        year = re.compile('(\d{4})').findall(year)[0] or '0'

                    if plot == '0':
                        plot = client.parseDOM(item3, 'Overview')[0] or '0'
                        plot = client.replaceHTMLCodes(plot)
                        try:
                            plot = plot.encode('utf-8')
                        except:
                            pass

                    airday = client.parseDOM(item3, 'Airs_DayOfWeek')[0] or '0'
                    airtime = client.parseDOM(item3, 'Airs_Time')[0] or '0'
###-----

                item = {}
                item = {
                    'content': content,
                    'title': title,
                    'originaltitle': title,
                    'year': year,
                    'premiered': premiered,
                    'studio': studio,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'castandart': castandart,
                    'plot': plot,
                    'tagline': '0',
                    'status': status,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'tmdb': tmdb,
                    'airday': airday,
                    'airtime': airtime,
                    'poster': poster,
                    'poster2': '0',
                    'banner': banner,
                    'banner2': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': fanart,
                    'metacache': False,
                    'next': next
                }

                meta = {}
                meta = {
                    'tmdb': tmdb,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'lang': self.lang,
                    'user': self.user,
                    'item': item
                }

                if self.disable_fanarttv != 'true':
                    from resources.lib.indexers import fanarttv
                    extended_art = cache.get(fanarttv.get_tvshow_art, 168,
                                             tvdb)
                    if extended_art is not None:
                        item.update(extended_art)
                        meta.update(item)

                item = dict((k, v) for k, v in item.iteritems() if v != '0')
                self.list.append(item)

                if 'next' in meta.get('item'):
                    del meta['item']['next']

                self.meta.append(meta)
                metacache.insert(self.meta)
            except:
                log_utils.error()
                pass
    def tmdb_list(self, url):
        next = url
        try:
            result = self.get_request(url % self.tmdb_key)
            items = result['results']
        except:
            return

        # try:
        # page = int(result['page'])
        # total = int(result['total_pages'])
        # if page >= total: raise Exception()
        # url2 = '%s&page=%s' % (url.split('&page=', 1)[0], str(page+1))
        # result = self.get_request(url2 % self.tmdb_key)
        # # result = client.request(url2 % self.tmdb_key)
        # # result = json.loads(result)
        # items += result['results']
        # except: pass
        try:
            page = int(result['page'])
            total = int(result['total_pages'])
            if page >= total: raise Exception()
            if not 'page=' in url: raise Exception()
            next = '%s&page=%s' % (next.split('&page=', 1)[0], str(page + 1))
            next = next.encode('utf-8')
        except:
            next = ''

        for item in items:
            try:
                title = item['title']
                title = client.replaceHTMLCodes(title)
                title = title.encode('utf-8')

                try:
                    originaltitle = item['original_title']
                    originaltitle = client.replaceHTMLCodes(title)
                    originaltitle = title.encode('utf-8')
                except:
                    originaltitle = title

                year = item['release_date']
                year = re.compile('(\d{4})').findall(year)[-1]
                year = year.encode('utf-8')

                tmdb = item['id']
                tmdb = re.sub('[^0-9]', '', str(tmdb))
                tmdb = tmdb.encode('utf-8')

                # try:
                # meta_chk = []
                # meta_chk.append({'tmdb': tmdb, 'imdb': '0', 'tvdb': '0'})
                # meta_chk = metacache.fetch(meta_chk, self.lang, self.tmdb_key)
                # log_utils.log('meta_chk = %s' % str(meta_chk), __name__, log_utils.LOGDEBUG)

                # for i in meta_chk:
                # if 'metacache' in i:
                # if i['metacache'] is True:
                # item = meta_chk
                # log_utils.log('metacache = %s' % i['metacache'], __name__, log_utils.LOGDEBUG)
                # raise Exception()

                poster = item['poster_path']
                if poster == '' or poster is None:
                    poster = '0'
                if not poster == '0':
                    poster = '%s%s' % (self.tmdb_poster, poster)
                poster = poster.encode('utf-8')

                fanart = item['backdrop_path']
                if fanart == '' or fanart is None:
                    fanart = '0'
                if not fanart == '0':
                    fanart = '%s%s' % (self.tmdb_image, fanart)
                fanart = fanart.encode('utf-8')

                premiered = item['release_date']
                try:
                    premiered = re.compile('(\d{4}-\d{2}-\d{2})').findall(
                        premiered)[0]
                except:
                    premiered = '0'
                premiered = premiered.encode('utf-8')

                try:
                    rating = str(item['vote_average']).encode('utf-8')
                except:
                    rating = '0'

                try:
                    votes = str(format(int(item['vote_count']),
                                       ',d')).encode('utf-8')
                except:
                    votes = '0'

                plot = item['overview']
                if plot == '' or plot is None:
                    plot = '0'
                plot = client.replaceHTMLCodes(plot)
                plot = plot.encode('utf-8')

                try:
                    tagline = item['tagline']
                    tagline = re.compile('[.!?][\s]{1,2}(?=[A-Z])').split(
                        plot)[0]
                    tagline = tagline.encode('utf-8')
                except:
                    tagline = '0'


##--TMDb additional info
                url = self.tmdb_info_link % tmdb
                item = self.get_request(url)

                imdb = item['external_ids']['imdb_id']
                if imdb == '' or imdb is None: imdb = '0'
                imdb = imdb.encode('utf-8')

                # studio = item['production_companies']
                # try: studio = [x['name'] for x in studio][0]
                # except: studio = '0'
                # if studio == '' or studio is None: studio = '0'
                # studio = studio.encode('utf-8')

                try:
                    genre = item['genres']
                    genre = [x['name'] for x in genre]
                    genre = (' / '.join(genre)).encode('utf-8')
                except:
                    genre = 'NA'

                try:
                    duration = (str(item['runtime'])).encode('utf-8')
                except:
                    duration = '0'

                mpaa = item['release_dates']['results']
                mpaa = [i for i in mpaa if i['iso_3166_1'] == 'US']
                try:
                    mpaa = mpaa[0].get('release_dates')[-1].get(
                        'certification')
                    if not mpaa:
                        mpaa = mpaa[0].get('release_dates')[0].get(
                            'certification')
                        if not mpaa:
                            mpaa = mpaa[0].get('release_dates')[1].get(
                                'certification')
                    mpaa = str(mpaa).encode('utf-8')
                except:
                    mpaa = '0'

                director = item['credits']['crew']
                try:
                    director = [
                        x['name'] for x in director
                        if x['job'].encode('utf-8') == 'Director'
                    ]
                except:
                    director = '0'
                if director == '' or director is None or director == []:
                    director = '0'
                director = (' / '.join(director)).encode('utf-8')

                writer = item['credits']['crew']
                try:
                    writer = [
                        x['name'] for x in writer if x['job'].encode('utf-8')
                        in ['Writer', 'Screenplay']
                    ]
                except:
                    writer = '0'
                try:
                    writer = [
                        x for n, x in enumerate(writer) if x not in writer[:n]
                    ]
                except:
                    writer = '0'
                if writer == '' or writer is None or writer == []: writer = '0'
                writer = (' / '.join(writer)).encode('utf-8')

                cast = item['credits']['cast']
                try:
                    cast = [(x['name'].encode('utf-8'),
                             x['character'].encode('utf-8')) for x in cast]
                except:
                    cast = []

                try:
                    if not imdb is None or not imdb == '0':
                        url = self.imdbinfo % imdb
                        item = client.request(url, timeout='30')
                        item = json.loads(item)

                        plot2 = item['Plot']
                        plot2 = client.replaceHTMLCodes(plot2)
                        plot2 = plot.encode('utf-8')
                        if plot == '0' or plot == '' or plot is None:
                            plot = plot2

                        rating2 = str(item['imdbRating'])
                        rating2 = rating2.encode('utf-8')
                        if rating == '0' or rating == '' or rating is None:
                            rating = rating2

                        votes2 = str(item['imdbVotes'])
                        votes2 = str(format(int(votes2), ',d'))
                        votes2 = votes2.encode('utf-8')
                        if votes == '0' or votes == '' or votes is None:
                            votes = votes2
                except:
                    pass

                item = {}
                item = {
                    'content': 'movie',
                    'title': title,
                    'originaltitle': originaltitle,
                    'year': year,
                    'premiered': premiered,
                    'studio': '0',
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'director': director,
                    'writer': writer,
                    'cast': cast,
                    'plot': plot,
                    'tagline': tagline,
                    'code': tmdb,
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'poster': poster,
                    'poster2': '0',
                    'poster3': '0',
                    'banner': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'fanart3': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': '0',
                    'metacache': False,
                    'next': next
                }
                meta = {}
                meta = {
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'lang': self.lang,
                    'user': self.tmdb_key,
                    'item': item
                }

                # fanart_thread = threading.Thread
                from resources.lib.indexers import fanarttv
                extended_art = fanarttv.get_movie_art(tmdb)
                if not extended_art is None:
                    item.update(extended_art)
                    meta.update(item)

                self.list.append(item)
                self.meta.append(meta)
                metacache.insert(self.meta)
                # log_utils.log('self.list = %s' % str(self.list), __name__, log_utils.LOGDEBUG)
            except:
                pass
        return self.list
        def items_list(i):
            # if i['metacache']:
            # return
            try:
                tvmaze = i
                url = self.tvmaze_info_link % i
                item = requests.get(url, timeout=10).json()

                content = item.get('type', '0').lower()

                try:
                    title = (item.get('name')).encode('utf-8')
                except:
                    title = item.get('name')

                premiered = item.get('premiered', '0')

                year = str(item.get('premiered', '0'))
                if year is not None and year != 'None' and year != '0':
                    year = re.search(r"(\d{4})", year).group(1)
                else:
                    year = '0'

                imdb = item.get('externals').get('imdb', '0')
                if imdb == '' or imdb is None or imdb == 'None':
                    imdb = '0'

                tvdb = str(item.get('externals').get('thetvdb', '0'))
                if tvdb == '' or tvdb is None or tvdb == 'None':
                    tvdb = '0'

                # TVMaze does not have tmdb_id in api
                tmdb = '0'

                studio = item.get('network', {}) or item.get('webChannel', {})
                studio = studio.get('name', '0')

                genre = []
                for i in item['genres']:
                    genre.append(i.title())
                if genre == []: genre = 'NA'

                duration = str(item.get('runtime', '0'))

                rating = str(item.get('rating').get('average', '0'))

                plot = item.get('summary', '0')
                if plot:
                    plot = re.sub('<.+?>|</.+?>|\n', '', plot)

                status = item.get('status', '0')

                castandart = []
                for person in item['_embedded']['cast']:
                    try:
                        try:
                            castandart.append({
                                'name':
                                person['person']['name'].encode('utf-8'),
                                'role':
                                person['character']['name'].encode('utf-8'),
                                'thumbnail':
                                (person['person']['image']['original']
                                 if person['person']['image']['original']
                                 is not None else '0')
                            })
                        except:
                            castandart.append({
                                'name':
                                person['person']['name'],
                                'role':
                                person['character']['name'],
                                'thumbnail':
                                (person['person']['image']['medium']
                                 if person['person']['image']['medium']
                                 is not None else '0')
                            })
                    except:
                        castandart = []
                        pass
                    if len(castandart) == 150: break

                image = item.get('image')
                poster = image.get('original',
                                   '0') if image is not None else '0'
                fanart = '0'
                banner = '0'
                mpaa = '0'
                votes = '0'
                airday = '0'
                airtime = '0'

                # self.list = metacache.fetch(self.list, self.lang, self.user)
                # if self.list['metacache'] is True:
                # raise Exception()

                if (imdb == '0' or tmdb == '0') and tvdb != '0':
                    from resources.lib.modules import trakt
                    trakt_ids = trakt.IdLookup('tvdb', tvdb, 'show')
                    if trakt_ids:
                        if imdb == '0':
                            imdb = str(trakt_ids.get('imdb', '0'))
                            if imdb == '' or imdb is None or imdb == 'None':
                                imdb = '0'
                        if tmdb == '0':
                            tmdb = str(trakt_ids.get('tmdb', '0'))
                            if tmdb == '' or tmdb is None or tmdb == 'None':
                                tmdb = '0'

###--Check TVDb by IMDB_ID for missing ID's
                if tvdb == '0' and imdb != '0':
                    try:
                        url = self.tvdb_by_imdb % imdb
                        result = requests.get(url).content
                        result = re.sub(r'[^\x00-\x7F]+', '', result)
                        result = client.replaceHTMLCodes(result)
                        result = client.parseDOM(result, 'Series')
                        result = [(client.parseDOM(x, 'SeriesName'),
                                   client.parseDOM(x, 'FirstAired'),
                                   client.parseDOM(x, 'seriesid'),
                                   client.parseDOM(x, 'AliasNames'))
                                  for x in result]
                        years = [
                            str(year),
                            str(int(year) + 1),
                            str(int(year) - 1)
                        ]
                        item = [(x[0], x[1], x[2], x[3]) for x in result
                                if cleantitle.get(title) == cleantitle.get(
                                    str(x[0][0])) and any(y in str(x[1][0])
                                                          for y in years)]
                        if item == []:
                            item = [(x[0], x[1], x[2], x[3]) for x in result
                                    if cleantitle.get(title) == cleantitle.get(
                                        str(x[3][0]))]
                        if item == []:
                            item = [(x[0], x[1], x[2], x[3]) for x in result
                                    if cleantitle.get(title) == cleantitle.get(
                                        str(x[0][0]))]
                        if item == []:
                            raise Exception()
                        tvdb = item[0][2]
                        tvdb = tvdb[0] or '0'
                    except:
                        log_utils.error()
                        pass

###--Check TVDb by seriesname
                if tvdb == '0' or imdb == '0':
                    try:
                        url = self.tvdb_by_query % (quote_plus(title))
                        result = requests.get(url).content
                        result = re.sub(r'[^\x00-\x7F]+', '', result)
                        result = client.replaceHTMLCodes(result)
                        result = client.parseDOM(result, 'Series')
                        result = [(client.parseDOM(x, 'SeriesName'),
                                   client.parseDOM(x, 'FirstAired'),
                                   client.parseDOM(x, 'seriesid'),
                                   client.parseDOM(x, 'IMDB_ID'),
                                   client.parseDOM(x, 'AliasNames'))
                                  for x in result]
                        years = [
                            str(year),
                            str(int(year) + 1),
                            str(int(year) - 1)
                        ]
                        item = [(x[0], x[1], x[2], x[3], x[4]) for x in result
                                if cleantitle.get(title) == cleantitle.get(
                                    str(x[0][0])) and any(y in str(x[1][0])
                                                          for y in years)]
                        if item == []:
                            item = [(x[0], x[1], x[2], x[3], x[4])
                                    for x in result
                                    if cleantitle.get(title) == cleantitle.get(
                                        str(x[4][0]))]
                        if item == []:
                            item = [(x[0], x[1], x[2], x[3], x[4])
                                    for x in result
                                    if cleantitle.get(title) == cleantitle.get(
                                        str(x[0][0]))]
                        if item == []:
                            raise Exception()
                        if tvdb == '0':
                            tvdb = item[0][2]
                            tvdb = tvdb[0] or '0'
                        if imdb == '0':
                            imdb = item[0][3]
                            imdb = imdb[0] or '0'
                    except:
                        log_utils.error()
                        pass
#################################

                if tvdb == '0':
                    raise Exception()

                try:
                    url = self.tvdb_info_link % (tvdb, self.lang)
                    item3 = requests.get(url).content
                except:
                    item3 = None

                if item3:
                    if poster == '0':
                        poster = client.parseDOM(item3, 'poster')[0]
                        poster = '%s%s' % (self.tvdb_image,
                                           poster) if poster else '0'

                    fanart = client.parseDOM(item3, 'fanart')[0]
                    fanart = '%s%s' % (self.tvdb_image,
                                       fanart) if fanart else '0'

                    banner = client.parseDOM(item3, 'banner')[0]
                    banner = '%s%s' % (self.tvdb_image,
                                       banner) if banner else '0'

                    mpaa = client.parseDOM(item3, 'ContentRating')[0] or '0'

                    if duration == '0':
                        duration = client.parseDOM(item3, 'Runtime')[0] or '0'

                    if rating == '0':
                        rating = client.parseDOM(item3, 'Rating')[0] or '0'

                    votes = client.parseDOM(item3, 'RatingCount')[0] or '0'

                    if status == '0':
                        status = client.parseDOM(item3, 'Status')[0] or '0'

                    if year == '0':
                        year = client.parseDOM(item3, 'FirstAired')[0] or '0'
                        if year != '0':
                            year = re.compile('(\d{4})').findall(
                                year)[0] or '0'

                    if not plot:
                        plot = client.parseDOM(item3, 'Overview')[0] or '0'
                        plot = client.replaceHTMLCodes(plot)
                        try:
                            plot = plot.encode('utf-8')
                        except:
                            pass

                    airday = client.parseDOM(item3, 'Airs_DayOfWeek')[0] or '0'
                    # log_utils.log('airday = %s' % str(airday), __name__, log_utils.LOGDEBUG)
                    airtime = client.parseDOM(item3, 'Airs_Time')[0] or '0'

                item = {}
                item = {
                    'content': content,
                    'title': title,
                    'originaltitle': title,
                    'year': year,
                    'premiered': premiered,
                    'studio': studio,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'castandart': castandart,
                    'plot': plot,
                    'tagline': '0',
                    'status': status,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'tmdb': tmdb,
                    'tvmaze': tvmaze,
                    'airday': airday,
                    'airtime': airtime,
                    'poster': poster,
                    'poster2': '0',
                    'banner': banner,
                    'banner2': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': fanart,
                    'metacache': False,
                    'next': next
                }

                meta = {}
                meta = {
                    'tmdb': tmdb,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'lang': self.lang,
                    'user': self.user,
                    'item': item
                }

                if self.disable_fanarttv != 'true':
                    from resources.lib.indexers import fanarttv
                    extended_art = cache.get(fanarttv.get_tvshow_art, 168,
                                             tvdb)
                    if extended_art:
                        item.update(extended_art)
                        meta.update(item)

                if (self.disable_fanarttv == 'true' and
                    (poster == '0' or fanart == '0')) or (
                        self.disable_fanarttv != 'true' and
                        ((poster == '0' and item.get('poster2') == '0') or
                         (fanart == '0' and item.get('fanart2') == '0'))):
                    from resources.lib.indexers.tmdb import TVshows
                    tmdb_art = TVshows().get_art(tmdb)
                    # log_utils.log('tmdb_art = %s' % tmdb_art, __name__, log_utils.LOGDEBUG)
                    if tmdb_art:
                        item.update(tmdb_art)
                        if item.get('landscape', '0') == '0':
                            landscape = item.get('fanart3', '0')
                            item.update({'landscape': landscape})
                        meta.update(item)

                item = dict((k, v) for k, v in item.iteritems() if v != '0')
                self.list.append(item)

                if 'next' in meta.get('item'):
                    del meta['item']['next']

                self.meta.append(meta)
                metacache.insert(self.meta)
            except:
                log_utils.error()
                pass
    def tmdb_list(self, url):
        next = url
        try:
            result = self.get_request(url % self.tmdb_key)
            items = result['results']
        except:
            return

        # try:
        # page = int(result['page'])
        # total = int(result['total_pages'])
        # if page >= total: raise Exception()
        # url2 = '%s&page=%s' % (url.split('&page=', 1)[0], str(page+1))
        # result = self.get_request(url2 % self.tmdb_key)
        # # result = client.request(url2 % self.tmdb_key)
        # # result = json.loads(result)
        # items += result['results']
        # except: pass
        try:
            page = int(result['page'])
            total = int(result['total_pages'])
            if page >= total: raise Exception()
            if not 'page=' in url: raise Exception()
            next = '%s&page=%s' % (next.split('&page=', 1)[0], str(page + 1))
            next = next.encode('utf-8')
        except:
            next = ''

        for item in items:
            try:
                title = item['name']
                title = client.replaceHTMLCodes(title)
                title = title.encode('utf-8')

                year = item['first_air_date']
                year = re.compile('(\d{4})').findall(year)[-1]
                year = year.encode('utf-8')

                tmdb = item['id']
                tmdb = re.sub('[^0-9]', '', str(tmdb))
                tmdb = tmdb.encode('utf-8')

                poster = item['poster_path']
                if poster == '' or poster is None: poster = '0'
                if not poster == '0':
                    poster = '%s%s' % (self.tmdb_poster, poster)
                poster = poster.encode('utf-8')

                fanart = item['backdrop_path']
                if fanart == '' or fanart is None: fanart = '0'
                if not fanart == '0':
                    fanart = '%s%s' % (self.tmdb_image, fanart)
                fanart = fanart.encode('utf-8')

                # bannner = item['banner_path']
                # if banner == '' or banner is None: banner = '0'
                # if not banner == '0': banner = self.tmdb_image + banner
                # banner = banner.encode('utf-8')

                premiered = item['first_air_date']
                try:
                    premiered = re.compile('(\d{4}-\d{2}-\d{2})').findall(
                        premiered)[0]
                except:
                    premiered = '0'
                premiered = premiered.encode('utf-8')

                rating = str(item['vote_average'])
                if rating == '' or rating is None: rating = '0'
                rating = rating.encode('utf-8')

                votes = str(item['vote_count'])
                try:
                    votes = str(format(int(votes), ',d'))
                except:
                    pass
                if votes == '' or votes is None: votes = '0'
                votes = votes.encode('utf-8')

                plot = item['overview']
                if plot == '' or plot is None: plot = '0'
                plot = client.replaceHTMLCodes(plot)
                plot = plot.encode('utf-8')

                tagline = re.compile('[.!?][\s]{1,2}(?=[A-Z])').split(plot)[0]
                try:
                    tagline = tagline.encode('utf-8')
                except:
                    tagline = 'NA'

                ##--TMDb additional info
                url = self.tmdb_info_link % tmdb
                item = self.get_request(url)

                tvdb = item['external_ids']['tvdb_id']
                if tvdb == '' or tvdb is None or tvdb == 'N/A' or tvdb == 'NA':
                    tvdb = '0'
                tvdb = re.sub('[^0-9]', '', str(tvdb))
                tvdb = tvdb.encode('utf-8')

                imdb = item['external_ids']['imdb_id']
                if imdb == '' or imdb is None or imdb == 'N/A' or imdb == 'NA':
                    imdb = '0'
                imdb = imdb.encode('utf-8')

                genre = item['genres']
                try:
                    genre = [x['name'] for x in genre]
                except:
                    genre = '0'
                genre = ' / '.join(genre)
                genre = genre.encode('utf-8')
                if not genre: genre = 'NA'

                duration = str(item['episode_run_time'][0])
                try:
                    duration = duration.strip("[]")
                except:
                    duration = '0'
                duration = duration.encode('utf-8')

                try:
                    mpaa = [
                        i['rating'] for i in item['content_ratings']['results']
                        if i['iso_3166_1'] == 'US'
                    ][0]
                except:
                    try:
                        mpaa = item['content_ratings'][0]['rating']
                    except:
                        mpaa = 'NR'

                studio = item['networks']
                try:
                    studio = [x['name'] for x in studio][0]
                except:
                    studio = '0'
                if studio == '' or studio is None: studio = '0'
                studio = studio.encode('utf-8')

                director = item['credits']['crew']
                try:
                    director = [
                        x['name'] for x in director
                        if x['job'].encode('utf-8') == 'Director'
                    ]
                except:
                    director = '0'
                if director == '' or director is None or director == []:
                    director = '0'
                director = ' / '.join(director)
                director = director.encode('utf-8')

                cast = item['credits']['cast']
                try:
                    cast = [(x['name'].encode('utf-8'),
                             x['character'].encode('utf-8')) for x in cast]
                except:
                    cast = []

                # ##--IMDb additional info
                if not imdb == '0' or None:
                    try:
                        url = self.imdb_by_query % imdb
                        item2 = client.request(url, timeout='30')
                        item2 = json.loads(item2)
                    except:
                        Exception()

                    try:
                        mpaa2 = item2['Rated']
                    except:
                        mpaa2 = 'NR'
                    mpaa2 = mpaa.encode('utf-8')
                    if mpaa == '0' or mpaa == 'NR' and not mpaa2 == 'NR':
                        mpaa = mpaa2

                    try:
                        writer = item2['Writer']
                    except:
                        writer = 'NA'
                    writer = writer.replace(', ', ' / ')
                    writer = re.sub(r'\(.*?\)', '', writer)
                    writer = ' '.join(writer.split())
                    writer = writer.encode('utf-8')

                item = {}
                item = {
                    'content': 'tvshow',
                    'title': title,
                    'originaltitle': title,
                    'year': year,
                    'premiered': premiered,
                    'studio': studio,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'director': director,
                    'writer': writer,
                    'cast': cast,
                    'plot': plot,
                    'tagline': tagline,
                    'code': tmdb,
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': tvdb,
                    'poster': poster,
                    'poster2': '0',
                    'banner': '0',
                    'banner2': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': '0',
                    'metacache': False,
                    'next': next
                }

                meta = {}
                meta = {
                    'tmdb': tmdb,
                    'imdb': imdb,
                    'tvdb': tvdb,
                    'lang': self.lang,
                    'user': self.tmdb_key,
                    'item': item
                }

                # fanart_thread = threading.Thread
                from resources.lib.indexers import fanarttv
                extended_art = fanarttv.get_tvshow_art(tvdb)
                if not extended_art is None:
                    item.update(extended_art)
                    meta.update(item)

                self.list.append(item)
                self.meta.append(meta)
                metacache.insert(self.meta)

            except:
                pass
        return self.list
    def tmdb_collections_list(self, url):
        result = self.get_request(url)
        items = result['items']
        next = ''
        for item in items:
            try:
                title = item['name']
                title = client.replaceHTMLCodes(title)
                title = title.encode('utf-8')

                year = item['first_air_date']
                year = re.compile('(\d{4})').findall(year)[-1]
                year = year.encode('utf-8')

                tmdb = item['id']
                if tmdb == '' or tmdb is None: tmdb = '0'
                tmdb = re.sub('[^0-9]', '', str(tmdb))
                tmdb = tmdb.encode('utf-8')

                imdb = '0'
                tvdb = '0'

                poster = item['poster_path']
                if poster == '' or poster is None: poster = '0'
                else: poster = self.tmdb_poster + poster
                poster = poster.encode('utf-8')

                fanart = item['backdrop_path']
                if fanart == '' or fanart is None: fanart = '0'
                if not fanart == '0':
                    fanart = '%s%s' % (self.tmdb_image, fanart)
                fanart = fanart.encode('utf-8')

                premiered = item['first_air_date']
                try:
                    premiered = re.compile('(\d{4}-\d{2}-\d{2})').findall(
                        premiered)[0]
                except:
                    premiered = '0'
                premiered = premiered.encode('utf-8')

                rating = str(item['vote_average'])
                if rating == '' or rating is None: rating = '0'
                rating = rating.encode('utf-8')

                votes = str(item['vote_count'])
                try:
                    votes = str(format(int(votes), ',d'))
                except:
                    pass
                if votes == '' or votes is None: votes = '0'
                votes = votes.encode('utf-8')

                plot = item['overview']
                if plot == '' or plot is None: plot = '0'
                plot = client.replaceHTMLCodes(plot)
                plot = plot.encode('utf-8')

                try:
                    tagline = item['tagline']
                    if tagline == '' or tagline == '0' or tagline is None:
                        tagline = re.compile('[.!?][\s]{1,2}(?=[A-Z])').split(
                            plot)[0]
                    tagline = tagline.encode('utf-8')
                except:
                    tagline = '0'

                ##--TMDb additional info
                url = self.tmdb_info_link % tmdb
                item = self.get_request(url)

                tvdb = item['external_ids']['tvdb_id']
                if tvdb == '' or tvdb is None or tvdb == 'N/A' or tvdb == 'NA':
                    tvdb = '0'
                tvdb = re.sub('[^0-9]', '', str(tvdb))
                tvdb = tvdb.encode('utf-8')

                imdb = item['external_ids']['imdb_id']
                if imdb == '' or imdb is None or imdb == 'N/A' or imdb == 'NA':
                    imdb = '0'
                imdb = imdb.encode('utf-8')

                genre = item['genres']
                try:
                    genre = [x['name'] for x in genre]
                except:
                    genre = '0'
                genre = ' / '.join(genre)
                genre = genre.encode('utf-8')
                if not genre: genre = 'NA'

                try:
                    duration = str(item['runtime'])
                except:
                    duration = '0'
                if duration == '' or duration is None or duration == 'N/A':
                    duration = '0'
                duration = duration.encode('utf-8')

                try:
                    mpaa = [
                        i['rating'] for i in item['content_ratings']['results']
                        if i['iso_3166_1'] == 'US'
                    ][0]
                except:
                    try:
                        mpaa = item['content_ratings'][0]['rating']
                    except:
                        mpaa = 'NR'

                # studio = item['production_companies']
                # try: studio = [x['name'] for x in studio][0]
                # except: studio = '0'
                # if studio == '' or studio is None: studio = '0'
                # studio = studio.encode('utf-8')

                studio = item['networks']
                try:
                    studio = [x['name'] for x in studio][0]
                except:
                    studio = '0'
                if studio == '' or studio is None: studio = '0'
                studio = studio.encode('utf-8')

                director = item['credits']['crew']
                try:
                    director = [
                        x['name'] for x in director
                        if x['job'].encode('utf-8') == 'Director'
                    ]
                except:
                    director = '0'
                if director == '' or director is None or director == []:
                    director = '0'
                director = ' / '.join(director)
                director = director.encode('utf-8')

                writer = item['credits']['crew']
                try:
                    writer = [
                        x['name'] for x in writer if x['job'].encode('utf-8')
                        in ['Writer', 'Screenplay']
                    ]
                except:
                    writer = '0'
                try:
                    writer = [
                        x for n, x in enumerate(writer) if x not in writer[:n]
                    ]
                except:
                    writer = '0'
                if writer == '' or writer is None or writer == []: writer = '0'
                writer = ' / '.join(writer)
                writer = writer.encode('utf-8')

                cast = item['credits']['cast']
                try:
                    cast = [(x['name'].encode('utf-8'),
                             x['character'].encode('utf-8')) for x in cast]
                except:
                    cast = []

                try:
                    if not imdb is None or not imdb == '0':
                        url = self.imdbinfo % imdb
                        item = client.request(url, timeout='30')
                        item = json.loads(item)

                        plot2 = item['Plot']
                        plot2 = client.replaceHTMLCodes(plot2)
                        plot2 = plot.encode('utf-8')
                        if plot == '0' or plot == '' or plot is None:
                            plot = plot2

                        rating2 = str(item['imdbRating'])
                        rating2 = rating2.encode('utf-8')
                        if rating == '0' or rating == '' or rating is None:
                            rating = rating2

                        votes2 = str(item['imdbVotes'])
                        votes2 = str(format(int(votes2), ',d'))
                        votes2 = votes2.encode('utf-8')
                        if votes == '0' or votes == '' or votes is None:
                            votes = votes2
                except:
                    pass

                item = {}
                item = {
                    'content': 'movie',
                    'title': title,
                    'originaltitle': title,
                    'year': year,
                    'premiered': premiered,
                    'studio': studio,
                    'genre': genre,
                    'duration': duration,
                    'rating': rating,
                    'votes': votes,
                    'mpaa': mpaa,
                    'director': director,
                    'writer': writer,
                    'cast': cast,
                    'plot': plot,
                    'tagline': tagline,
                    'code': tmdb,
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'poster': poster,
                    'poster2': '0',
                    'poster3': '0',
                    'banner': '0',
                    'fanart': fanart,
                    'fanart2': '0',
                    'fanart3': '0',
                    'clearlogo': '0',
                    'clearart': '0',
                    'landscape': '0',
                    'metacache': False,
                    'next': next
                }
                meta = {}
                meta = {
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': '0',
                    'lang': self.lang,
                    'user': self.tmdb_key,
                    'item': item
                }

                # fanart_thread = threading.Thread
                from resources.lib.indexers import fanarttv
                extended_art = fanarttv.get_tvshow_art(tvdb)
                if not extended_art is None:
                    item.update(extended_art)
                    meta.update(item)

                self.list.append(item)
                self.meta.append(meta)
                metacache.insert(self.meta)
            except:
                pass
        return self.list