Beispiel #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()
Beispiel #2
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')
			try:
				item = tmdb_indexer.Movies().get_movie_request(tmdb, imdb)  # api claims int rq'd.  But imdb_id works for movies but not looking like it does for shows
				if not item and (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 tmdb: item = tmdb_indexer.Movies().get_movie_request(tmdb, '')
				if not item:
					results = trakt.SearchMovie(title=quote_plus(self.list[i]['title']), year=self.list[i]['year'], fields='title', full=False)
					if results:
						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 ''
						item = tmdb_indexer.Movies().get_movie_request(tmdb, imdb)
						if not item: return
					else: return
			except:
				log_utils.error()
				return
			title = item.get('title') or self.list[i]['title']
			originaltitle = title

#add these so sources module may not have to make a trakt api request
			# aliases = item.get('alternative_titles').get('titles')
			# log_utils.log('aliases = %s' % str(aliases), __name__, log_utils.LOGDEBUG)

			if not imdb: imdb = str(item.get('imdb_id', '')) if item.get('imdb_id') else ''
			if not tmdb: tmdb = str(item.get('id', '')) if item.get('id') else ''

			if 'year' not in self.list[i] or not self.list[i]['year']:
				year = str(item.get('release_date')[:4]) if item.get('release_date') else ''
			else: year = self.list[i]['year']

			if 'premiered' not in self.list[i] or not self.list[i]['premiered']:
				premiered = item.get('release_date', '')
			else: premiered = self.list[i]['premiered']

			if premiered and year not in premiered: # hack fix for imdb vs. tmdb mismatch without a new request.
				premiered = premiered.replace(premiered[:4], year)

			if 'genre' not in self.list[i] or not self.list[i]['genre']:
				genre = []
				for x in item['genres']: genre.append(x.get('name'))
			else: genre = self.list[i]['genre']

			if 'duration' not in self.list[i] or not self.list[i]['duration']:
				duration = str(item.get('runtime', '')) if item.get('runtime') else ''
			else: duration = self.list[i]['duration']

			if 'rating' not in self.list[i] or not self.list[i]['rating']:
				rating = str(item.get('vote_average', '')) if item.get('vote_average') else ''
			else: rating = self.list[i]['rating']

			if 'votes' not in self.list[i] or not self.list[i]['votes']:
				votes = str(item.get('vote_count', '')) if item.get('vote_count') else ''
			else: votes = self.list[i]['votes']

			if 'mpaa' not in self.list[i] or not self.list[i]['mpaa']:
				rel_info = [x for x in item['release_dates']['results'] if x['iso_3166_1'] == 'US'][0]
				try:
					mpaa = ''
					for cert in rel_info.get('release_dates', {}):
						if cert['certification']: # loop thru all keys
							mpaa = cert['certification']
							break
				except: mpaa = ''
			else: mpaa = self.list[i]['mpaa']

			if 'plot' not in self.list[i] or not self.list[i]['plot']:
				plot = item.get('overview')
			else: plot = self.list[i]['plot']

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

			director = writer = ''
			poster3 = fanart3 = ''

			castandart = []
			for person in item['credits']['cast']:
				try: castandart.append({'name': person['name'], 'role': person['character'], 'thumbnail': ((self.profile_path + person.get('profile_path')) if person.get('profile_path') else '')})
				except: pass
				if len(castandart) == 150: break

			crew = item.get('credits', {}).get('crew')
			try: director = ', '.join([d['name'] for d in [x for x in crew if x['job'] == 'Director']])
			except: director = ''
			try: writer = ', '.join([w['name'] for w in [y for y in crew if y['job'] in ['Writer', 'Screenplay', 'Author', 'Novel']]])
			except: writer = ''

			poster3 = '%s%s' % (self.tmdb_poster, item['poster_path']) if item['poster_path'] else ''
			fanart3 = '%s%s' % (self.tmdb_fanart, item['backdrop_path']) if item['backdrop_path'] else ''

			try:
				if self.lang == 'en' or self.lang not in item.get('available_translations', [self.lang]): raise Exception()
				trans_item = trakt.getMovieTranslation(imdb, self.lang, full=True)
				title = trans_item.get('title') or title
				plot = trans_item.get('overview') or plot
			except:
				log_utils.error()

			item = {'title': title, 'originaltitle': originaltitle, 'year': year, 'imdb': imdb, 'tmdb': tmdb, 'premiered': premiered,
						'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'director': director,
						'writer': writer, 'castandart': castandart, 'plot': plot, 'poster2': '', 'poster3': poster3,
						'banner': '', 'banner2': '', 'fanart2': '', 'fanart3': fanart3, 'clearlogo': '', 'clearart': '', 'landscape': '',
						'discart': '', 'mediatype': 'movie', 'trailer': trailer, 'metacache': False}
			if not self.disable_fanarttv:
				extended_art = cache.get(fanarttv.get_movie_art, 168, imdb, tmdb)
				if extended_art: item.update(extended_art)
			if not item.get('landscape'): item.update({'landscape': fanart3})
			item = dict((k, v) for k, v in iter(item.items()) if v is not None and and v != '')
			self.list[i].update(item)
			meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': '', 'lang': self.lang, 'user': self.user, 'item': item}
			self.meta.append(meta)
		except:
			log_utils.error()
    def super_info(self, i):
        try:
            if self.list[i]['metacache']: return
            imdb = self.list[i]['imdb'] or '0'
            tmdb = self.list[i]['tmdb'] or '0'
            try:
                item = tmdb_indexer.Movies().get_details(
                    tmdb, imdb
                )  # api claims int rq'd.  But imdb_id works for movies but not looking like it does for shows
                if not item and (tmdb == '0' and imdb != '0'):
                    trakt_ids = trakt.IdLookup('imdb', imdb, 'movie')
                    if trakt_ids:
                        tmdb = str(trakt_ids.get('tmdb', '0'))
                        if not tmdb or tmdb == 'None': tmdb = '0'
                        else:
                            item = tmdb_indexer.Movies().get_details(tmdb, '0')
                if not item:
                    results = trakt.SearchMovie(title=quote_plus(
                        self.list[i]['title']),
                                                year=self.list[i]['year'],
                                                fields='title',
                                                full=False)[0]
                    if results:
                        if tmdb == '0':
                            tmdb = str(
                                results.get('movie').get('ids').get(
                                    'tmdb', '0'))
                        if imdb == '0':
                            imdb = str(
                                results.get('movie').get('ids').get(
                                    'imdb', '0'))
                        item = tmdb_indexer.Movies().get_details(tmdb, imdb)
                        if not item: return
                    else: return
            except:
                log_utils.error()
                return

            title = py_tools.ensure_str(item.get('title'))
            originaltitle = title

            #add these so sources module may not have to make a trakt api request
            # aliases = item.get('alternative_titles').get('titles')
            # log_utils.log('aliases = %s' % str(aliases), __name__, log_utils.LOGDEBUG)

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

            if 'year' not in self.list[i] or self.list[i]['year'] == '0':
                year = str(item.get('release_date')[:4])
            else:
                year = self.list[i]['year'] or '0'

            if 'premiered' not in self.list[i] or self.list[i][
                    'premiered'] == '0':  # imdb and tmdb difffer often
                premiered = item.get('release_date')
            else:
                premiered = self.list[i]['premiered']

            if premiered and year not in premiered:  # hack fix for imdb vs. tmdb mismatch without a new request.
                premiered = premiered.replace(premiered[:4], year)

            if 'genre' not in self.list[i] or self.list[i][
                    'genre'] == '0' or self.list[i]['genre'] == 'NA':
                genre = []
                for x in item['genres']:
                    genre.append(x.get('name'))
                if genre == []: genre = 'NA'
            else: genre = self.list[i]['genre']

            if 'duration' not in self.list[i] or self.list[i][
                    'duration'] == '0':
                duration = str(item.get('runtime', '0'))
            else:
                duration = self.list[i]['duration']

            if 'rating' not in self.list[i] or self.list[i]['rating'] == '0':
                rating = str(item.get('vote_average', '0'))
            else:
                rating = self.list[i]['rating']

            if 'votes' not in self.list[i] or self.list[i]['votes'] == '0':
                votes = str(format(int(item.get('vote_count', '0')), ',d'))
            else:
                votes = self.list[i]['votes']

            if 'mpaa' not in self.list[i] or self.list[i][
                    'mpaa'] == '0' or self.list[i]['mpaa'] == 'NR':
                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'
            else:
                mpaa = self.list[i]['mpaa']

            if 'plot' not in self.list[i] or self.list[i]['plot'] == '0':
                plot = item.get('overview')
            else:
                plot = self.list[i]['plot']
            plot = py_tools.ensure_str(plot)

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

            castandart = []
            director = writer = '0'
            poster3 = fanart3 = '0'

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

            for person in item['credits']['crew']:
                if 'Director' in person['job']:
                    # director = ', '.join([director['name'].encode('utf-8') for director in item['credits']['crew'] if director['job'].lower() == 'director'])
                    director = ', '.join([
                        director['name']
                        for director in item['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 item['credits']['crew'] if writer['job'].lower() in ['writer', 'screenplay', 'author', 'novel']])
                    writer = ', '.join([
                        writer['name'] for writer in item['credits']['crew']
                        if writer['job'].lower() in
                        ['writer', 'screenplay', 'author', 'novel']
                    ])

            poster3 = '%s%s' % (self.tmdb_poster, item['poster_path']
                                ) if item['poster_path'] else '0'
            fanart3 = '%s%s' % (self.tmdb_fanart, item['backdrop_path']
                                ) if item['backdrop_path'] else '0'

            try:
                if self.lang == 'en' or self.lang not in item.get(
                        'available_translations', [self.lang]):
                    raise Exception()
                trans_item = trakt.getMovieTranslation(imdb,
                                                       self.lang,
                                                       full=True)
                title = trans_item.get('title') or title
                plot = trans_item.get('overview') or plot
            except:
                log_utils.error()

            item = {
                'title': title,
                'originaltitle': originaltitle,
                'year': year,
                'imdb': imdb,
                'tmdb': tmdb,
                'premiered': premiered,
                'genre': genre,
                'duration': duration,
                'rating': rating,
                'votes': votes,
                'mpaa': mpaa,
                'director': director,
                'writer': writer,
                'castandart': castandart,
                'plot': plot,
                'poster2': '0',
                'poster3': poster3,
                'banner': '0',
                'banner2': '0',
                'fanart2': '0',
                'fanart3': fanart3,
                'clearlogo': '0',
                'clearart': '0',
                'landscape': '0',
                'discart': '0',
                'mediatype': 'movie',
                'trailer': trailer,
                'metacache': False
            }
            meta = {
                'imdb': imdb,
                'tmdb': tmdb,
                'tvdb': '0',
                '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_movie_art, 168, imdb,
                                         tmdb)
                if extended_art:
                    item.update(extended_art)
                    meta.update(item)

            if item.get('landscape', '0') == '0':
                item.update({'landscape': fanart3})
                meta.update(item)
            item = dict(
                (k, v) for k, v in control.iteritems(item) if v and v != '0')
            self.list[i].update(item)
            self.meta.append(meta)
        except:
            log_utils.error()
Beispiel #4
0
def download(name, image, url):
    if url == None: return

    from resources.lib.modules import control
    from resources.lib.modules import trakt

    try:
        headers = dict(urlparse.parse_qsl(url.rsplit('|', 1)[1]))
    except:
        headers = dict('')

    url = url.split('|')[0]

    content = re.compile('(.+?)\sS(\d*)E\d*$').findall(name)

    if control.setting('Download.auf.Deutsch') != 'false':
        if len(content) == 0:
            title = name[:-7]
            transyear = name.replace("(", "").replace(")", "")
            year = transyear[-4:]
            imdb = trakt.SearchMovie(title, year, full=False)[0]
            imdb = imdb.get('movie', '0')
            imdb = imdb.get('ids', {}).get('imdb', '0')
            imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))
            lang = 'de'
            germantitle = trakt.getMovieTranslation(imdb, lang)
            transname = germantitle.translate(
                None, '\/:*?"<>|').strip('.') + ' ' + '(' + str(year) + ')'
        else:
            title = name[:-7]
            transyear = name.replace("(", "").replace(")", "")
            year = transyear[-4:]
            imdb = trakt.SearchTVShow(title, year, full=False)[0]
            imdb = imdb.get('show', '0')
            imdb = imdb.get('ids', {}).get('imdb', '0')
            imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))
            lang = 'de'
            germantitle = trakt.getTVShowTranslation(imdb, lang)
            #transname = germantitle.translate(None, '\/:*?"<>|').strip('.') ### Warum nicht möglich?
            transname = name.translate(None, '\/:*?"<>|').strip('.')
            transtvshowtitle = content[0][0].translate(None,
                                                       '\/:*?"<>|').strip('.')
    else:
        if len(content) == 0:
            transname = name.translate(None, '\/:*?"<>|').strip('.')
        else:
            transname = name.translate(None, '\/:*?"<>|').strip('.')
            transtvshowtitle = content[0][0].translate(None,
                                                       '\/:*?"<>|').strip('.')

    levels = ['../../../..', '../../..', '../..', '..']

    if len(content) == 0:
        dest = control.setting('movie.download.path')
        dest = control.transPath(dest)
        for level in levels:
            try:
                control.makeFile(os.path.abspath(os.path.join(dest, level)))
            except:
                pass
        control.makeFile(dest)
        dest = os.path.join(dest, transname)
        control.makeFile(dest)
    else:
        dest = control.setting('tv.download.path')
        dest = control.transPath(dest)
        for level in levels:
            try:
                control.makeFile(os.path.abspath(os.path.join(dest, level)))
            except:
                pass
        control.makeFile(dest)
        dest = os.path.join(dest, transtvshowtitle)
        control.makeFile(dest)
        dest = os.path.join(dest, 'Season %01d' % int(content[0][1]))
        control.makeFile(dest)

    ext = os.path.splitext(urlparse.urlparse(url).path)[1][1:]
    if not ext in ['mp4', 'mkv', 'flv', 'avi', 'mpg']: ext = 'mp4'
    dest = os.path.join(dest, transname + '.' + ext)

    sysheaders = urllib.quote_plus(json.dumps(headers))

    sysurl = urllib.quote_plus(url)

    systitle = urllib.quote_plus(name)

    sysimage = urllib.quote_plus(image)

    sysdest = urllib.quote_plus(dest)

    script = inspect.getfile(inspect.currentframe())
    cmd = 'RunScript(%s, %s, %s, %s, %s, %s)' % (
        script, sysurl, sysdest, systitle, sysimage, sysheaders)

    xbmc.executebuiltin(cmd)