Example #1
0
    def imdb_user_list(self, url):
        try:
            result = client.request(url)
            items = client.parseDOM(result, 'li', attrs = {'class': 'ipl-zebra-list__item user-list'})
        except:
            pass

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

                url = client.parseDOM(item, 'a', ret='href')[0]
                url = url.split('/list/', 1)[-1].strip('/')
                url = self.imdblist_link % url
                url = client.replaceHTMLCodes(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
Example #2
0
def sort_list(sort_key, sort_direction, list_data):
    reverse = False if sort_direction == "asc" else True
    if sort_key == "rank":
        return sorted(list_data, key=lambda x: x["rank"], reverse=reverse)
    elif sort_key == "added":
        return sorted(list_data, key=lambda x: x["listed_at"], reverse=reverse)
    elif sort_key == "title":
        return sorted(
            list_data,
            key=lambda x: utils.title_key(x[x["type"]].get("title")),
            reverse=reverse,
        )
    elif sort_key == "released":
        return sorted(list_data,
                      key=lambda x: _released_key(x[x["type"]]),
                      reverse=reverse)
    elif sort_key == "runtime":
        return sorted(list_data,
                      key=lambda x: x[x["type"]].get("runtime", 0),
                      reverse=reverse)
    elif sort_key == "popularity":
        return sorted(list_data,
                      key=lambda x: x[x["type"]].get("votes", 0),
                      reverse=reverse)
    elif sort_key == "percentage":
        return sorted(list_data,
                      key=lambda x: x[x["type"]].get("rating", 0),
                      reverse=reverse)
    elif sort_key == "votes":
        return sorted(list_data,
                      key=lambda x: x[x["type"]].get("votes", 0),
                      reverse=reverse)
    else:
        return list_data
    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
Example #4
0
def getMovies(query=None):
    if DBURL == None or DBURL == '': 
        control.infoDialog('RemoteDB Address is Empty...', time=3000)
        return
    DBlist = []
    HOSTDB = str(DBURL)
    DBLINK = str(HOSTDB) + "/library.php?action=movies"
    r = requests.get(DBLINK).json()
    for item in r:
        try:
            title = item['title']
            imdb = item['imdb']
            tmdb = item['tmdbtvdb'] 
            year = item['year'] if 'year' in item else '0'
            poster = item['poster'] if 'poster' in item else addonPoster
            fanart = item['fanart'] if 'rating' in item else addonFanart
            rating = item['rating'] if 'rating' in item else '0'
            genre = item['genre'] if 'genre' in item else '0'
            plot = item['plot'] if 'plot' in item else '0'
                                    
            # #print("REMOTEDB items", title, imdb, tmdb, year, poster, fanart, rating, genre, plot)         
            DBlist.append({'title': title, 'originaltitle': title, 'year': year, 'imdb': imdb, 'tmdb': tmdb,'poster': poster , 'fanart': fanart, 'rating':rating, 'genre': genre, 'plot': plot})
        except:pass
    DBlist = sorted(DBlist, key=lambda k: utils.title_key(k['title']))
    if query == None or query == '': movieDirectory(DBlist) 
    else: return DBlist
Example #5
0
    def imdb_user_list(self, url):
        try:
            result = client.request(url)
            items = client.parseDOM(result, 'li', attrs = {'class': 'ipl-zebra-list__item user-list'})
        except:
            pass

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

                url = client.parseDOM(item, 'a', ret='href')[0]
                url = url.split('/list/', 1)[-1].strip('/')
                url = self.imdblist_link % url
                url = client.replaceHTMLCodes(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
Example #6
0
def getTV(query=None):
	if DBURL == None or DBURL == '': 
		control.infoDialog('RemoteDB Address is Empty...', time=3000)
		return
	DBlist = []
	HOSTDB = str(DBURL)
	DBLINK = str(HOSTDB) + "/library.php?action=tv"
	r = requests.get(DBLINK).json()
	print ("TV REMOTE LIST 1", query, r)
	for item in r:
		try:
			title = item['title'].encode('utf-8')
			imdb = item['imdb'].encode('utf-8')
			tvdb = item['tmdbtvdb'].encode('utf-8') 
			year = item['year'].encode('utf-8') if 'year' in item else '0'
			poster = item['poster'].encode('utf-8') if 'poster' in item else addonPoster
			fanart = item['fanart'].encode('utf-8') if 'rating' in item else addonFanart
			rating = item['rating'].encode('utf-8') if 'rating' in item else '0'
			genre = item['genre'].encode('utf-8') if 'genre' in item else '0'
			plot = item['plot'].encode('utf-8') if 'plot' in item else '0'
									
			DBlist.append({'title': title, 'tvshowtitle': title, 'originaltitle': title, 'year': year, 'imdb': imdb, 'tvdb': tvdb,'poster': poster , 'fanart': fanart, 'rating':rating, 'genre': genre, 'plot': plot})
		except:pass
	print ("TV REMOTE LIST 2", DBlist)
	DBlist = sorted(DBlist, key=lambda k: utils.title_key(k['title']))
	print ("TV REMOTE LIST 3", DBlist)
	if query == None or query == '': tvDirectory(DBlist)	
	else: return DBlist	
Example #7
0
def sort_list(sort_key, sort_direction, list_data):
    reverse = False if sort_direction == 'asc' else True
    if sort_key == 'rank':
        return sorted(list_data, key=lambda x: x['rank'], reverse=reverse)
    elif sort_key == 'added':
        return sorted(list_data, key=lambda x: x['listed_at'], reverse=reverse)
    elif sort_key == 'title':
        return sorted(list_data,
                      key=lambda x: utils.title_key(x[x['type']].get('title')),
                      reverse=reverse)
    elif sort_key == 'released':
        return sorted(list_data,
                      key=lambda x: _released_key(x[x['type']]),
                      reverse=reverse)
    elif sort_key == 'runtime':
        return sorted(list_data,
                      key=lambda x: x[x['type']].get('runtime', 0),
                      reverse=reverse)
    elif sort_key == 'popularity':
        return sorted(list_data,
                      key=lambda x: x[x['type']].get('votes', 0),
                      reverse=reverse)
    elif sort_key == 'percentage':
        return sorted(list_data,
                      key=lambda x: x[x['type']].get('rating', 0),
                      reverse=reverse)
    elif sort_key == 'votes':
        return sorted(list_data,
                      key=lambda x: x[x['type']].get('votes', 0),
                      reverse=reverse)
    else:
        return list_data
Example #8
0
    def get(self, url, idx=True, create_directory=True):
        try:
            try:
                url = getattr(self, url + '_link')
            except:
                pass
            try:
                u = urlparse.urlparse(url).netloc.lower()
            except:
                pass
            if u in self.trakt_link and '/users/' in url:
                try:
                    if url == self.trakthistory_link:
                        raise Exception()
                    if '/users/me/' not in url:
                        raise Exception()
                    if trakt.getActivity() > cache.timeout(self.trakt_list, url, self.trakt_user):
                        raise Exception()
                    self.list = cache.get(self.trakt_list, 720, url, self.trakt_user)
                except:
                    self.list = cache.get(self.trakt_list, 0, url, self.trakt_user)
                if '/users/me/' in url and '/collection/' in url:
                    self.list = sorted(self.list, key=lambda k: utils.title_key(k['title']))

                if idx is True:
                    self.worker()

            elif u in self.trakt_link and self.search_link in url:
                self.list = cache.get(self.trakt_list, 1, url, self.trakt_user)
                if idx is True:
                    self.worker(level=0)

            elif u in self.trakt_link:
                self.list = cache.get(self.trakt_list, 24, url, self.trakt_user)
                if idx is True:
                    self.worker()

            elif u in self.imdb_link and ('/user/' in url or '/list/' in url):
                self.list = cache.get(self.imdb_list, 0, url)
                if idx is True:
                    self.worker()

            elif u in self.imdb_link:
                self.list = cache.get(self.imdb_list, 24, url)
                if idx is True:
                    self.worker()

            if idx is True and create_directory is True:
                self.movieDirectory(self.list)
            return self.list
        except:
            pass
Example #9
0
    def get(self, url, idx=True, create_directory=True):
        try:
            try: url = getattr(self, url + '_link')
            except: pass

            try: u = urlparse.urlparse(url).netloc.lower()
            except: pass


            if u in self.trakt_link and '/users/' in url:
                try:
                    if url == self.trakthistory_link: raise Exception()
                    if not '/users/me/' in url: raise Exception()
                    if trakt.getActivity() > cache.timeout(self.trakt_list, url, self.trakt_user): raise Exception()
                    self.list = cache.get(self.trakt_list, 720, url, self.trakt_user)
                except:
                    self.list = cache.get(self.trakt_list, 0, url, self.trakt_user)

                if '/users/me/' in url and '/collection/' in url:
                    self.list = sorted(self.list, key=lambda k: utils.title_key(k['title']))

                if idx == True: self.worker()

            elif u in self.trakt_link and self.search_link in url:
                self.list = cache.get(self.trakt_list, 1, url, self.trakt_user)
                if idx == True: self.worker(level=0)

            elif u in self.trakt_link:
                self.list = cache.get(self.trakt_list, 24, url, self.trakt_user)
                if idx == True: self.worker()


            elif u in self.imdb_link and ('/user/' in url or '/list/' in url):
                self.list = cache.get(self.imdb_list, 0, url)
                if idx == True: self.worker()

            elif u in self.imdb_link:
                self.list = cache.get(self.imdb_list, 24, url)
                if idx == True: self.worker()


            if self.list == None or len(self.list) == 0:
                control.idle()
                control.infoDialog(control.lang(32709).encode('utf-8'), time=8000)
            elif idx == True and create_directory == True:
                    self.movieDirectory(self.list)
            return self.list
        except:
            pass
Example #10
0
    def get(self, url, idx=True, create_directory=True):
        try:
            try: url = getattr(self, url + '_link')
            except: pass

            try: u = urlparse.urlparse(url).netloc.lower()
            except: pass


            if u in self.trakt_link and '/users/' in url:
                try:
                    if not '/users/me/' in url: raise Exception()
                    if trakt.getActivity() > cache.timeout(self.trakt_list, url, self.trakt_user): raise Exception()
                    self.list = cache.get(self.trakt_list, 720, url, self.trakt_user)
                except:
                    self.list = cache.get(self.trakt_list, 0, url, self.trakt_user)

                if '/users/me/' in url and '/collection/' in url:
                    self.list = sorted(self.list, key=lambda k: utils.title_key(k['title']))

                if idx == True: self.worker()

            elif u in self.trakt_link and self.search_link in url:
                self.list = cache.get(self.trakt_list, 1, url, self.trakt_user)
                if idx == True: self.worker(level=0)

            elif u in self.trakt_link:
                self.list = cache.get(self.trakt_list, 24, url, self.trakt_user)
                if idx == True: self.worker()


            elif u in self.imdb_link and ('/user/' in url or '/list/' in url):
                self.list = cache.get(self.imdb_list, 0, url)
                if idx == True: self.worker()

            elif u in self.imdb_link:
                self.list = cache.get(self.imdb_list, 24, url)
                if idx == True: self.worker()


            elif u in self.tvmaze_link:
                self.list = cache.get(self.tvmaze_list, 168, url)
                if idx == True: self.worker()


            if idx == True and create_directory == True: self.tvshowDirectory(self.list)
            return self.list
        except:
            pass
    def get(self, url, idx=True, create_directory=True):
        try:
            try: url = getattr(self, url + '_link')
            except: pass

            try: u = urlparse.urlparse(url).netloc.lower()
            except: pass

            log_utils.log(u)

            if u in self.trakt_link and '/users/' in url:
                try:
                    if not '/users/me/' in url: raise Exception()
                    if trakt.getActivity() > cache.timeout(self.trakt_list, url, self.trakt_user): raise Exception()
                    self.list = cache.get(self.trakt_list, 720, url, self.trakt_user)
                except:
                    self.list = cache.get(self.trakt_list, 0, url, self.trakt_user)

                if '/users/me/' in url and '/collection/' in url:
                    self.list = sorted(self.list, key=lambda k: utils.title_key(k['title']))

                if idx == True: self.worker()

            elif u in self.trakt_link and self.search_link in url:
                self.list = cache.get(self.trakt_list, 1, url, self.trakt_user)
                if idx == True: self.worker(level=0)

            elif u in self.trakt_link:
                self.list = cache.get(self.trakt_list, 24, url, self.trakt_user)
                if idx == True: self.worker()

            elif u in self.imdb_link:
                log_utils.log(url)
                self.list = cache.get(imdb_lists.IMDBLists('tvSeries').get_imdb_url_contents, 0, url, 'tvSeries')
                log_utils.log(self.list)
                if idx == True: self.worker()

            elif u in self.tvmaze_link:
                self.list = cache.get(self.tvmaze_list, 168, url)
                if idx == True: self.worker()


            if idx == True and create_directory == True: self.tvshowDirectory(self.list)
            return self.list
        except:
            pass
Example #12
0
def retrieve_favourites(db_type, page_no, letter, passed_list=[]):
    import ast
    from resources.lib.modules.nav_utils import paginate_list
    from resources.lib.modules.utils import title_key
    limit = 40
    if db_type == 'audio': return Favourites().get_favourites(db_type)
    if not passed_list:
        data = Favourites().get_favourites(db_type)
        data = sorted(data, key=lambda k: title_key(k['title']))
        original_list = [{
            'media_id': i['tmdb_id'],
            'title': i['title']
        } for i in data]
    else:
        original_list = ast.literal_eval(passed_list)
    paginated_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    return paginated_list, original_list, total_pages, limit
Example #13
0
def retrieve_subscriptions(db_type, page_no, letter, passed_list=[]):
    import ast
    from resources.lib.modules.nav_utils import paginate_list
    from resources.lib.modules.utils import title_key
    limit = 40
    if not passed_list:
        data = Subscriptions(db_type).get_subscriptions()
        logger('data', data)
        data = sorted(data, key=lambda k: title_key(k['title']))
        original_list = [{
            'media_id': i['tmdb_id'],
            'title': i['title']
        } for i in data]
    else:
        original_list = ast.literal_eval(passed_list)
    paginated_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    return paginated_list, original_list, total_pages, limit
Example #14
0
def sort_list(sort_key, sort_direction, list_data):
    reverse = False if sort_direction == 'asc' else True
    if sort_key == 'rank':
        return sorted(list_data, key=lambda x: x['rank'], reverse=reverse)
    elif sort_key == 'added':
        return sorted(list_data, key=lambda x: x['listed_at'], reverse=reverse)
    elif sort_key == 'title':
        return sorted(list_data, key=lambda x: utils.title_key(x[x['type']].get('title')), reverse=reverse)
    elif sort_key == 'released':
        return sorted(list_data, key=lambda x: _released_key(x[x['type']]), reverse=reverse)
    elif sort_key == 'runtime':
        return sorted(list_data, key=lambda x: x[x['type']].get('runtime', 0), reverse=reverse)
    elif sort_key == 'popularity':
        return sorted(list_data, key=lambda x: x[x['type']].get('votes', 0), reverse=reverse)
    elif sort_key == 'percentage':
        return sorted(list_data, key=lambda x: x[x['type']].get('rating', 0), reverse=reverse)
    elif sort_key == 'votes':
        return sorted(list_data, key=lambda x: x[x['type']].get('votes', 0), reverse=reverse)
    else:
        return list_data
Example #15
0
File: tmdb.py Project: 7jdope8/icon
def tmdb_tv_actor_roles(actor_id, page_no, letter, passed_list=[]):
    import ast
    from resources.lib.modules.nav_utils import paginate_list
    from resources.lib.modules.utils import title_key
    limit = 40
    if not passed_list:
        string = "%s_%s" % ('tmdb_tv_actor_roles', actor_id)
        url = 'https://api.themoviedb.org/3/person/%s/tv_credits?api_key=%s&language=en-US' % (
            int(actor_id), tmdb_api)
        data = cache_object(get_tmdb, string, url, 4)['cast']
        data = sorted(data, key=lambda k: title_key(k['name']))
        original_list = [{
            'media_id': i['id'],
            'title': i['name']
        } for i in data]
    else:
        original_list = ast.literal_eval(passed_list)
    if page_no == 'None':
        return original_list
    paginated_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    return paginated_list, original_list, total_pages, limit
Example #16
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 get(self, url, idx=True, create_directory=True):
        # Save the current url
        self.url = url
        # Initialize the url params into a dictionary
        self.params = self.params_init(url)

        # New parsing logic for imdb
        if 'imdb' in url:
            if self.params.get('q') == 'imdbUserList':
                if 'listId' in self.params.keys():
                    list_id = self.params['listId']
                    self.list = cache.get(
                        self.imdblists.get_user_list_contents,
                        IMDB_USER_LIST_CACHE_TIMEOUT, list_id)
                else:
                    self.list = cache.get(self.imdblists.get_user_lists,
                                          IMDB_USER_LIST_CACHE_TIMEOUT,
                                          'movie')

            elif self.params.get('q') == 'imdbList':
                # Default to "featured" if listType isnt defined
                list_type = self.params['listType']
                self.list = cache.get(self.imdblists.get_imdb_list_contents,
                                      IMDB_LIST_CACHE_TIMEOUT_LONG, list_type,
                                      self.hidecinema, 'movie')
            elif self.params.get('q') == 'imdb_params':
                imdb_url = self.imdblists.build_imdb_search_url(self.params)
                self.list = cache.get(self.imdblists.get_imdb_url_contents,
                                      IMDB_LIST_CACHE_TIMEOUT_LONG, imdb_url,
                                      'movie')
            # Support for legacy imdb
            else:
                decoded_url = urllib.unquote(url).decode('utf8')
                self.list = cache.get(self.imdblists.get_imdb_url_contents,
                                      IMDB_LIST_CACHE_TIMEOUT_LONG,
                                      decoded_url)

            if idx == True: self.worker()
            if idx == True and create_directory == True:
                self.movieDirectory(self.list)
            return self.list

        # Old parsing logic -- only used for trakt now
        try:
            try:
                url = getattr(self, url + '_link')
            except:
                pass

            try:
                u = urlparse.urlparse(url).netloc.lower()
            except:
                pass

            if u in self.trakt_link and '/users/' in url:
                try:
                    if url == self.trakthistory_link: raise Exception()
                    if not '/users/me/' in url: raise Exception()
                    if trakt.getActivity() > cache.timeout(
                            self.trakt_list, url, self.trakt_user):
                        raise Exception()
                    self.list = cache.get(self.trakt_list, 720, url,
                                          self.trakt_user)
                except:
                    self.list = cache.get(self.trakt_list, 0, url,
                                          self.trakt_user)

                if '/users/me/' in url and '/collection/' in url:
                    self.list = sorted(
                        self.list, key=lambda k: utils.title_key(k['title']))

                if idx == True: self.worker()

            elif u in self.trakt_link and self.search_link in url:
                self.list = cache.get(self.trakt_list, 1, url, self.trakt_user)
                if idx == True: self.worker(level=0)

            elif u in self.trakt_link:
                self.list = cache.get(self.trakt_list, 24, url,
                                      self.trakt_user)
                if idx == True: self.worker()

            if idx == True and create_directory == True:
                self.movieDirectory(self.list)
            return self.list
        except:
            log_utils.log(sys.exc_info())
            pass
Example #18
0
def get_watched_items(db_type, page_no, letter, passed_list=[]):
    import ast
    from resources.lib.modules.nav_utils import paginate_list
    from resources.lib.modules.utils import title_key, to_utf8
    watched_indicators = settings.watched_indicators()
    limit = 40
    if db_type == 'tvshow':
        from resources.lib.indexers.tvshows import aired_episode_number_tvshow
        if watched_indicators in (1, 2):
            if not passed_list:
                from resources.lib.modules.trakt import trakt_indicators_tv
                data = trakt_indicators_tv()
                data = sorted(data, key=lambda tup: title_key(tup[3]))
                original_list = [{
                    'media_id': i[0],
                    'title': i[3]
                } for i in data if i[1] == len(i[2])]
            else:
                original_list = ast.literal_eval(passed_list)
        else:
            if not passed_list:
                from resources.lib.indexers.tvshows import make_fresh_tvshow_meta
                settings.check_database(WATCHED_DB)
                dbcon = database.connect(WATCHED_DB)
                dbcur = dbcon.cursor()
                dbcur.execute(
                    "SELECT media_id, title FROM watched_status WHERE db_type = ?",
                    ('episode', ))
                rows = dbcur.fetchall()
                dbcon.close()
                watched_list = list(set(to_utf8([(i[0], i[1]) for i in rows])))
                data = []
                for item in watched_list:
                    watched = get_watched_status_tvshow(
                        item[0],
                        aired_episode_number_tvshow(
                            make_fresh_tvshow_meta('tmdb_id', item[0])))
                    if watched[0] == 1: data.append(item)
                    else: pass
                data = sorted(data, key=lambda tup: title_key(tup[1]))
                original_list = [{
                    'media_id': i[0],
                    'title': i[1]
                } for i in data]
            else:
                original_list = ast.literal_eval(passed_list)
    else:
        if watched_indicators in (1, 2):
            if not passed_list:
                from resources.lib.modules.trakt import trakt_indicators_movies
                data = trakt_indicators_movies()
                data = sorted(data, key=lambda tup: title_key(tup[1]))
                original_list = [{
                    'media_id': i[0],
                    'title': i[1]
                } for i in data]
            else:
                original_list = ast.literal_eval(passed_list)

        else:
            if not passed_list:
                settings.check_database(WATCHED_DB)
                dbcon = database.connect(WATCHED_DB)
                dbcur = dbcon.cursor()
                dbcur.execute(
                    "SELECT media_id, title FROM watched_status WHERE db_type = ?",
                    (db_type, ))
                rows = dbcur.fetchall()
                dbcon.close()
                data = to_utf8([(i[0], i[1]) for i in rows])
                data = sorted(data, key=lambda tup: title_key(tup[1]))
                original_list = [{
                    'media_id': i[0],
                    'title': i[1]
                } for i in data]
            else:
                original_list = ast.literal_eval(passed_list)
    paginated_list, total_pages = paginate_list(original_list, page_no, letter,
                                                limit)
    return paginated_list, original_list, total_pages, limit
Example #19
0
 def func(function):
     if ne_settings['sort_key'] == 'name': return title_key(function)
     else: return function