def playlist_add_episode(playlist, season, id, season_tag='season', type=''):
    dev.log('playlist_add_episode(' + season + ',' + id + ', type=' + type +
            ')')
    #Check if this playlist isnt in the xml file yet
    #if xml_get_elem('season', 'episode', {'id' : id}, playlist=playlist) is None:
    #Build the playlist
    #doc = playlist_xml_get(playlist)

    #s = doc.find("season[@number='"+season+"']")
    s = xml_get_elem(season_tag,
                     season_tag, {'number': season},
                     playlist=playlist,
                     type=type)
    if s is None:
        playlist_add_season(playlist, season, type=type)
        #doc = playlist_xml_get(playlist)
        #s = doc.find("season[@number='"+season+"']")
        s = xml_get_elem(season_tag,
                         season_tag, {'number': season},
                         playlist=playlist,
                         type=type)

    #doc = playlist_xml_get(playlist)
    global playlistdocument
    attr = {'id': id}
    elem = Element('episode', attr)

    s.insert(0, elem)
    root = playlistdocument.getroot()

    write_xml(root, dir=dev.typeEpnr(type), output=playlist + '.xml')
    dev.log('Added the episode ' + id + ' to ' + season_tag + ': ' + season +
            ' in ' + dev.typeEpnr(type) + '/' + playlist + '.xml')
def playlist_add_episode(playlist, season, id, season_tag='season', type=''):
    dev.log('playlist_add_episode('+season+','+id+', type='+type+')')
    #Check if this playlist isnt in the xml file yet
    #if xml_get_elem('season', 'episode', {'id' : id}, playlist=playlist) is None:
    #Build the playlist
    #doc = playlist_xml_get(playlist)
    
    #s = doc.find("season[@number='"+season+"']")
    s = xml_get_elem(season_tag, season_tag, {'number': season}, playlist=playlist, type=type)
    if s is None:
        playlist_add_season(playlist, season, type=type)
        #doc = playlist_xml_get(playlist)
        #s = doc.find("season[@number='"+season+"']")
        s = xml_get_elem(season_tag, season_tag, {'number': season}, playlist=playlist, type=type)
        
    #doc = playlist_xml_get(playlist)
    global playlistdocument
    attr = { 'id' : id}
    elem = Element('episode', attr)
    
    s.insert(0, elem)
    root = playlistdocument.getroot()
    
    write_xml(root, dir=dev.typeEpnr(type), output=playlist+'.xml')
    dev.log('Added the episode '+id+' to '+season_tag+': '+season+' in '+dev.typeEpnr(type)+'/'+playlist+'.xml')
    #else:
        #dev.log('playlist_add_episode: not added episode '+id+' since the episode already exists')    
def playlist_xml_get(playlist, type=''):
    dev.log('playlist_XML_get('+type+')')
    if xbmcvfs.exists(os.path.join(vars.settingsPath,dev.typeEpnr(type)+"/"+playlist+".xml")) == False: #If the episodes.xml file can't be found, we should create this file
        playlist_create_xml(playlist, type=type)
    
    global playlistdocument #Set the document variable as global, so every function can reach it
    playlistdocument = ElementTree.parse( vars.settingsPath+dev.typeEpnr(type)+'/'+playlist+'.xml' )
    return playlistdocument
def playlist_add_season(playlist, season, season_tag='season', type=''):
    dev.log('playlist_add_season('+season+')')
    #Check if this playlist isnt in the xml file yet
    #if xml_get_elem('season', 'episode', {'id' : id}, playlist=playlist) is None:
    #Build the playlist
    doc = playlist_xml_get(playlist, type=type)
    
    attr = { 'number' : season}
    elem = Element(season_tag, attr)
    root = doc.getroot()
    root.insert(0, elem)
    write_xml(root, dir=dev.typeEpnr(type), output=playlist+'.xml')
    dev.log('Added '+season_tag+': '+season+' in '+dev.typeEpnr(type)+'/'+playlist+'.xml')
