예제 #1
0
def genres_choice(db_type, genres, poster, return_genres=False):
    from modules.meta_lists import movie_genres, tvshow_genres

    def _process_dicts(genre_str, _dict):
        final_genres_list = []
        append = final_genres_list.append
        for key, value in _dict.items():
            if key in genre_str: append({'genre': key, 'value': value})
        return final_genres_list

    if db_type in ('movie', 'movies'):
        genre_action, meta_type, action = movie_genres, 'movie', 'tmdb_movies_genres'
    else:
        genre_action, meta_type, action = tvshow_genres, 'tvshow', 'tmdb_tv_genres'
    genre_list = _process_dicts(genres, genre_action)
    if return_genres: return genre_list
    if len(genre_list) == 0:
        kodi_utils.notification(32760, 2500)
        return None
    mode = 'build_%s_list' % meta_type
    items = [{
        'line':
        item['genre'],
        'function':
        json.dumps({
            'mode': mode,
            'action': action,
            'genre_id': item['value'][0]
        })
    } for item in genre_list]
    return open_window(['windows.extras', 'ShowSelectMedia'],
                       'select_media.xml',
                       items=items,
                       poster=poster)
예제 #2
0
def imdb_keywords_choice(db_type, imdb_id, poster):
    from apis.imdb_api import imdb_keywords

    def _builder():
        for item in keywords_info:
            obj = {
                'line':
                item,
                'function':
                json.dumps({
                    'mode': mode,
                    'action': 'imdb_keywords_list_contents',
                    'list_id': item,
                    'iconImage': 'imdb.png'
                })
            }
            yield obj

    kodi_utils.show_busy_dialog()
    keywords_info = imdb_keywords(imdb_id)
    if len(keywords_info) == 0:
        kodi_utils.hide_busy_dialog()
        kodi_utils.notification(32760, 2500)
        return None
    meta_type = 'movie' if db_type == 'movies' else 'tvshow'
    mode = 'build_%s_list' % meta_type
    items = list(_builder())
    kodi_utils.hide_busy_dialog()
    return open_window(['windows.extras', 'ShowSelectMedia'],
                       'select_media.xml',
                       items=items,
                       poster=poster,
                       context_active_action='keywords')
예제 #3
0
def clean_databases(current_time=None, database_check=True, silent=False):
    def _process(args):
        try:
            dbcon = database.connect(args[0], timeout=60.0)
            dbcur = dbcon.cursor()
            dbcur.execute('''PRAGMA synchronous = OFF''')
            dbcur.execute('''PRAGMA journal_mode = OFF''')
            dbcur.execute(args[1], (current_time, ))
            dbcon.commit()
            dbcur.execute('VACUUM')
            dbcon.close()
        except:
            pass

    if database_check: check_databases()
    if not current_time: current_time = get_current_time()
    command_base = 'DELETE from %s WHERE CAST(%s AS INT) <= ?'
    functions_list = []
    functions_list_append = functions_list.append
    functions_list_append(
        (external_db, command_base % ('results_data', 'expires')))
    functions_list_append(
        (maincache_db, command_base % ('maincache', 'expires')))
    functions_list_append(
        (metacache_db, command_base % ('metadata', 'expires')))
    functions_list_append(
        (metacache_db, command_base % ('function_cache', 'expires')))
    functions_list_append(
        (metacache_db, command_base % ('season_metadata', 'expires')))
    functions_list_append(
        (debridcache_db, command_base % ('debrid_data', 'expires')))
    threads = list(make_thread_list(_process, functions_list, Thread))
    [i.join() for i in threads]
    if not silent: notification(32576, time=2000)
예제 #4
0
def remove_all_history(params):
    db_type = params['db_type']
    if not kodi_utils.confirm_dialog(): return
    all_history = Discover({}).history(db_type, display=False)
    for item in all_history:
        remove_from_history({'data_id': item, 'silent': True})
    kodi_utils.notification(32576)
예제 #5
0
	def remove_from_favourites(self):
		dbcon = database.connect(self.fav_database)
		dbcon.execute("DELETE FROM favourites where db_type=? and tmdb_id=?", (self.db_type, str(self.tmdb_id)))
		dbcon.commit()
		dbcon.close()
		execute_builtin('Container.Refresh')
		notification(32576, 3500)
