示例#1
0
def get(media_type, imdb, season, episode, local=False):

    if control.setting('rersume.source') == '1' and trakt.getTraktCredentialsInfo() == True and local == False:
        try:
            if media_type == 'episode':

                # Looking for a Episode progress
                traktInfo = trakt.getTraktAsJson('https://api.trakt.tv/sync/playback/episodes?extended=full')
                for i in traktInfo:
                    if imdb == i['show']['ids']['imdb']:
                        # Checking Episode Number
                        if int(season) == i['episode']['season'] and int(episode) == i['episode']['number']:
                            seekable = 1 < i['progress'] < 92
                            if seekable:
                                # Calculating Offset to seconds
                                offset = (float(i['progress'] / 100) * int(i['episode']['runtime']) * 60)
                            else:
                                offset = 0
            else:

                # Looking for a Movie Progress
                traktInfo = trakt.getTraktAsJson('https://api.trakt.tv/sync/playback/movies?extended=full')
                for i in traktInfo:
                    if imdb == i['movie']['ids']['imdb']:
                        seekable = 1 < i['progress'] < 92
                        if seekable:
                            # Calculating Offset to seconds
                            offset = (float(i['progress'] / 100) * int(i['movie']['runtime']) * 60)
                        else:
                            offset = 0

            return offset

        except:
            return 0

    else:
        try:

            sql_select = "SELECT * FROM bookmarks WHERE imdb = '%s'" % imdb
            if media_type == 'episode':
                sql_select += " AND season = '%s' AND episode = '%s'" % (season, episode)

            control.makeFile(control.dataPath)
            dbcon = database.connect(control.bookmarksFile)
            dbcur = dbcon.cursor()
            dbcur.execute(sql_select)
            match = dbcur.fetchone()
            if match:
                offset = match[0]
                return float(offset)
            else:
                return 0
            dbcon.commit()
        except:
            log_utils.log('bookmarks_get', 1)
            return 0
    def trakt_user_list(self, url, user):
        try:
            items = trakt.getTraktAsJson(url)
        except:
            pass

        for item in items:
            try:
                try:
                    name = item['list']['name']
                except:
                    name = item['name']
                name = client.replaceHTMLCodes(name)

                try:
                    url = (trakt.slug(item['list']['user']['username']),
                           item['list']['ids']['slug'])
                except:
                    url = ('me', item['ids']['slug'])
                url = self.traktlist_link % url
                url = url.encode('utf-8')

                self.list.append({'name': name, 'url': url, 'context': url})
            except:
                pass

        self.list = sorted(self.list, key=lambda k: utils.title_key(k['name']))
        return self.list
