def add_fav_song(): if xbmc.Player().isPlayingAudio(): title = xbmc.Player().getMusicInfoTag().getTitle() if len(title) > 0: commontasks.write_to_file(__fav_songs_list__, title + '\n', True) xbmc.executebuiltin('Container.Refresh') else: commontasks.message(_no_audio_stream, _fav_songs)
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 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 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)