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)')
예제 #2
0
파일: service.py 프로젝트: c0ns0le/YCBuilds
def update_playlist(id, type=''):
    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('Could not find playlist '+id+' in the '+dev.typeXml(type)+' file', True)
        return False
    else:
        dev.log('Updating playlist %s (Id: %s)' % (settings.find('title').text.encode('utf-8'), id))
        #Check in which folder the show should be added
        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)
        
        #Create the tvshow.nfo
        writenfo = settings.find('writenfo').text
        if writenfo != 'no':
            if type == '' or type == 'tv':
                generators.write_tvshow_nfo(folder, settings)
        
        update_playlist_vids(id, folder, settings, type=type)
        
        #Save the time this playlist got updated in the xml
        import datetime
        d=datetime.datetime.now()
        m_xml.xml_update_playlist_attr(id, 'scansince', d.strftime("%d/%m/%Y %H:%M:%S"), type=type)
    
        return True
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 write_xml(elem, dir='', output='', type=''):
    if output == '':
        output = dev.typeXml(type)
    dev.log('write_xml('+type+','+output+').')
    
    
    xbmcvfs.mkdir(vars.settingsPath) #Create the settings dir if it does not exist already
    if dir is not '': xbmcvfs.mkdir(vars.settingsPath+dir) #Create the settings dir if it does not exist already
    #Write these settings to a .xml file in the addonfolder
    output_file = os.path.join(vars.settingsPath+dir, output) #Set the outputfile to settings.xml
    
    #Creating a backup of the .xml file (in case it gets corrupted)
    backupfile = os.path.join(vars.settingsPath+dir, output+'.backup')
    if xbmcvfs.exists(output_file):
        if xbmcvfs.copy(output_file, backupfile):
            dev.log('Created a backup of the xml file at: '+backupfile)
        else:
            dev.log('Failed to create a backup of the xml file at: '+backupfile)
    else:
        dev.log(output_file+' could not be found, so not able to create a backup')
    
    
    indent( elem ) #Prettify the xml so its not on one line
    tree = ElementTree.ElementTree( elem ) #Convert the xml back to an element
    tree.write(output_file) #Save the XML in the settings file
    
    #For backup purposes, check if the xml got corrupted by writing just now
    if xml_get(type) is False:
        dev.log('corrupt .xml file')
def write_xml(elem, dir='', output='', type=''):
    if output == '':
        output = dev.typeXml(type)
    dev.log('write_xml(' + type + ',' + output + ').')

    xbmcvfs.mkdir(vars.settingsPath
                  )  #Create the settings dir if it does not exist already
    if dir is not '':
        xbmcvfs.mkdir(
            vars.settingsPath +
            dir)  #Create the settings dir if it does not exist already
    #Write these settings to a .xml file in the addonfolder
    output_file = os.path.join(vars.settingsPath + dir,
                               output)  #Set the outputfile to settings.xml

    #Creating a backup of the .xml file (in case it gets corrupted)
    backupfile = os.path.join(vars.settingsPath + dir, output + '.backup')
    if xbmcvfs.exists(output_file):
        if xbmcvfs.copy(output_file, backupfile):
            dev.log('Created a backup of the xml file at: ' + backupfile)
        else:
            dev.log('Failed to create a backup of the xml file at: ' +
                    backupfile)
    else:
        dev.log(output_file +
                ' could not be found, so not able to create a backup')

    indent(elem)  #Prettify the xml so its not on one line
    tree = ElementTree.ElementTree(elem)  #Convert the xml back to an element
    tree.write(output_file)  #Save the XML in the settings file

    #For backup purposes, check if the xml got corrupted by writing just now
    if xml_get(type) is False:
        dev.log('corrupt .xml file')
def xml_get(type=''):
    file=dev.typeXml(type)
    dev.log('XML_get('+type+','+file+')')
    global document #Set the document variable as global, so every function can reach it
    try:
        document = ElementTree.parse( vars.settingsPath+file )
    except Exception:
        xbmcgui.Dialog().ok("ERROR: "+file+" got corrupted", "ERROR!: "+file+" got corrupted. Please report this error to the addon developer on youtubelibrary.nl or the kodi forums. Luckily a backup has been created automatically before.")
        dev.log('ERROR: '+file+' got corrupted.', 1)
        raise ValueError(output_file+' got corrupted! Best to quit here')
        return False
    return document
def xml_remove_playlist(id, type=''):
    dev.log('XML_remove_playlist('+id+')')
    pl = xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type)
    if pl is not None:
        dev.log('Found the playlist to delete')
        
        root = document.getroot()
        parent = root.find('playlists')
        parent.remove(pl)
        write_xml(root, type=type)
        dev.log('XML_remove_playlist: Removed playlist '+id+' ('+dev.typeXml(type)+')', 8)
        return True
    else:
        return False
def xml_get(type=''):
    file = dev.typeXml(type)
    dev.log('XML_get(' + type + ',' + file + ')')
    global document  #Set the document variable as global, so every function can reach it
    try:
        document = ElementTree.parse(vars.settingsPath + file)
    except Exception:
        xbmcgui.Dialog().ok(
            "ERROR: " + file + " got corrupted", "ERROR!: " + file +
            " got corrupted. Please report this error to the addon developer on youtubelibrary.nl or the kodi forums. Luckily a backup has been created automatically before."
        )
        dev.log('ERROR: ' + file + ' got corrupted.', 1)
        raise ValueError(output_file + ' got corrupted! Best to quit here')
        return False
    return document
def xml_remove_playlist(id, type=''):
    dev.log('XML_remove_playlist(' + id + ')')
    pl = xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type)
    if pl is not None:
        dev.log('Found the playlist to delete')

        root = document.getroot()
        parent = root.find('playlists')
        parent.remove(pl)
        write_xml(root, type=type)
        dev.log(
            'XML_remove_playlist: Removed playlist ' + id + ' (' +
            dev.typeXml(type) + ')', 8)
        return True
    else:
        return False
예제 #10
0
def update_playlist(id, type=''):
    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(
            'Could not find playlist ' + id + ' in the ' + dev.typeXml(type) +
            ' file', True)
        return False
    else:
        dev.log('Updating playlist %s (Id: %s)' %
                (settings.find('title').text.encode('utf-8'), id))
        #Check in which folder the show should be added
        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)

        #Create the tvshow.nfo
        writenfo = settings.find('writenfo').text
        if writenfo != 'no':
            if type == '' or type == 'tv':
                generators.write_tvshow_nfo(folder, settings)
            elif type == 'musicvideo':
                generators.write_artist_nfo(folder, settings)

        if update_playlist_vids(id, folder, settings, type=type) == False:
            return False  #something failed while updating the videos of the playlist

        #Save the time this playlist got updated in the xml
        import datetime
        d = datetime.datetime.now()
        m_xml.xml_update_playlist_attr(id,
                                       'scansince',
                                       d.strftime("%d/%m/%Y %H:%M:%S"),
                                       type=type)

        return True