示例#3
0
    def trakt_user_list(self, url, user):
        try:
            items = trakt.getTraktAsJson(url)
        except:
            pass

        for item in items:
            try:
                try: name = item['list']['name']
                except: name = item['name']
                name = client.replaceHTMLCodes(name)

                try: url = (trakt.slug(item['list']['user']['username']), item['list']['ids']['slug'])
                except: url = ('me', item['ids']['slug'])
                url = self.traktlist_link % url
                url = url.encode('utf-8')

                self.list.append({'name': name, 'url': url, 'context': url})
            except:
                pass

        self.list = sorted(self.list, key=lambda k: utils.title_key(k['name']))
        return self.list
    def trakt_list(self, url, user):
        try:
            dupes = []

            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            q.update({'extended': 'full'})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            u = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q

            result = trakt.getTraktAsJson(u)

            items = []
            for i in result:
                try: items.append(i['show'])
                except: pass
            if len(items) == 0:
                items = result
        except:
            return

        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            if not int(q['limit']) == len(items): raise Exception()
            q.update({'page': str(int(q['page']) + 1)})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            next = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q
            next = next.encode('utf-8')
        except:
            next = ''

        for item in items:
            try:
                title = item['title']
                title = re.sub('\s(|[(])(UK|US|AU|\d{4})(|[)])$', '', title)
                title = client.replaceHTMLCodes(title)

                year = item['year']
                year = re.sub('[^0-9]', '', str(year))

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

                imdb = item['ids']['imdb']
                if imdb == None or imdb == '': imdb = '0'
                else: imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))

                tvdb = item['ids']['tvdb']
                tvdb = re.sub('[^0-9]', '', str(tvdb))

                if tvdb == None or tvdb == '' or tvdb in dupes: raise Exception()
                dupes.append(tvdb)

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

                try: studio = item['network']
                except: studio = '0'
                if studio == None: studio = '0'

                try: genre = item['genres']
                except: genre = '0'
                genre = [i.title() for i in genre]
                if genre == []: genre = '0'
                genre = ' / '.join(genre)

                try: duration = str(item['runtime'])
                except: duration = '0'
                if duration == None: duration = '0'

                try: rating = str(item['rating'])
                except: rating = '0'
                if rating == None or rating == '0.0': rating = '0'

                try: votes = str(item['votes'])
                except: votes = '0'
                try: votes = str(format(int(votes),',d'))
                except: pass
                if votes == None: votes = '0'

                try: mpaa = item['certification']
                except: mpaa = '0'
                if mpaa == None: mpaa = '0'

                try: plot = item['overview']
                except: plot = '0'
                if plot == None: plot = '0'
                plot = client.replaceHTMLCodes(plot)

                self.list.append({'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'plot': plot, 'imdb': imdb, 'tvdb': tvdb, 'poster': '0', 'next': next})
            except:
                pass

        return self.list
示例#5
0
def trakt_list(self, url, user):
    try:
        q = dict(parse_qsl(urlsplit(url).query))
        q.update({'extended': 'full'})
        q = (urlencode(q)).replace('%2C', ',')
        u = url.replace('?' + urlparse(url).query, '') + '?' + q

        result = trakt.getTraktAsJson(u)

        items = []
        for i in result:
            try:
                movie = i['movie']
                try:
                    movie['progress'] = max(0, min(1, i['progress'] / 100.0))
                except:
                    pass
                items.append(movie)
            except:
                pass
        if len(items) == 0:
            items = result
    except:
        return

    try:
        q = dict(parse_qsl(urlsplit(url).query))
        if not int(q['limit']) == len(items): raise Exception()
        q.update({'page': str(int(q['page']) + 1)})
        q = (urlencode(q)).replace('%2C', ',')
        next = url.replace('?' + urlparse(url).query, '') + '?' + q
        next = next.encode('utf-8')
    except:
        next = ''

    for item in items:
        try:
            try:
                title = (item.get('title')).encode('utf-8')
            except:
                title = item.get('title')

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

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

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

            try:
                progress = item['progress']
            except:
                progress = None

            imdb = item.get('ids', {}).get('imdb', '0')
            if imdb == '' or imdb is None or imdb == 'None':
                imdb = '0'

            tmdb = str(item.get('ids', {}).get('tmdb', 0))
            if tmdb == '' or tmdb is None or tmdb == 'None':
                tmdb = '0'

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

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

            rating = str(item.get('rating', '0'))
            votes = str(format(int(item.get('votes', '0')), ',d'))

            mpaa = item.get('certification', '0')

            plot = item.get('overview')
            try:
                plot = plot.encode('utf-8')
            except:
                pass

            # tagline = item.get('tagline', '0')
            tagline = '0'

            self.list.append({
                'title': title,
                'originaltitle': title,
                'year': year,
                'premiered': premiered,
                'genre': genre,
                'duration': duration,
                'rating': rating,
                'votes': votes,
                'mpaa': mpaa,
                'plot': plot,
                'tagline': tagline,
                'imdb': imdb,
                'tmdb': tmdb,
                'tvdb': '0',
                'poster': '0',
                'fanart': '0',
                'next': next,
                'progress': progress
            })
        except:
            pass
    return self.list
示例#6
0
	def trakt_list(self, url, user):
		list = []
		try:
			dupes = []
			q = dict(parse_qsl(urlsplit(url).query))
			extended = q.get('extended', '')
			if extended and extended != 'full': q.update({'extended': '%s,%s' % ('full', extended)})
			else: q.update({'extended': 'full'})
			q = (urlencode(q)).replace('%2C', ',')
			u = url.replace('?' + urlparse(url).query, '') + '?' + q
			if '/related' in u: u = u + '&limit=20'
			result = trakt.getTraktAsJson(u)
			if not result: return list
			items = []
			for i in result:
				try:
					show = i['show']
					show['added'] = i.get('listed_at')
					show['paused_at'] = i.get('paused_at', '')
					try: show['progress'] = max(0, min(1, i['progress'] / 100.0))
					except: show['progress'] = ''
					show['lastplayed'] = i.get('watched_at', '')
					items.append(show)
				except: pass
			if len(items) == 0: items = result
		except:
			from resources.lib.modules import log_utils
			log_utils.error()
			return
		try:
			q = dict(parse_qsl(urlsplit(url).query))
			if int(q['limit']) != len(items): raise Exception()
			q.update({'page': str(int(q['page']) + 1)})
			q = (urlencode(q)).replace('%2C', ',')
			next = url.replace('?' + urlparse(url).query, '') + '?' + q
		except: next = ''

		def items_list(item):
			try:
				values = item
				values['next'] = next 
				values['title'] = item.get('title')
				values['originaltitle'] = values['title']
				values['tvshowtitle'] = values['title']
				try: values['premiered'] = item.get('first_aired', '')[:10]
				except: values['premiered'] = ''
				values['year'] = str(item.get('year')) if item.get('year') else ''
				if not values['year']:
					try: values['year'] = str(values['premiered'][:4])
					except: values['year'] = ''
				ids = item.get('ids', {})
				values['imdb'] = str(ids.get('imdb', '')) if ids.get('imdb', '') else ''
				values['tmdb'] = str(ids.get('tmdb')) if ids.get('tmdb', '') else ''
				values['tvdb'] = str(ids.get('tvdb')) if ids.get('tvdb', '') else ''
				if values['tvdb'] in dupes: return
				dupes.append(values['tvdb'])
				values['studio'] = item.get('network')
				values['genre'] = ' / '.join([x.title() for x in item.get('genres', {})]) or 'NA'
				values['duration'] = int(item.get('runtime') * 60) if item.get('runtime') else ''
				values['total_episodes'] = item.get('aired_episodes', '')
				values['mpaa'] = item.get('certification', '') or 'NA'
				values['plot'] = item.get('overview')
				values['poster'] = ''
				values['fanart'] = ''
				try: values['trailer'] = control.trailer % item['trailer'].split('v=')[1]
				except: values['trailer'] = ''
				airs = item.get('airs', {})
				values['airday'] = airs['day']
				values['airtime'] = airs['time']
				values['airzone'] = airs['timezone']
				for k in ('first_aired', 'ids', 'genres', 'runtime', 'certification', 'overview', 'aired_episodes', 'comment_count', 'network', 'airs'): values.pop(k, None) # pop() keys that are not needed anymore
				list.append(values)
			except:
				from resources.lib.modules import log_utils
				log_utils.error()
		threads = []
		for item in items: threads.append(workers.Thread(items_list, item))
		[i.start() for i in threads]
		[i.join() for i in threads]
		return list
示例#7
0
    def trakt_list(self, url, user):
        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            q.update({'extended': 'full'})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            u = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q
            result = trakt.getTraktAsJson(u)
            items = []
            for i in result:
                try:
                    movie = i['movie']
                    try: movie['progress'] = max(0, min(1, i['progress'] / 100.0))
                    except: pass
                    items.append(movie)
                except: pass
            if len(items) == 0:
                items = result
        except:
            return
        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            if not int(q['limit']) == len(items): raise Exception()
            q.update({'page': str(int(q['page']) + 1)})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            next = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q
            next = next.encode('utf-8')
        except:
            next = ''

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

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

                # try:
                    # if int(year) > int((self.datetime).strftime('%Y')): continue
                # except: pass

                try: progress = item['progress']
                except: progress = None

                try:
                    imdb = item['ids']['imdb']
                    imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))
                    imdb = imdb.encode('utf-8')
                except: imdb = '0'

                tmdb = str(item.get('ids', {}).get('tmdb', 0))

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

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

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

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

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

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

                try:
                    plot = item['overview'].encode('utf-8')
                    plot = client.replaceHTMLCodes(plot)
                    plot = plot.encode('utf-8')
                except: plot = '0'

                try:
                    tagline = item['tagline']
                    tagline = client.replaceHTMLCodes(tagline)
                except: tagline = '0'

                self.list.append({'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'plot': plot, 'tagline': tagline, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': '0', 'poster': '0', 'fanart': '0', 'next': next, 'progress': progress})
            except:
                pass
        return self.list