예제 #6
0
def batch_mark_kodi_library(action, insert_list, title, year):
    from modules.kodi_library import get_library_video, batch_mark_episodes_as_watched_unwatched_kodi_library
    in_library = get_library_video('tvshow', title, year)
    if not in_library: return
    if batch_mark_episodes_as_watched_unwatched_kodi_library(
            action, in_library, insert_list):
        kodi_utils.notification(32787, time=5000)
예제 #7
0
 def export(self):
     try:
         db_type = self.discover_params['db_type']
         query = self.discover_params['final_string']
         name = self.discover_params['name']
         set_history(db_type, name, query)
         if db_type == 'movie':
             mode = 'build_movie_list'
             action = 'tmdb_movies_discover'
         else:
             mode = 'build_tvshow_list'
             action = 'tmdb_tv_discover'
         final_params = {
             'name': name,
             'mode': mode,
             'action': action,
             'query': query,
             'iconImage': 'discover.png'
         }
         url_params = {
             'mode': 'navigator.adjust_main_lists',
             'method': 'add_external',
             'list_name': name,
             'menu_item': json.dumps(final_params)
         }
         kodi_utils.execute_builtin('RunPlugin(%s)' %
                                    self._build_url(url_params))
     except:
         kodi_utils.notification(32574)
예제 #8
0
	def add_to_favourites(self):
		try:
			dbcon = database.connect(self.fav_database)
			dbcon.execute("INSERT INTO favourites VALUES (?, ?, ?)", (self.db_type, str(self.tmdb_id), to_unicode(self.title)))
			dbcon.commit()
			dbcon.close()
			notification(32576, 3500)
		except: notification(32574, 3500)
예제 #9
0
def add_to_collection(data):
    result = call_trakt('/sync/collection', data=data)
    if result['added']['movies'] > 0: db_type = 'movie'
    elif result['added']['episodes'] > 0: db_type = 'tvshow'
    else: return kodi_utils.notification(32574, 3000)
    kodi_utils.notification(32576, 6000)
    trakt_sync_activities()
    return result
예제 #10
0
def toggle_jump_to():
    from modules.settings import nav_jump_use_alphabet
    (setting,
     new_action) = ('0', ls(32022)) if nav_jump_use_alphabet() else ('1',
                                                                     ls(32023))
    set_setting('nav_jump', setting)
    kodi_utils.execute_builtin('Container.Refresh')
    kodi_utils.notification(ls(32851) % new_action)
예제 #11
0
def add_to_list(user, slug, data):
    result = call_trakt('/users/%s/lists/%s/items' % (user, slug), data=data)
    if result['added']['shows'] > 0 or result['added']['movies'] > 0:
        kodi_utils.notification(32576, 3000)
        trakt_sync_activities()
    else:
        kodi_utils.notification(32574, 3000)
    return result
예제 #12
0
def manual_add_magnet_to_cloud(params):
    show_busy_dialog()
    function = [i[2] for i in debrid_list if i[0] == params['provider']][0]
    result = function.create_transfer(params['magnet_url'])
    function.clear_cache()
    hide_busy_dialog()
    if result == 'failed': notification(32490)
    else: notification(32576)
예제 #13
0
def delete_trakt_list(params):
    user = params['user']
    list_slug = params['list_slug']
    if not kodi_utils.confirm_dialog(): return
    url = 'users/%s/lists/%s' % (user, list_slug)
    call_trakt(url, is_delete=True)
    trakt_sync_activities()
    kodi_utils.notification(32576, 3000)
    kodi_utils.execute_builtin('Container.Refresh')
예제 #14
0
def remove_from_collection(data):
    result = call_trakt('/sync/collection/remove', data=data)
    if result['deleted']['movies'] > 0: db_type = 'movie'
    elif result['deleted']['episodes'] > 0: db_type = 'tvshow'
    else: return kodi_utils.notification(32574, 3000)
    kodi_utils.notification(32576, 3000)
    trakt_sync_activities()
    kodi_utils.execute_builtin('Container.Refresh')
    return result
