示例#1
0
	def super_info(self, i):
		try:
			if self.list[i]['metacache']: return
			imdb = self.list[i].get('imdb', '') ; tmdb = self.list[i].get('tmdb', '')
#### -- Missing id's lookup -- ####
			if not tmdb and imdb:
				try:
					result = cache.get(tmdb_indexer.Movies().IdLookup, 96, imdb)
					tmdb = str(result.get('id', '')) if result.get('id') else ''
				except: tmdb = ''
			if not tmdb and imdb:
				trakt_ids = trakt.IdLookup('imdb', imdb, 'movie')
				if trakt_ids: tmdb = str(trakt_ids.get('tmdb', '')) if trakt_ids.get('tmdb') else ''
			if not tmdb and not imdb:
				try:
					results = trakt.SearchMovie(title=quote_plus(self.list[i]['title']), year=self.list[i]['year'], fields='title', full=False)
					if results[0]['movie']['title'] != self.list[i]['title'] or results[0]['movie']['year'] != self.list[i]['year']: return
					ids = results[0].get('movie', {}).get('ids', {})
					if not tmdb: tmdb = str(ids.get('tmdb', '')) if ids.get('tmdb') else ''
					if not imdb: imdb = str(ids.get('imdb', '')) if ids.get('imdb') else ''
				except: pass
#################################
			if not tmdb: return
			movie_meta = cache.get(tmdb_indexer.Movies().get_movie_meta, 96, tmdb)
			if not movie_meta: return
			values = {}
			values.update(movie_meta)
			if 'rating' in self.list[i] and self.list[i]['rating']: del values['rating'] #prefer trakt rating and votes if set
			if 'votes' in self.list[i] and self.list[i]['votes']: del values['votes'] 
			if 'year' in self.list[i] and self.list[i]['year'] != values.get('year'): del values['year'] 
			if not imdb: imdb = values.get('imdb', '')
			if not values.get('imdb'): values['imdb'] = imdb
			if not values.get('tmdb'): values['tmdb'] = tmdb
			if self.lang != 'en':
				try:
					# if self.lang == 'en' or self.lang not in values.get('available_translations', [self.lang]): raise Exception()
					trans_item = trakt.getMovieTranslation(imdb, self.lang, full=True)
					if trans_item:
						if trans_item.get('title'): values['title'] = trans_item.get('title')
						if trans_item.get('overview'): values['plot'] =trans_item.get('overview')
				except:
					from resources.lib.modules import log_utils
					log_utils.error()
			if self.enable_fanarttv:
				extended_art = fanarttv_cache.get(fanarttv.get_movie_art, 168, imdb, tmdb)
				if extended_art: values.update(extended_art)
			values = dict((k, v) for k, v in iter(values.items()) if v is not None and v != '') # remove empty keys so .update() doesn't over-write good meta with empty values.
			self.list[i].update(values)
			meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': '', 'lang': self.lang, 'user': self.user, 'item': values}
			self.meta.append(meta)
		except:
			from resources.lib.modules import log_utils
			log_utils.error()
示例#2
0
def get_season_poster(tvdb, season):
    if not tvdb or not season: return None
    try:
        from resources.lib.database import fanarttv_cache
        extended_art = fanarttv_cache.get(get_tvshow_art, 168, tvdb)
        if not extended_art: return None
        season_posters = extended_art.get('season_posters', {})
        if season_posters:
            season_posters = [
                i for i in season_posters if i.get('season') == str(season)
            ]
            season_poster = parse_art(season_posters)
            return season_poster
    except:
        from resources.lib.modules import log_utils
        log_utils.error()
示例#3
0
		def items_list(i):
			if self.list[i]['metacache']: return
			try:
				values = {}
				tmdb = self.list[i].get('tmdb', '')
				movie_meta = cache.get(self.get_movie_meta, 96, tmdb)
				values.update(movie_meta)
				imdb = values['imdb']
				if self.enable_fanarttv:
					extended_art = fanarttv_cache.get(fanarttv.get_movie_art, 168, imdb, tmdb)
					if extended_art: values.update(extended_art)
				values = dict((k,v) for k, v in iter(values.items()) if v is not None and v != '') # remove empty keys so .update() doesn't over-write good meta with empty values.
				self.list[i].update(values)
				meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': '', 'lang': self.lang, 'user': self.user, 'item': values}
				self.meta.append(meta)
			except:
				from resources.lib.modules import log_utils
				log_utils.error()