示例#8
0
    def trakt_list(self, url, user):
        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            q.update({'extended': 'full'})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            u = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q

            result = trakt.getTraktAsJson(u)

            items = []
            for i in result:
                try: items.append(i['movie'])
                except: pass
            if len(items) == 0:
                items = result
        except:
            return

        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            if not int(q['limit']) == len(items): raise Exception()
            q.update({'page': str(int(q['page']) + 1)})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            next = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q
            next = next.encode('utf-8')
        except:
            next = ''

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

                year = item['year']
                year = re.sub('[^0-9]', '', str(year))

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

                imdb = item['ids']['imdb']
                if imdb == None or imdb == '': raise Exception()
                imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))

                tmdb = str(item.get('ids', {}).get('tmdb', 0))

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

                try: genre = item['genres']
                except: genre = '0'
                genre = [i.title() for i in genre]
                if genre == []: genre = '0'
                genre = ' / '.join(genre)

                try: duration = str(item['runtime'])
                except: duration = '0'
                if duration == None: duration = '0'

                try: rating = str(item['rating'])
                except: rating = '0'
                if rating == None or rating == '0.0': rating = '0'

                try: votes = str(item['votes'])
                except: votes = '0'
                try: votes = str(format(int(votes),',d'))
                except: pass
                if votes == None: votes = '0'

                try: mpaa = item['certification']
                except: mpaa = '0'
                if mpaa == None: mpaa = '0'

                try: plot = item['overview']
                except: plot = '0'
                if plot == None: plot = '0'
                plot = client.replaceHTMLCodes(plot)

                try: tagline = item['tagline']
                except: tagline = '0'
                if tagline == None: tagline = '0'
                tagline = client.replaceHTMLCodes(tagline)

                self.list.append({'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'plot': plot, 'tagline': tagline, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': '0', 'poster': '0', 'next': next})
            except:
                pass

        return self.list