예제 #15
0
def remove_from_files(item_id):
    if not kodi_utils.confirm_dialog(): return
    response = Furk.file_unlink(item_id)
    if Furk.check_status(response):
        kodi_utils.notification(32576, 3500)
        kodi_utils.execute_builtin('Container.Refresh')
    else:
        kodi_utils.notification(32574, 3500)
    return (None, None)
예제 #16
0
def remove_from_list(user, slug, data):
    result = call_trakt('/users/%s/lists/%s/items/remove' % (user, slug),
                        data=data)
    if result['deleted']['shows'] > 0 or result['deleted']['movies'] > 0:
        kodi_utils.notification(32576, 3000)
        trakt_sync_activities()
        kodi_utils.execute_builtin('Container.Refresh')
    else:
        kodi_utils.notification(32574, 3000)
    return result
예제 #17
0
def remove_from_history(params):
    cache_file = kodi_utils.translate_path(
        'special://profile/addon_data/plugin.video.fen/maincache.db')
    dbcon = database.connect(cache_file)
    dbcur = dbcon.cursor()
    dbcur.execute("DELETE FROM maincache WHERE id=?", (params['data_id'], ))
    dbcon.commit()
    kodi_utils.clear_property(params['data_id'])
    kodi_utils.execute_builtin('Container.Refresh')
    if not params['silent']: kodi_utils.notification(32576)
예제 #18
0
 def _get(self, url, stream=False, retry=False):
     response = requests.get(url, headers=self.headers, stream=stream)
     if '200' in str(response):
         return response
     elif '429' in str(response) and retry:
         notification(32740, 3500)
         sleep(10000)
         return self._get(url, stream)
     else:
         return
예제 #19
0
def trakt_like_a_list(params):
    user = params['user']
    list_slug = params['list_slug']
    try:
        call_trakt('/users/%s/lists/%s/like' % (user, list_slug),
                   method='post')
        kodi_utils.notification(32576, 3000)
        trakt_sync_activities()
    except:
        kodi_utils.notification(32574, 3000)
예제 #20
0
def myfiles_protect_unprotect(action, name, item_id):
    is_protected = '1' if action == 'protect' else '0'
    try:
        response = Furk.file_protect(item_id, is_protected)
        if Furk.check_status(response):
            kodi_utils.execute_builtin('Container.Refresh')
            return kodi_utils.notification(32576)
        else:
            kodi_utils.notification(32574)
    except:
        return
예제 #21
0
def make_new_trakt_list(params):
    from urllib.parse import unquote
    mode = params['mode']
    list_title = kodi_utils.dialog.input('Fen')
    if not list_title: return
    list_name = unquote(list_title)
    data = {'name': list_name, 'privacy': 'private', 'allow_comments': False}
    call_trakt('users/me/lists', data=data)
    trakt_sync_activities()
    kodi_utils.notification(32576, 3000)
    kodi_utils.execute_builtin('Container.Refresh')
예제 #22
0
def trakt_unlike_a_list(params):
    user = params['user']
    list_slug = params['list_slug']
    try:
        call_trakt('/users/%s/lists/%s/like' % (user, list_slug),
                   method='delete')
        kodi_utils.notification(32576, 3000)
        trakt_sync_activities()
        kodi_utils.execute_builtin('Container.Refresh')
    except:
        kodi_utils.notification(32574, 3000)
예제 #23
0
def remove_from_search_history(params):
    try:
        result = main_cache.get(params['setting_id'])
        result.remove(params.get('query'))
        main_cache.set(params['setting_id'],
                       result,
                       expiration=EXPIRES_365_DAYS)
        kodi_utils.notification(32576, 3500)
        kodi_utils.execute_builtin('Container.Refresh')
    except:
        return
예제 #24
0
def remove_from_downloads(item_id):
    if not kodi_utils.confirm_dialog(): return
    response = Furk.download_unlink(item_id)
    if Furk.check_status(response):
        main_cache.set('furk_active_downloads',
                       None,
                       expiration=EXPIRES_1_HOUR)
        kodi_utils.notification(32576, 3500)
    else:
        kodi_utils.notification(32574, 3500)
    return (None, None)