def playlist_xml_get(playlist, type=''):
    dev.log('playlist_XML_get(' + type + ')')
    if xbmcvfs.exists(
            os.path.join(vars.settingsPath,
                         dev.typeEpnr(type) + "/" + playlist + ".xml")
    ) == False:  #If the episodes.xml file can't be found, we should create this file
        playlist_create_xml(playlist, type=type)

    global playlistdocument  #Set the document variable as global, so every function can reach it
    playlistdocument = ElementTree.parse(vars.settingsPath +
                                         dev.typeEpnr(type) + '/' + playlist +
                                         '.xml')
    return playlistdocument
def playlist_add_season(playlist, season, season_tag='season', type=''):
    dev.log('playlist_add_season(' + season + ')')
    #Check if this playlist isnt in the xml file yet
    #if xml_get_elem('season', 'episode', {'id' : id}, playlist=playlist) is None:
    #Build the playlist
    doc = playlist_xml_get(playlist, type=type)

    attr = {'number': season}
    elem = Element(season_tag, attr)
    root = doc.getroot()
    root.insert(0, elem)
    write_xml(root, dir=dev.typeEpnr(type), output=playlist + '.xml')
    dev.log('Added ' + season_tag + ': ' + season + ' in ' +
            dev.typeEpnr(type) + '/' + playlist + '.xml')
def delete_playlist(id, type=''):
    #Grab the settings from this playlist
    settings = m_xml.xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type) #Grab the xml settings for this playlist
    if settings is None:
        dev.log('deletePlaylist: Could not find playlist '+id+' in the '+dev.typeXml(type)+' file', True)
        return False
    else:         
        i = xbmcgui.Dialog().yesno("Delete Playlist", "Are you sure you want to delete this playlist?")
        if i == 0:
            editPlaylist(id, type=type)
        else:
            if m_xml.xml_remove_playlist(id, type=type) is True:
                #Remove the episodenr xml file to
                file = os.path.join(vars.settingsPath+dev.typeEpnr(type), id+'.xml' )
                if os.path.isfile(file):
                    success = os.remove(file) #Remove the episodenr xml file
                
                xbmcgui.Dialog().ok('Removed Playlist', 'Succesfully removed playlist '+id)
                i = xbmcgui.Dialog().yesno('Delete from library', 'Do you also want to delete the videos from your library?')
                if i != 0:
                    #Check in which folder the show resides
                    folder = settings.find('overwritefolder').text
                    if folder is None or folder == '':
                        folder = dev.legal_filename(settings.find('title').text) #Overwrite folder is not set in settings.xml, so set the folder to the title of the show
                    else:
                        folder = dev.legal_filename(folder)
                    movieLibrary = vars.tv_folder #Use the directory from the addon settings
                    if type == 'musicvideo':
                        movieLibrary = vars.musicvideo_folder
                    elif type == 'movies':
                        movieLibrary = vars.movies_folder
                    dir = os.path.join(movieLibrary, folder) #Set the folder to the maindir/dir
                    
                    success = shutil.rmtree(dir, ignore_errors=True) #Remove the directory
                    xbmcgui.Dialog().ok('Removed from library', 'Deleted the videos from your library (You should clean your library, otherwise they will still show in your library)')
def delete_playlist(id, type=''):
    #Grab the settings from this playlist
    settings = m_xml.xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type) #Grab the xml settings for this playlist
    if settings is None:
        dev.log('deletePlaylist: Could not find playlist '+id+' in the '+dev.typeXml(type)+' file', True)
        return False
    else:         
        i = xbmcgui.Dialog().yesno("Delete Playlist", "Are you sure you want to delete this playlist?")
        if i == 0:
            editPlaylist(id, type=type)
        else:
            if m_xml.xml_remove_playlist(id, type=type) is True:
                #Remove the episodenr xml file to
                file = os.path.join(vars.settingsPath+dev.typeEpnr(type), id+'.xml' )
                if os.path.isfile(file):
                    success = os.remove(file) #Remove the episodenr xml file
                
                xbmcgui.Dialog().ok('Removed Playlist', 'Succesfully removed playlist '+id)
                i = xbmcgui.Dialog().yesno('Delete from library', 'Do you also want to delete the videos from your library?')
                if i != 0:
                    #Check in which folder the show resides
                    folder = settings.find('overwritefolder').text
                    if folder is None or folder == '':
                        folder = dev.legal_filename(settings.find('title').text) #Overwrite folder is not set in settings.xml, so set the folder to the title of the show
                    else:
                        folder = dev.legal_filename(folder)
                    movieLibrary = vars.tv_folder #Use the directory from the addon settings
                    if type == 'musicvideo':
                        movieLibrary = vars.musicvideo_folder
                    elif type == 'movies':
                        movieLibrary = vars.movies_folder
                    dir = os.path.join(movieLibrary, folder) #Set the folder to the maindir/dir
                    
                    success = shutil.rmtree(dir, ignore_errors=True) #Remove the directory
                    xbmcgui.Dialog().ok('Removed from library', 'Deleted the videos from your library (You should clean your library, otherwise they will still show in your library)')