示例#9
0
    def get(self, name, season, episode, imdb, year='0'):
        offset = '0'

        if control.setting('bookmarks') == 'true':
            if control.setting('bookmarks.trakt') == 'true':
                try:
                    from resources.lib.modules import trakt

                    if not episode is None:

                        # Looking for a Episode progress

                        traktInfo = trakt.getTraktAsJson('https://api.trakt.tv/sync/playback/episodes?extended=full')
                        for i in traktInfo:
                            if imdb == i['show']['ids']['imdb']:
                                # Checking Episode Number
                                if int(season) == i['episode']['season'] and int(episode) == i['episode']['number']:
                                    # Calculating Offset to seconds
                                    offset = (float(i['progress'] / 100) * int(i['episode']['runtime']) * 60)
                    else:

                        # Looking for a Movie Progress
                        traktInfo = trakt.getTraktAsJson('https://api.trakt.tv/sync/playback/episodes?extended=full')
                        for i in traktInfo:
                            if imdb == i['movie']['ids']['imdb']:
                                # Calculating Offset to seconds
                                offset = (float(i['progress'] / 100) * int(i['movie']['runtime']) * 60)

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

                    if control.setting('bookmarks.auto') == 'false':
                        try:
                            yes = control.dialog.contextmenu(["Fortsetzen", "Vom Anfang abspielen", ])
                        except:
                            yes = control.yesnoDialog("Fortsetzen", '', '', str(name), "Fortsetzen",
                                                      "Vom Anfang abspielen")
                        if yes: offset = '0'

                    return offset

                except:
                    return '0'
            else:
                try:
                    offset = '0'

                    if not control.setting('bookmarks') == 'true': raise Exception()

                    idFile = hashlib.md5()
                    for i in name: idFile.update(str(i))
                    for i in year: idFile.update(str(i))
                    idFile = str(idFile.hexdigest())

                    dbcon = database.connect(control.bookmarksFile)
                    dbcur = dbcon.cursor()
                    dbcur.execute("SELECT * FROM bookmark WHERE idFile = '%s'" % idFile)
                    match = dbcur.fetchone()
                    self.offset = str(match[1])
                    dbcon.commit()
                    if self.offset == '0': raise Exception()

                    minutes, seconds = divmod(float(self.offset), 60);
                    hours, minutes = divmod(minutes, 60)
                    label = '%02d:%02d:%02d' % (hours, minutes, seconds)
                    label = "Fortsetzen ab: %s" % label

                    if control.setting('bookmarks.auto') == 'false':

                        try:
                            yes = control.dialog.contextmenu([label, "Vom Anfang abspielen", ])
                        except:
                            yes = control.yesnoDialog(label, '', '', str(name), "Fortsetzen",
                                                      "Vom Anfang abspielen")
                        if yes: self.offset = '0'

                    return self.offset
                except:
                    return offset
        else:
            return offset