示例#4
0
	def imdb_list(self, url, isRatinglink=False):
		list = []
		try:
			for i in re.findall(r'date\[(\d+)\]', url):
				url = url.replace('date[%s]' % i, (self.date_time - 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
				url = self.imdbwatchlist2_link % url
			result = client.request(url)
			result = result.replace('\n', ' ')
			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:
			log_utils.error()
			return

		next = ''
		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': '.*?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)
		except: next = ''
		for item in items:
			try:
				title = client.replaceHTMLCodes(client.parseDOM(item, 'a')[1])
				year = client.parseDOM(item, 'span', attrs = {'class': 'lister-item-year.+?'})
				try: year = re.findall(r'(\d{4})', year[0])[0]
				except: continue
				if int(year) > int((self.date_time).strftime('%Y')): continue
				try: show = '–'.decode('utf-8') in str(year).decode('utf-8') or '-'.decode('utf-8') in str(year).decode('utf-8') # check with Matrix
				except: show = False
				if show or ('Episode:' in item): raise Exception() # Some lists contain TV shows.

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

				try: mpaa = client.parseDOM(item, 'span', attrs = {'class': 'certificate'})[0]
				except: mpaa = ''
				if isRatinglink and 'Short' not in genre:
					if mpaa in ('TV-Y', 'TV-Y7', 'TV-G', 'TV-PG', 'TV-13', 'TV-14', 'TV-MA'):
						raise Exception()
				if mpaa == '' or mpaa == 'NOT_RATED': mpaa = ''
				mpaa = mpaa.replace('_', '-')
				mpaa = client.replaceHTMLCodes(mpaa)

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

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

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

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

				rating = ''
				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 == '-': rating = ''
				if not rating:
					try:
						rating = client.parseDOM(item, 'span', attrs = {'class': 'ipl-rating-star__rating'})[0]
						if rating == '-': rating = ''
					except: pass
				rating = client.replaceHTMLCodes(rating)

				votes = ''
				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(r'\((.+?) vote(?:s|)\)', votes)[0]
						except: pass
				votes = client.replaceHTMLCodes(votes)

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

				plot = ''
				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(r'<.+?>|</.+?>', '', plot)
				if not plot:
					try:
						plot = client.parseDOM(item, 'div', attrs = {'class': 'lister-item-content'})[0] # not sure on this, check html
						plot = re.sub(r'<p\s*class="">', '<p class="plot_">', plot)
						plot = client.parseDOM(plot, 'p', attrs = {'class': 'plot_'})[0]
						plot = re.sub(r'<.+?>|</.+?>', '', plot)
					except: pass
				plot = client.cleanHTML(plot)

				values = {}
				values = {'content': 'movie', 'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered,
						'studio': '', 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa,
						'director': director, 'writer': writer, 'cast': cast, 'plot': plot, 'code': tmdb,
						'imdb': imdb, 'tmdb': tmdb, 'tvdb': '', 'poster': poster, 'poster2': '', 'poster3': '', 'banner': '',
						'fanart': '', 'fanart2': '', 'fanart3': '', 'clearlogo': '', 'clearart': '', 'landscape': '',
						'metacache': False, 'next': next}
				meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': '', 'lang': self.lang, 'user': self.tmdb_key, 'item': values}
				if self.enable_fanarttv:
					extended_art = fanarttv_cache.get(fanarttv.get_movie_art, 168, imdb, tmdb)
					if extended_art:
						values.update(extended_art)
						meta.update(values)

				values = dict((k, v) for k, v in iter(values.items()) if v is not None and v != '')
				self.list.append(values)

				if 'next' in meta.get('item'): del meta['item']['next'] # next can not exist in metacache
				self.meta.append(meta)
				self.meta = [i for i in self.meta if i.get('tmdb')] # without this ui removed missing tmdb but it still writes these cases to metacache?
				metacache.insert(self.meta) # don't insert until cleaned up and can also be fetched.
			except:
				log_utils.error()
		return self.list
示例#5
0
        def items_list(tvmaze_id):
            # if i['metacache']: return # not possible with only a tvmaze_id
            try:
                values = {}
                values['next'] = next
                values['tvmaze'] = tvmaze_id
                url = self.tvmaze_info_link % tvmaze_id
                item = get_request(url)
                values['content'] = item.get('type', '').lower()
                values['mediatype'] = 'tvshow'
                values['title'] = item.get('name')
                values['originaltitle'] = values['title']
                values['tvshowtitle'] = values['title']
                values['premiered'] = str(item.get(
                    'premiered', '')) if item.get('premiered') else ''
                try:
                    values['year'] = values['premiered'][:4]
                except:
                    values['year'] = ''
                ids = item.get('externals')
                imdb = str(ids.get('imdb', '')) if ids.get('imdb') else ''
                tvdb = str(ids.get('thetvdb',
                                   '')) if ids.get('thetvdb') else ''
                tmdb = ''  # TVMaze does not have tmdb_id in api
                studio = item.get('network', {}) or item.get('webChannel', {})
                values['studio'] = studio.get('name', '')
                values['genre'] = []
                for i in item['genres']:
                    values['genre'].append(i.title())
                if values['genre'] == []: values['genre'] = 'NA'
                values['duration'] = int(item.get(
                    'runtime', '')) * 60 if item.get('runtime') else ''
                values['rating'] = str(item.get('rating').get(
                    'average',
                    '')) if item.get('rating').get('average') else ''
                values['plot'] = client.cleanHTML(item['summary'])
                values['status'] = item.get('status', '')
                values['castandart'] = []
                for person in item['_embedded']['cast']:
                    try:
                        values['castandart'].append({
                            'name':
                            person['person']['name'],
                            'role':
                            person['character']['name'],
                            'thumbnail':
                            (person['person']['image']['medium']
                             if person['person']['image']['medium'] else '')
                        })
                    except:
                        pass
                    if len(values['castandart']) == 150: break
                image = item.get('image', {}) or ''
                values['poster'] = image.get('original', '') if image else ''
                values['fanart'] = ''
                values['banner'] = ''
                values['mpaa'] = ''
                values['votes'] = ''
                try:
                    values['airday'] = item['schedule']['days'][0]
                except:
                    values['airday'] = ''
                values['airtime'] = item['schedule']['time'] or ''
                try:
                    values['airzone'] = item['network']['country']['timezone']
                except:
                    values['airzone'] = ''
                values['metacache'] = False

                #### -- Missing id's lookup -- ####
                if not tmdb and (imdb or tvdb):
                    try:
                        result = cache.get(tmdb_indexer.TVshows().IdLookup, 96,
                                           imdb, tvdb)
                        tmdb = str(result.get('id',
                                              '')) if result.get('id') else ''
                    except:
                        tmdb = ''
                if not imdb or not tmdb or not tvdb:
                    try:
                        trakt_ids = trakt.SearchTVShow(quote_plus(
                            values['tvshowtitle']),
                                                       values['year'],
                                                       full=False)
                        if not trakt_ids: raise Exception
                        ids = trakt_ids[0].get('show', {}).get('ids', {})
                        if not imdb:
                            imdb = str(ids.get('imdb',
                                               '')) if ids.get('imdb') else ''
                        if not tmdb:
                            tmdb = str(ids.get('tmdb',
                                               '')) if ids.get('tmdb') else ''
                        if not tvdb:
                            tvdb = str(ids.get('tvdb',
                                               '')) if ids.get('tvdb') else ''
                    except:
                        log_utils.error()
#################################
                if not tmdb:
                    return log_utils.log(
                        'tvshowtitle: (%s) missing tmdb_id: ids={imdb: %s, tmdb: %s, tvdb: %s}'
                        % (values['tvshowtitle'], imdb, tmdb, tvdb), __name__,
                        log_utils.LOGDEBUG
                    )  # log TMDb shows that they do not have
                # self.list = metacache.fetch(self.list, self.lang, self.user)
                # if self.list['metacache'] is True: raise Exception()

                showSeasons = cache.get(
                    tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb)
                if not showSeasons: return
                showSeasons = dict(
                    (k, v) for k, v in iter(showSeasons.items())
                    if v is not None and v != ''
                )  # removes empty keys so .update() doesn't over-write good meta
                values.update(showSeasons)
                if not values.get('imdb'): values['imdb'] = imdb
                if not values.get('tmdb'): values['tmdb'] = tmdb
                if not values.get('tvdb'): values['tvdb'] = tvdb
                for k in ('seasons', ):
                    values.pop(
                        k, None
                    )  # pop() keys from showSeasons that are not needed anymore
                if self.enable_fanarttv:
                    extended_art = fanarttv_cache.get(fanarttv.get_tvshow_art,
                                                      168, tvdb)
                    if extended_art: values.update(extended_art)
                meta = {
                    'imdb': imdb,
                    'tmdb': tmdb,
                    'tvdb': tvdb,
                    'lang': self.lang,
                    'user': self.user,
                    'item': values
                }  # DO NOT move this after "values = dict()" below or it becomes the same object and "del meta['item']['next']" removes it from both
                values = dict((k, v) for k, v in iter(values.items())
                              if v is not None and v != '')
                self.list.append(values)
                if 'next' in meta.get('item'):
                    del meta['item']['next']  # next can not exist in metacache
                self.meta.append(meta)
                self.meta = [
                    i for i in self.meta if i.get('tmdb')
                ]  # without this ui removed missing tmdb but it still writes these cases to metacache?
                metacache.insert(self.meta)
            except:
                log_utils.error()