def playlist_create_xml(playlist, type=''):
    dev.log('playlist_create_xml('+type+')')
    
    #<playlists>
    root = Element('seasons')
    #attr = { 'number' : season }
    #newxml = SubElement(root, 'season', attr)
    #attr = { 'id' : videoId}
    #elem = SubElement(newxml, 'episode', attr)
    
    #playlist = xml_create_playlist(example)
    #Append this playlist to the new created xml file
    #newxml.append(playlist)
    #Write this new xml to the settings.xml file
    write_xml(root, dev.typeEpnr(type), playlist+'.xml')
    dev.log('playlist_create_xml: Created new '+dev.typeEpnr(type)+'/'+playlist+'.xml')
Пример #10
0
def refresh_playlist(id, type=''):
    #Grab the settings from this playlist
    settings = m_xml.xml_get_elem(
        'playlists/playlist', 'playlist', {'id': id},
        type=type)  #Grab the xml settings for this playlist
    if settings is None:
        dev.log(
            'refreshPlaylist: Could not find playlist ' + id + ' in the ' +
            typeXml(type) + ' file', True)
        return False
    else:
        i = xbmcgui.Dialog().yesno(
            "Refresh Playlist",
            "Are you sure you want to refresh this playlist?")
        if i != 0:
            m_xml.xml_update_playlist_setting(id, 'lastvideoId', '', type=type)
            #Delete the .xml containing all scanned videoId's as well
            file = os.path.join(vars.settingsPath, dev.typeEpnr(type))
            file = os.path.join(file, id + '.xml')
            if os.path.isfile(file):
                success = os.remove(file)  #Remove the episodenr xml file

            xbmcgui.Dialog().ok('Refreshed Playlist',
                                'Succesfully refreshed playlist ' + id)
            i = xbmcgui.Dialog().yesno(
                'Delete from library',
                'Do you also want to delete the previous videos from your library?'
            )
            if i != 0:
                #Check in which folder the show resides
                folder = settings.find('overwritefolder').text
                if folder is None or folder == '':
                    folder = dev.legal_filename(
                        settings.find('title').text
                    )  #Overwrite folder is not set in settings.xml, so set the folder to the title of the show
                else:
                    folder = dev.legal_filename(folder)
                movieLibrary = vars.tv_folder  #Use the directory from the addon settings
                if type == 'musicvideo':
                    movieLibrary = vars.musicvideo_folder
                elif type == 'movies':
                    movieLibrary = vars.movies_folder
                dir = os.path.join(movieLibrary,
                                   folder)  #Set the folder to the maindir/dir

                success = shutil.rmtree(
                    dir, ignore_errors=True)  #Remove the directory
                #if vars.update_videolibrary == "true" and type=='':
                #    update_dir = vars.tv_folder_path
                #    if type == 'musicvideo':
                #        update_dir = vars.musicvideo_folder_path
                #    dev.log('Updating video library is enabled. Cleaning librarys directory %s' % update_dir, True)
                #    xbmc.executebuiltin('xbmc.updatelibrary(Video,'+update_dir+')')

                xbmcgui.Dialog().ok(
                    'Removed from library',
                    'Deleted the previous videos from your library (You should clean your library, otherwise they will still show in your library)'
                )
            editPlaylist(id, type=type)  #Load the editplaylist view