示例#10
0
    def get(self, name, season, episode, imdb, year='0'):
        offset = '0'

        if control.setting('bookmarks') == 'true':
            if control.setting('bookmarks.trakt') == 'true':
                try:
                    from resources.lib.modules import trakt

                    if not episode is None:

                        # Looking for a Episode progress

                        traktInfo = trakt.getTraktAsJson('https://api.trakt.tv/sync/playback/episodes?extended=full')
                        for i in traktInfo:
                            if imdb == i['show']['ids']['imdb']:
                                # Checking Episode Number
                                if int(season) == i['episode']['season'] and int(episode) == i['episode']['number']:
                                    # Calculating Offset to seconds
                                    offset = (float(i['progress'] / 100) * int(i['episode']['runtime']) * 60)
                    else:

                        # Looking for a Movie Progress
                        traktInfo = trakt.getTraktAsJson('https://api.trakt.tv/sync/playback/episodes?extended=full')
                        for i in traktInfo:
                            if imdb == i['movie']['ids']['imdb']:
                                # Calculating Offset to seconds
                                offset = (float(i['progress'] / 100) * int(i['movie']['runtime']) * 60)

                    if control.setting('bookmarks.auto') == 'false':
                        try:
                            yes = control.dialog.contextmenu(["Resume", control.lang(32501).encode('utf-8'), ])
                        except:
                            yes = control.yesnoDialog("Resume", '', '', str(name), control.lang(32503).encode('utf-8'),
                                                      control.lang(32501).encode('utf-8'))
                        if yes: offset = '0'

                    return offset

                except:
                    return '0'
            else:
                try:
                    offset = '0'

                    if not control.setting('bookmarks') == 'true': raise Exception()

                    idFile = hashlib.md5()
                    for i in name: idFile.update(str(i))
                    for i in year: idFile.update(str(i))
                    idFile = str(idFile.hexdigest())

                    dbcon = database.connect(control.bookmarksFile)
                    dbcur = dbcon.cursor()
                    dbcur.execute("SELECT * FROM bookmark WHERE idFile = '%s'" % idFile)
                    match = dbcur.fetchone()
                    self.offset = str(match[1])
                    dbcon.commit()
                    if self.offset == '0': raise Exception()

                    minutes, seconds = divmod(float(self.offset), 60);
                    hours, minutes = divmod(minutes, 60)
                    label = '%02d:%02d:%02d' % (hours, minutes, seconds)
                    label = (control.lang(32502) % label).encode('utf-8')

                    if control.setting('bookmarks.auto') == 'false':

                        try:
                            yes = control.dialog.contextmenu([label, control.lang(32501).encode('utf-8'), ])
                        except:
                            yes = control.yesnoDialog(label, '', '', str(name), control.lang(32503).encode('utf-8'),
                                                      control.lang(32501).encode('utf-8'))
                        if yes: self.offset = '0'

                    return self.offset
                except:
                    return offset
        else:
            return offset