예제 #25
0
    def process_torrents(self, torrent_sources):
        def _return_early(return_list=torrent_sources):
            try:
                self.kill_progress_dialog()
            except:
                pass
            return return_list

        if len(torrent_sources) == 0: return _return_early()
        if len(self.debrid_torrents) == 0: return _return_early([])
        torrent_sources = sorted(
            torrent_sources,
            key=lambda x:
            (x.get('package') == 'show', x.get('package') == 'season'),
            reverse=True)
        hashList = []
        hashList_append = hashList.append
        for i in torrent_sources:
            try:
                infoHash = i['hash']
                if len(infoHash) == 40: hashList_append(infoHash)
                else:
                    converted_hash = base32_to_hex(infoHash)
                    if converted_hash: hashList_append(converted_hash)
                    else: torrent_sources.remove(i)
            except:
                torrent_sources.remove(i)
        if len(torrent_sources) == 0: return _return_early()
        try:
            torrent_results = []
            hashList = list(set(hashList))
            cached_hashes = debrid_check.run(hashList, self.background,
                                             self.debrid_torrents, self.meta,
                                             self.progress_dialog)
            for item in debrid_hash_tuple:
                if item[0] in self.debrid_torrents:
                    torrent_results.extend([
                        dict(i, **{'cache_provider': item[0]})
                        for i in torrent_sources
                        if i['hash'] in cached_hashes[item[1]]
                    ])
                    if self.display_uncached_torrents:
                        torrent_results.extend([
                            dict(i,
                                 **{'cache_provider': 'Uncached %s' % item[0]})
                            for i in torrent_sources
                            if not i['hash'] in cached_hashes[item[1]]
                        ])
            return torrent_results
        except:
            self.kill_progress_dialog()
            kodi_utils.notification(32574, 2500)
예제 #26
0
 def make_person_data(self):
     if self.kwargs['query']:
         try:
             self.person_id = tmdb_people_info(
                 self.kwargs['query'])[0]['id']
         except:
             notification(32760)
     else:
         self.person_id = self.kwargs['actor_id']
     person_info = tmdb_people_full_info(self.person_id)
     if person_info.get('biography', None) in ('', None):
         person_info = tmdb_people_full_info(self.person_id, 'en')
     self.person_name = person_info['name']
     image_path = person_info['profile_path']
     if image_path:
         self.person_image = tmdb_image_base % ('h632', image_path)
     else:
         self.person_image = backup_cast_thumbnail
     gender = person_info.get('gender')
     if gender: self.person_gender = gender_dict[gender]
     else: self.person_gender = ''
     place_of_birth = person_info.get('place_of_birth')
     if place_of_birth: self.person_place_of_birth = place_of_birth
     else: self.person_place_of_birth = ''
     biography = person_info.get('biography')
     if biography: self.person_biography = biography
     else: self.person_biography = ls(32760)
     birthday = person_info.get('birthday')
     if birthday: self.person_birthday = birthday
     else: self.person_birthday = ''
     deathday = person_info.get('deathday')
     if deathday: self.person_deathday = deathday
     else: self.person_deathday = ''
     if self.person_deathday:
         self.person_age = calculate_age(self.person_birthday, '%Y-%m-%d',
                                         self.person_deathday)
     elif self.person_birthday:
         self.person_age = calculate_age(self.person_birthday, '%Y-%m-%d')
     else:
         self.person_age = ''
     self.imdb_id = person_info['imdb_id']
     more_from_data = person_info['combined_credits']
     acting_data = more_from_data['cast']
     directing_data = more_from_data['crew']
     self.movie_data = [
         i for i in acting_data if i['media_type'] == 'movie'
     ]
     self.tvshow_data = [i for i in acting_data if i['media_type'] == 'tv']
     self.director_data = [
         i for i in directing_data if i['job'].lower() == 'director'
     ]
