Esempio n. 1
0
    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
Esempio n. 2
0
        def items_list(i):
            try:
                url = self.tvmaze_info_link % i
                item = client.request(url)
                item = json.loads(item)
                # if control.setting('tvshows.networks.filter') == '0' and not item['status'] == 'Running' or not item['status'] == 'In Development':
                    # raise exception()
                # if control.setting('tvshows.networks.filter') == '1' and not item['status'] == 'Ended':
                    # raise exception()
                # if control.setting('tvshows.networks.filter') == '2' and not item['type'] == 'Documentary':
                    # raise exception()
                # if control.setting('tvshows.networks.filter') == '3' and not item['type'] == 'talk show':
                    # raise exception()
                # if control.setting('tvshows.networks.filter') == '4' and not item['status'] == 'Running' or not item['status'] == 'In Development' or not item['status'] == 'Ended':
                    # raise exception()
                    # # and not item['type'] == 'reality':
                    # # and not item['type'] == 'news':
                title = item['name']
                title = re.sub('\s(|[(])(UK|US|AU|\d{4})(|[)])$', '', title)
                title = client.replaceHTMLCodes(title)
                title = title.encode('utf-8')

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

                try:
                    imdb = item['externals']['imdb']
                    if imdb is None or imdb == '':
                        imdb = '0'
                    else:
                        imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))
                    imdb = imdb.encode('utf-8')
                except:
                    imdb = '0'

                try:
                    tvdb = item['externals']['thetvdb']
                    if tvdb is None or tvdb == '':
                        tvdb = '0'
                    else:
                        tvdb = re.sub('[^0-9]', '', str(tvdb))
                    tvdb = tvdb.encode('utf-8')
                except:
                    tvdb = '0'

                tmdb = '0'

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

                try: studio = item['network']['name']
                except: studio = '0'
                if studio == '0':
                    try: studio = item['webChannel']['name']
                    except: studio = '0'
                if studio is None: studio = '0'
                studio = studio.encode('utf-8')

                try:
                    genre = item['genres']
                    genre = [i.title() for i in genre]
                    genre = (' / '.join(genre)).encode('utf-8')
                    if genre == '' or genre is None: raise Exception()
                except: genre = 'NA'

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

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

                try:
                    plot = item['summary']
                    plot = re.sub('<.+?>|</.+?>|\n', '', plot)
                    plot = client.replaceHTMLCodes(plot)
                    plot = plot.encode('utf-8')
                except: plot = '0'

                try:
                    content = item['type'].lower()
                    content = content.encode('utf-8')
                except: content = '0'

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

                # cast = []
                # try:
                    # people = item['_embedded']['cast']
                    # cast.append({'name': people['person']['name']})
                    # # cast.append({'name': people['person']['name'], 'role': people['character']['name']})
                # except: cast = []

                try:
                    poster = item['image']['original']
                    poster = poster.encode('utf-8')
                except: poster = '0'

                fanart = '0' ; banner = '0'


###--Check TVDb for missing info
                if tvdb == '0' or imdb == '0':
                    url = self.tvdb_by_query % (urllib.quote_plus(title))
                    item2 = client.request(url, timeout='20')
                    item2 = re.sub(r'[^\x00-\x7F]+', '', item2)
                    item2 = client.replaceHTMLCodes(item2)
                    item2 = client.parseDOM(item2, 'Series')
                    if tvdb == '0':
                        try: tvdb = client.parseDOM(item2, 'seriesid')[0]
                        except: tvdb = '0'
                    if imdb == '0':
                        try: imdb = client.parseDOM(item2, 'IMDB_ID')[0]
                        except: imdb = '0'

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

                if poster == '0' and not item3 is None :
                    try:
                        poster = client.parseDOM(item3, 'poster')[0]
                        if not poster == '' or not poster is None: poster = self.tvdb_image + poster
                        else: poster = '0'
                        poster = client.replaceHTMLCodes(poster)
                        poster = poster.encode('utf-8')
                    except: poster = '0'

                if not item3 is None:
                    try:
                        banner = client.parseDOM(item3, 'banner')[0]
                        if not banner == '' or not banner is None: banner = self.tvdb_image + banner
                        else: banner = '0'
                        banner = client.replaceHTMLCodes(banner)
                        banner = banner.encode('utf-8')
                    except: banner = '0'

                    try:
                        fanart = client.parseDOM(item3, 'fanart')[0]
                        if not fanart == '': fanart = self.tvdb_image + fanart
                        fanart = client.replaceHTMLCodes(fanart)
                        fanart = fanart.encode('utf-8')
                    except: fanart = '0'

                    try:
                        cast = client.parseDOM(item3, 'Actors')[0]
                        cast = [x for x in cast.split('|') if not x == '']
                        cast = [(x.encode('utf-8'), '') for x in cast]
                    except: cast = '0'

                    try:
                        mpaa = client.parseDOM(item3, 'ContentRating')[0]
                        mpaa = client.replaceHTMLCodes(mpaa)
                        mpaa = mpaa.encode('utf-8')
                    except: mpaa = 'NR'

                    if duration == '0':
                        try:
                            duration = client.parseDOM(item3, 'Runtime')[0]
                            duration = client.replaceHTMLCodes(duration)
                            duration = duration.encode('utf-8')
                        except: duration = '0'

                    try:
                        votes = client.parseDOM(item3, 'RatingCount')[0]
                        votes = client.replaceHTMLCodes(votes)
                        votes = votes.encode('utf-8')
                    except: votes = '0'

                    if year == '0':
                        try:
                            year = client.parseDOM(item3, 'FirstAired')[0]
                            year = re.compile('(\d{4})').findall(year)[0]
                            year = year.encode('utf-8')
                        except: year = '0'
###-----

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

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

                else:
                    item = {}
                    item = {'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered, 'studio': studio, 'mpaa': mpaa, 'genre': genre, 'duration': duration, 'cast': cast,
                            'rating': rating, 'votes': votes, 'plot': plot, 'content': content, 'status': status, 'imdb': imdb, 'tvdb': tvdb, 'tmdb': tmdb, 'poster': poster, 'poster2': '0',
                            'banner': banner, '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.user, '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
Esempio n. 3
0
    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
Esempio n. 4
0
		def items_list(i):
			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 (tvdb == '0' or tmdb == '0') and imdb != '0':
					from resources.lib.modules import trakt
					trakt_ids = trakt.IdLookup('show', 'imdb', imdb)
					if tvdb == '0':
						tvdb = str(trakt_ids.get('tvdb', '0'))
						if tvdb == '' or tvdb is None or tvdb == 'None':
							tvdb = '0'
					if tmdb == '0':
						tmdb = str(trakt_ids.get('tmdb', '0'))
						if tvdb == '' or tvdb is None or tvdb == 'None':
							tvdb = '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 % (urllib.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 is not None:
					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)
					extended_art = fanarttv.get_tvshow_art(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