示例#11
0
	def trakt_list(self, url, user):
		list = []
		try:
			q = dict(parse_qsl(urlsplit(url).query))
			q.update({'extended': 'full'})
			q = (urlencode(q)).replace('%2C', ',')
			u = url.replace('?' + urlparse(url).query, '') + '?' + q
			if '/related' in u: u = u + '&limit=20'
			result = trakt.getTraktAsJson(u)
			if not result: return list
			items = []
			for i in result:
				try:
					movie = i['movie']
					movie['added'] = i.get('listed_at') # for watchlist----confimed it's in response
					movie['paused_at'] = i.get('paused_at', '') # for history
					try: movie['progress'] = max(0, min(1, i['progress'] / 100.0))
					except: movie['progress'] = ''
					try: movie['lastplayed'] = i.get('watched_at', '')
					except: movie['lastplayed'] = ''
					items.append(movie)
				except: pass
			if len(items) == 0: items = result
		except:
			log_utils.error()
			return
		try:
			q = dict(parse_qsl(urlsplit(url).query))
			if int(q['limit']) != len(items): raise Exception()
			q.update({'page': str(int(q['page']) + 1)})
			q = (urlencode(q)).replace('%2C', ',')
			next = url.replace('?' + urlparse(url).query, '') + '?' + q
		except: next = ''

		def items_list(item):
			try:
				values = item
				values['next'] = next 
				values['title'] = py_tools.ensure_str(item.get('title'))
				values['originaltitle'] = values['title']
				try: values['premiered'] = item.get('released', '')[:10]
				except: values['premiered'] = ''
				values['year'] = str(item.get('year', '')) if item.get('year') else ''
				if not values['year']:
					try: values['year'] = str(values['premiered'][:4])
					except: values['year'] = ''
				ids = item.get('ids', {})
				values['imdb'] = str(ids.get('imdb', '')) if ids.get('imdb') else ''
				values['tmdb'] = str(ids.get('tmdb', '')) if ids.get('tmdb') else ''
				values['tvdb'] = ''
				# values['studio'] = item.get('network', '') # do not set, some skins show studio icons in place of thumb and looks like dog shit
				values['genre'] = []
				for x in item['genres']: values['genre'].append(x.title())
				if not values['genre']: values['genre'] = 'NA'
				values['duration'] = int(item.get('runtime') * 60) if item.get('runtime') else ''
				values['rating'] = item.get('rating')
				values['votes'] = item['votes']
				values['mpaa'] = item.get('certification', '')
				values['plot'] = py_tools.ensure_str(item.get('overview'))
				values['poster'] = ''
				values['fanart'] = ''
				try: values['trailer'] = control.trailer % item['trailer'].split('v=')[1]
				except: values['trailer'] = ''
				for k in ('released', 'ids', 'genres', 'runtime', 'certification', 'overview', 'comment_count', 'network'): values.pop(k, None) # pop() keys that are not needed anymore
				list.append(values)
			except:
				log_utils.error()
		threads = []
		for item in items: threads.append(workers.Thread(items_list, item))
		[i.start() for i in threads]
		[i.join() for i in threads]
		return list
