def enable_rss_feeds(): # Set RSS feeds to www.bulis.co.uk/?feeds=rss2 # and enable RSS feeds setting rss_xml_doc = xbmc.translatePath( os.path.join(__resources__, 'RssFeeds.xml')) if os.path.isfile(rss_xml_doc): new_xml_doc = '' lines = commontasks.read_from_file(rss_xml_doc) for line in lines: new_xml_doc += line commontasks.write_to_file('%s/RssFeeds.xml' % __userdata_path__, str(new_xml_doc), False) # Enable RSS feeds advsettings_xml_doc_res = xbmc.translatePath( os.path.join(__resources__, 'advancedsettings.xml')) advsettings_xml_doc_usr = '******' % __userdata_path__ # Fetch the current state of the RSS feeds setting enablerssfeeds = xbmc.executeJSONRPC( '{"jsonrpc":"2.0",' ' "method":"Settings.GetSettingValue",' ' "params":{"setting":"lookandfeel.enablerssfeeds"},' ' "id":1}') # If RSS feeds are disabled if '"value":false' in enablerssfeeds: # Check if the xml doc already exists if not os.path.isfile(advsettings_xml_doc_usr): # Check if the advanced settings xml exists in resources if os.path.isfile(advsettings_xml_doc_res): new_xml_doc = '' lines = commontasks.read_from_file(advsettings_xml_doc_res) for line in lines: new_xml_doc += line # Temperarily enables the RSS feeds until reboot xbmc.executeJSONRPC( '{"jsonrpc":"2.0",' ' "method":"Settings.SetSettingValue",' ' "params":{"setting":"lookandfeel.enablerssfeeds","value":true},' ' "id":1}') xbmc.executebuiltin('RefreshRSS') # Creates the advanced settings xml document to persist changes after reboot commontasks.write_to_file(advsettings_xml_doc_usr, str(new_xml_doc), False) else: # Check advamced settings xml document already exists and remove. # This runs on the next installation to then allow the user # to disable RSS feeds. if os.path.isfile(advsettings_xml_doc_usr): os.remove(advsettings_xml_doc_usr)
def show_fav_songs(): menuitems = [(_clear_list, 'ClearFavSongs', 5, os.path.join(image_path, 'fav_songs.png'), os.path.join(image_path, 'fav_songs_fanart.jpg')), (_add_current_song_to_list, 'AddFavSong', 6, os.path.join(image_path, 'fav_songs.png'), os.path.join(image_path, 'fav_songs_fanart.jpg'))] for title, url, mode, iconimage, fanartimage in menuitems: addDir(name=title, url=url, mode=mode, icon=iconimage, fanart=fanartimage) if not os.path.isfile(__fav_songs_list__): commontasks.create_file(__resources__, 'fav_songs.list') s = commontasks.read_from_file(__fav_songs_list__) search_list = s.split('\n') for list in search_list: if list != '': addDir(name=list, url=list, mode=7, icon=os.path.join(image_path, 'fav_songs.png'), fanart=os.path.join(image_path, 'fav_songs_fanart.jpg')) xbmcplugin.endOfDirectory(__handle__)
def clean_addons(): # Clean addons fetches the list of addons if os.path.isfile(__addons_to_clean_list__): al = commontasks.read_from_file(__addons_to_clean_list__) addons_list = al.split('\n') for list in addons_list: if list != '': split_list = list.split('<>') clean_addon(split_list[0], split_list[1])
def clean_music_addons(): # Clean music addons list if os.path.isfile(__music_addons_to_clean_list__): al = commontasks.read_from_file(__music_addons_to_clean_list__) addons_list = al.split('\n') for list in addons_list: if list != '': split_list = list.split('<>') clean_music_addon(split_list[0], split_list[1])
def clean_addon(addon_id, addon_name): # Clean addon removes the colours from addon names # to allow addons to be listed alphabetically addon_dir = xbmc.translatePath( os.path.join('special://home/addons', addon_id)) if os.path.isdir(addon_dir): old_xml_doc = commontasks.read_from_file('%s/addon.xml' % addon_dir) rep_string = commontasks.regex_from_to(old_xml_doc, 'name="', '"') new_xml_doc = old_xml_doc.replace(rep_string, addon_name) commontasks.write_to_file('%s/addon.xml' % addon_dir, str(new_xml_doc), False) xbmc.sleep(100)
def clean_music_addon(addon_id, addon_name): # Clean music addon text = '<provides>' new_xml_doc = '' addon_dir = xbmc.translatePath( os.path.join('special://home/addons', addon_id)) if os.path.isdir(addon_dir): lines = commontasks.read_from_file('%s/addon.xml' % addon_dir) if lines is not None: if lines.find(text) >= 0: for line in lines.split('\n'): if text in line: new_xml_doc += line.replace('audio', '').replace( '<provides> ', '<provides>').replace(' </provides>', '</provides>') else: new_xml_doc += line commontasks.write_to_file('%s/addon.xml' % addon_dir, str(new_xml_doc), False) xbmc.sleep(100)
def remove_dependancies(addon_id, addon_name): locations = [ 'plugin.video.*', 'plugin.audio.*', 'plugin.program.*', 'service.*', 'script.force-install-all-ep' ] text = '<import addon="%s" />' % addon_id new_xml_doc = '' for location in locations: addons_lst = glob.glob( xbmc.translatePath(os.path.join('special://home/addons', location))) for item in addons_lst: lines = commontasks.read_from_file('%s/addon.xml' % item) if lines is not None: if lines.find(text) >= 0: for line in lines.split('\n'): if line.find(text) < 0: new_xml_doc += line commontasks.write_to_file('%s/addon.xml' % item, str(new_xml_doc), False) xbmc.sleep(100)
def remove_addons_and_dependancies(): # Remove addons and dependancies for depricated addons if os.path.isfile(__addons_to_remove_list__): al = commontasks.read_from_file(__addons_to_remove_list__) addons_list = al.split('\n') for list in addons_list: if list != '': split_list = list.split('<>') remove_dependancies(split_list[0], split_list[1]) remove_addon(split_list[0], split_list[1]) remove_dependancies(__addon_id__, __addon_name__) remove_addon(__addon_id__, __addon_name__) if len(g_addons_removed_lst) > 0: text = '' for item in g_addons_removed_lst: if len(g_addons_removed_lst) == 1: text = '%s' % item else: if text == '': text = '%s' % item else: text += ', %s' % item text += '\n' text = "The following addons are now obsolete and have been removed.\n[COLOR orange]%s[/COLOR]" % text dialog = xbmcgui.Dialog() try: # Send system info # May fail if not installed on RPi send_system_info() except: pass if not dialog.yesno( 'PRB Clean: Remove Obsolete Addons', text + 'To finish removal of obsolete addons a reboot is required.\nDo you want to reboot now?', '', '', 'Reboot', 'Continue'): xbmc.executebuiltin('System.Exec(reboot)')
def _set_download_paths(): # Set download paths for addons that allow downloading addon_types = ['plugin', '.video.', '.audio.', '.program.'] msg = 'Set download paths for the following addons: ' if os.path.isfile(__addons_download_paths_list__): # Fetch list of addons al = commontasks.read_from_file(__addons_download_paths_list__) addons_list = al.split('\n') # Iterate through the list of addons for list in addons_list: if list != '': split_list = list.split('<>') setting_value = split_list[3] addon_data_dir = xbmc.translatePath( os.path.join('special://profile/addon_data', split_list[1])) if os.path.isdir(addon_data_dir): # Check the settings xml file exists if not os.path.isfile( os.path.join(addon_data_dir, 'settings.xml')): # Create a new settings xml file _create_settings_xml(split_list[1]) settings_file = os.path.join(addon_data_dir, 'settings.xml') tree = et.parse(settings_file) root = tree.getroot() # Iterate though all settings for setting in root.iter('setting'): value = '' if setting.get('id') == split_list[2]: try: # Set new value if setting_value.lower( ) == 'true' or setting_value.lower( ) == 'false': value = setting_value.lower() else: if __addon__.getSetting( setting_value) == '': value = '%s%s/' % ( __download_dir__, split_list[4].replace('\r', '')) __addon__.setSetting( setting_value, value) else: value = __addon__.getSetting( setting_value) setting.set('value', value) except: pass try: # Save settings file tree.write(settings_file) temp2 = '[COLOR orange]%s[/COLOR], ' % split_list[0] msg += temp2 msg = msg.replace(temp2 + temp2, temp2) except: pass for item in addon_types: msg = msg.replace(item, '') + '\n' return msg.replace(', \n', '.')