Exemplo n.º 1
0
def get_library_subfolders(folder_name):
    """Returns all the subfolders contained in a folder of library path"""
    section_path = common.join_folders_paths(get_library_path(), folder_name)
    return [
        common.join_folders_paths(section_path, G.py2_decode(folder))
        for folder in common.list_dir(section_path)[0]
    ]
def get_library_subfolders(folder_name, custom_lib_path=None):
    """Returns all the subfolders contained in a folder of library path"""
    section_path = common.join_folders_paths(
        custom_lib_path or get_library_path(), folder_name)
    return [
        common.join_folders_paths(section_path, folder)
        for folder in common.list_dir(section_path)[0]
    ]
Exemplo n.º 3
0
    def remove_item(self, job_data, library_home=None):  # pylint: disable=unused-argument
        """Remove an item from the Kodi library, delete it from disk, remove add-on database references"""
        videoid = job_data['videoid']
        LOG.debug('Removing {} ({}) from add-on library', videoid,
                  job_data['title'])
        try:
            # Remove the STRM file exported
            exported_file_path = G.py2_decode(
                xbmc.translatePath(job_data['file_path']))
            common.delete_file_safe(exported_file_path)

            parent_folder = G.py2_decode(
                xbmc.translatePath(os.path.dirname(exported_file_path)))

            # Remove the NFO file of the related STRM file
            nfo_file = os.path.splitext(exported_file_path)[0] + '.nfo'
            common.delete_file_safe(nfo_file)

            dirs, files = common.list_dir(parent_folder)

            # Remove the tvshow NFO file (only when it is the last file in the folder)
            tvshow_nfo_file = common.join_folders_paths(
                parent_folder, 'tvshow.nfo')

            # (users have the option of removing even single seasons)
            if xbmcvfs.exists(tvshow_nfo_file) and not dirs and len(
                    files) == 1:
                xbmcvfs.delete(tvshow_nfo_file)
                # Delete parent folder
                xbmcvfs.rmdir(parent_folder)

            # Delete parent folder when empty
            if not dirs and not files:
                xbmcvfs.rmdir(parent_folder)

            # Remove videoid records from add-on database
            remove_videoid_from_db(videoid)
        except ItemNotFound:
            LOG.warn(
                'The videoid {} not exists in the add-on library database',
                videoid)
        except Exception as exc:  # pylint: disable=broad-except
            import traceback
            LOG.error(G.py2_decode(traceback.format_exc(), 'latin-1'))
            ui.show_addon_error_info(exc)
 def import_videoid_from_existing_strm(self, folder_path, folder_name):
     """
     Get a VideoId from an existing STRM file that was exported
     """
     for filename in common.list_dir(folder_path)[1]:
         filename = G.py2_decode(filename)
         if not filename.endswith('.strm'):
             continue
         file_path = common.join_folders_paths(folder_path, filename)
         # Only get a VideoId from the first file in each folder.
         # For tv shows all episodes will result in the same VideoId, the movies only contain one file.
         file_content = common.load_file(file_path)
         if not file_content:
             common.warn('Import error: folder "{}" skipped, STRM file empty or corrupted', folder_name)
             return None
         if 'action=play_video' in file_content:
             common.debug('Trying to import (v0.13.x): {}', file_path)
             return self._import_videoid_old(file_content, folder_name)
         common.debug('Trying to import: {}', file_path)
         return self._import_videoid(file_content, folder_name)