示例#12
0
    def get(self, name, season, episode, imdb, year='0'):
        offset = '0'

        if control.setting(
                'rersume.source') == '1' and trakt.getTraktCredentialsInfo(
                ) == True:
            try:

                if not episode is None:

                    # Looking for a Episode progress
                    traktInfo = trakt.getTraktAsJson(
                        'https://api.trakt.tv/sync/playback/episodes?extended=full'
                    )
                    for i in traktInfo:
                        if imdb == i['show']['ids']['imdb']:
                            # Checking Episode Number
                            if int(season) == i['episode']['season'] and int(
                                    episode) == i['episode']['number']:
                                # Calculating Offset to seconds
                                offset = (float(i['progress'] / 100) *
                                          int(i['episode']['runtime']) * 60)
                                seekable = 1 < i['progress'] < 95
                                if not seekable:
                                    offset = '0'
                else:

                    # Looking for a Movie Progress
                    traktInfo = trakt.getTraktAsJson(
                        'https://api.trakt.tv/sync/playback/movies?extended=full'
                    )
                    for i in traktInfo:
                        if imdb == i['movie']['ids']['imdb']:
                            # Calculating Offset to seconds
                            offset = (float(i['progress'] / 100) *
                                      int(i['movie']['runtime']) * 60)
                            seekable = 1 < i['progress'] < 95
                            if not seekable:
                                offset = '0'

                return offset

            except:
                return '0'

        else:
            try:
                offset = '0'

                idFile = hashlib.md5()
                for i in name:
                    idFile.update(str(i))
                for i in year:
                    idFile.update(str(i))
                idFile = str(idFile.hexdigest())

                dbcon = database.connect(control.bookmarksFile)
                dbcur = dbcon.cursor()
                dbcur.execute("SELECT * FROM bookmark WHERE idFile = '%s'" %
                              idFile)
                match = dbcur.fetchone()
                self.offset = str(match[1])
                dbcon.commit()
                if self.offset == '0':
                    raise Exception()

                return self.offset
            except:
                return offset
示例#13
0
    def trakt_list(self, url, user):
        from resources.lib.modules import client
        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            q.update({'extended': 'full'})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            u = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q

            result = trakt.getTraktAsJson(u)

            items = []
            for i in result:
                try: items.append(i['movie'])
                except: pass
            if len(items) == 0:
                items = result
        except:
            return

        try:
            q = dict(urlparse.parse_qsl(urlparse.urlsplit(url).query))
            if not int(q['limit']) == len(items): raise Exception()
            q.update({'page': str(int(q['page']) + 1)})
            q = (urllib.urlencode(q)).replace('%2C', ',')
            next = url.replace('?' + urlparse.urlparse(url).query, '') + '?' + q
            next = next.encode('utf-8')
        except:
            next = ''

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

                year = item['year']
                year = re.sub('[^0-9]', '', str(year))

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

                imdb = item['ids']['imdb']
                log_utils.log('MovieShit - trakt_list - imdb: ' + str(imdb))
                if imdb == None or imdb == '': raise Exception()
                imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))

                tmdb = str(item.get('ids', {}).get('tmdb', 0))

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

                try: genre = item['genres']
                except: genre = '0'
                genre = [i.title() for i in genre]
                if genre == []: genre = '0'
                genre = ' / '.join(genre)

                try: duration = str(item['runtime'])
                except: duration = '0'
                if duration == None: duration = '0'

                try: rating = str(item['rating'])
                except: rating = '0'
                if rating == None or rating == '0.0': rating = '0'

                try: votes = str(item['votes'])
                except: votes = '0'
                try: votes = str(format(int(votes),',d'))
                except: pass
                if votes == None: votes = '0'

                try: mpaa = item['certification']
                except: mpaa = '0'
                if mpaa == None: mpaa = '0'

                try: plot = item['overview']
                except: plot = '0'
                if plot == None: plot = '0'
                plot = client.replaceHTMLCodes(plot)

                try: tagline = item['tagline']
                except: tagline = '0'
                if tagline == None: tagline = '0'
                tagline = client.replaceHTMLCodes(tagline)

                self.list.append({'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'plot': plot, 'tagline': tagline, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': '0', 'poster': '0', 'next': next})
            except:
                pass

        return self.list