예제 #27
0
def refresh_cached_data(db_type, id_type, media_id, tvdb_id, meta_language):
    from caches.meta_cache import metacache
    try:
        metacache.delete(db_type,
                         id_type,
                         media_id,
                         tvdb_id=tvdb_id,
                         meta_language=meta_language)
        if db_type == 'tvshow':
            metacache.delete_all_seasons_memory_cache(media_id)
        kodi_utils.notification(32576)
        kodi_utils.execute_builtin('Container.Refresh')
    except:
        kodi_utils.notification(32574)
예제 #28
0
	def clear_favourites(self):
		favorites = ls(32453)
		fl = [('%s %s' % (ls(32028), ls(32453)), 'movie'), ('%s %s' % (ls(32029), ls(32453)), 'tvshow')]
		list_items = [{'line1': item[0]} for item in fl]
		kwargs = {'items': json.dumps(list_items), 'heading': 'Fen', 'enumerate': 'false', 'multi_choice': 'false', 'multi_line': 'false'}
		self.db_type = select_dialog([item[1] for item in fl], **kwargs)
		if self.db_type == None: return
		if not confirm_dialog(): return
		dbcon = database.connect(self.fav_database)
		dbcon.execute("DELETE FROM favourites WHERE db_type=?", (self.db_type,))
		dbcon.commit()
		dbcon.execute('VACUUM')
		dbcon.close()
		notification(32576, 3000)
예제 #29
0
def batch_mark_as_watched_unwatched(insert_list, action, data_base=WATCHED_DB):
    try:
        dbcon = database.connect(data_base, timeout=40.0)
        if action == 'mark_as_watched':
            dbcon.executemany(
                "INSERT OR IGNORE INTO watched_status VALUES (?, ?, ?, ?, ?, ?)",
                insert_list)
        elif action == 'mark_as_unwatched':
            dbcon.executemany(
                "DELETE FROM watched_status WHERE (db_type = ? and media_id = ? and season = ? and episode = ?)",
                insert_list)
        dbcon.commit()
    except:
        kodi_utils.notification(32574)
예제 #30
0
def mark_as_watched_unwatched_season(params):
    season = int(params.get('season'))
    if season == 0: return kodi_utils.notification(32490)
    action = params.get('action')
    title = params.get('title')
    year = params.get('year')
    tmdb_id = params.get('tmdb_id')
    try:
        tvdb_id = int(params.get('tvdb_id', '0'))
    except:
        tvdb_id = 0
    watched_indicators = settings.watched_indicators()
    insert_list = []
    insert_append = insert_list.append
    kodi_utils.progressDialogBG.create(ls(32577), '')
    if watched_indicators == 1:
        if not trakt_watched_unwatched(action, 'season', tmdb_id, tvdb_id,
                                       season):
            return kodi_utils.notification(32574)
        clear_trakt_collection_watchlist_data('watchlist', 'tvshow')
        data_base = TRAKT_DB
        data_base = TRAKT_DB
    else:
        data_base = WATCHED_DB
    meta_user_info = metadata.retrieve_user_info()
    adjust_hours = settings.date_offset()
    current_date = get_datetime()
    meta = metadata.tvshow_meta('tmdb_id', tmdb_id, meta_user_info)
    ep_data = metadata.season_episodes_meta(season, meta, meta_user_info)
    last_played = get_last_played_value(data_base)
    for count, item in enumerate(ep_data, 1):
        season_number = item['season']
        ep_number = item['episode']
        display = 'S%.2dE%.2d' % (season_number, ep_number)
        episode_date, premiered = adjust_premiered_date(
            item['premiered'], adjust_hours)
        if not episode_date or current_date < episode_date: continue
        kodi_utils.progressDialogBG.update(
            int(float(count) / float(len(ep_data)) * 100), ls(32577),
            '%s' % display)
        insert_append(
            make_batch_insert(action, 'episode', tmdb_id, season_number,
                              ep_number, last_played, title))
    batch_mark_as_watched_unwatched(insert_list, action, data_base)
    batch_erase_bookmark(insert_list, action, watched_indicators)
    kodi_utils.progressDialogBG.close()
    if settings.sync_kodi_library_watchstatus():
        batch_mark_kodi_library(action, insert_list, title, year)
    refresh_container()