def playlist_create_xml(playlist, type=''):
    dev.log('playlist_create_xml(' + type + ')')

    #<playlists>
    root = Element('seasons')
    #attr = { 'number' : season }
    #newxml = SubElement(root, 'season', attr)
    #attr = { 'id' : videoId}
    #elem = SubElement(newxml, 'episode', attr)

    #playlist = xml_create_playlist(example)
    #Append this playlist to the new created xml file
    #newxml.append(playlist)
    #Write this new xml to the settings.xml file
    write_xml(root, dev.typeEpnr(type), playlist + '.xml')
    dev.log('playlist_create_xml: Created new ' + dev.typeEpnr(type) + '/' +
            playlist + '.xml')
def episode_exists(playlist, episode, season_tag='season', episode_tag='episode', type=''):
    dev.log('episode_exists('+playlist+', '+episode+', type='+type+')')
    #Quicker way to check if this episode already exists
    #doc = playlist_xml_get(playlist)
    #e = doc.findall("*/episode[@id='"+episode+"']")
    e = xml_get_elem(season_tag+'/'+episode_tag, episode_tag, {'id' : episode}, playlist=playlist, type=type)
    #if len(e) == 0:
    if e == None:
        dev.log(episode_tag+' '+episode+' is not yet present in '+dev.typeEpnr(type)+' file')
        return False
    dev.log('Already present: '+episode)
    return True
def refresh_playlist(id, type=''):
    #Grab the settings from this playlist
    settings = m_xml.xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type) #Grab the xml settings for this playlist
    if settings is None:
        dev.log('refreshPlaylist: Could not find playlist '+id+' in the '+typeXml(type)+' file', True)
        return False
    else:         
        i = xbmcgui.Dialog().yesno("Refresh Playlist", "Are you sure you want to refresh this playlist?")
        if i != 0:
            m_xml.xml_update_playlist_setting(id, 'lastvideoId', '', type=type)
            #Delete the .xml containing all scanned videoId's as well
            file = os.path.join(vars.settingsPath, dev.typeEpnr(type))
            file = os.path.join(file, id+'.xml')
            if os.path.isfile(file):
                success = os.remove(file) #Remove the episodenr xml file
            
            xbmcgui.Dialog().ok('Refreshed Playlist', 'Succesfully refreshed playlist '+id)
            i = xbmcgui.Dialog().yesno('Delete from library', 'Do you also want to delete the previous videos from your library?')
            if i != 0:
                #Check in which folder the show resides
                folder = settings.find('overwritefolder').text
                if folder is None or folder == '':
                    folder = dev.legal_filename(settings.find('title').text) #Overwrite folder is not set in settings.xml, so set the folder to the title of the show
                else:
                    folder = dev.legal_filename(folder)
                movieLibrary = vars.tv_folder #Use the directory from the addon settings
                if type == 'musicvideo':
                    movieLibrary = vars.musicvideo_folder
                elif type == 'movies':
                    movieLibrary = vars.movies_folder
                dir = os.path.join(movieLibrary, folder) #Set the folder to the maindir/dir
                
                success = shutil.rmtree(dir, ignore_errors=True) #Remove the directory
                #if vars.update_videolibrary == "true" and type=='':
                #    update_dir = vars.tv_folder_path
                #    if type == 'musicvideo':
                #        update_dir = vars.musicvideo_folder_path
                #    dev.log('Updating video library is enabled. Cleaning librarys directory %s' % update_dir, True)
                #    xbmc.executebuiltin('xbmc.updatelibrary(Video,'+update_dir+')')

                xbmcgui.Dialog().ok('Removed from library', 'Deleted the previous videos from your library (You should clean your library, otherwise they will still show in your library)')
            editPlaylist(id, type=type) #Load the editplaylist view
def episode_exists(playlist,
                   episode,
                   season_tag='season',
                   episode_tag='episode',
                   type=''):
    dev.log('episode_exists(' + playlist + ', ' + episode + ', type=' + type +
            ')')
    #Quicker way to check if this episode already exists
    #doc = playlist_xml_get(playlist)
    #e = doc.findall("*/episode[@id='"+episode+"']")
    e = xml_get_elem(season_tag + '/' + episode_tag,
                     episode_tag, {'id': episode},
                     playlist=playlist,
                     type=type)
    #if len(e) == 0:
    if e == None:
        dev.log(episode_tag + ' ' + episode + ' is not yet present in ' +
                dev.typeEpnr(type) + ' file')
        return False
    dev.log('Already present: ' + episode)
    return True