diff --git a/script.copacetic.helper/README.md b/script.copacetic.helper/README.md index df2ad68d59..f8200b5930 100644 --- a/script.copacetic.helper/README.md +++ b/script.copacetic.helper/README.md @@ -13,6 +13,23 @@ All code contained in this project is licensed under GPL 3.0. * __jurialmunkey__ for all the best-practice code examples from [plugin.video.themoviedb.helper](https://github.com/jurialmunkey/plugin.video.themoviedb.helper) and forum support. ### Changelog +**1.0.17** +- Parse args for script actions to enable values with special characters to be properly escaped from Kodi using '"$INFO[ListItem.Title]"' + +**1.0.16** +- Added tvchannels/radiochannels to background_slideshow() +- Error handling for clearlogos that aren't in a supported PIL mode https://github.com/realcopacetic/script.copacetic.helper/issues/3 +- Added landscape to movieartwhitelist/tvshowartwhitelist recommended settings +- SlideshowMonitor class extended to accept custom paths to folders of images e.g. special://profile/backgrounds/ - it can now populate background slideshows sourced from library paths, playlists, plugin sources (e.g. themoviedbhelper) and folders +- Rebuilt wideget_move() to account for new widget settings + +**1.0.15** +- Global search action to open keyboard and return value to relevant skin string. +- Minor error catching in play_all() + +**1.0.14** +- Test fix for issue: IndexError: list index out of range https://github.com/realcopacetic/script.copacetic.helper/issues/5 + **1.0.13** - Player monitor captures Set ID for currently playing movie and passes to a window property for skin.copacetic to use for Now_Playing indicator on sets diff --git a/script.copacetic.helper/addon.xml b/script.copacetic.helper/addon.xml index 32fe7a5eb6..f12d59bf0c 100644 --- a/script.copacetic.helper/addon.xml +++ b/script.copacetic.helper/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/script.copacetic.helper/resources/lib/plugin/content.py b/script.copacetic.helper/resources/lib/plugin/content.py index d513dc1da5..4858a81957 100644 --- a/script.copacetic.helper/resources/lib/plugin/content.py +++ b/script.copacetic.helper/resources/lib/plugin/content.py @@ -175,13 +175,13 @@ def next_up(self): try: episode_details = episode_query['result']['episodes'] + ''' Add tv show studio and mpaa to episode dictionary ''' + episode_details[0]['studio'] = studio + episode_details[0]['mpaa'] = mpaa except Exception: log( f"Widget next_up: No next episodes found for {episode['title']}") else: - ''' Add tv show studio and mpaa to episode dictionary ''' - episode_details[0]['studio'] = studio - episode_details[0]['mpaa'] = mpaa add_items(self.li, episode_details, type='episode') set_plugincontent(content='episodes', category=ADDON.getLocalizedString(32600)) diff --git a/script.copacetic.helper/resources/lib/script/actions.py b/script.copacetic.helper/resources/lib/script/actions.py index 5f18939e6e..2779db68ec 100644 --- a/script.copacetic.helper/resources/lib/script/actions.py +++ b/script.copacetic.helper/resources/lib/script/actions.py @@ -2,8 +2,8 @@ from resources.lib.service.art import ImageEditor from resources.lib.utilities import (ADDON, DIALOG, clear_playlists, condition, - infolabel, json_call, log_and_execute, - skin_string, window_property, xbmc) + infolabel, json_call, log, log_and_execute, + skin_string, window_property, xbmc, urllib) def clean_filename(label=False, **kwargs): @@ -33,6 +33,16 @@ def dialog_yesno(heading, message, **kwargs): log_and_execute(action) +def globalsearch_input(**kwargs): + kb = xbmc.Keyboard( + infolabel('$INFO[Skin.String(globalsearch)]'), infolabel('$LOCALIZE[137]')) + kb.doModal() + if (kb.isConfirmed()): + text = kb.getText() + skin_string('globalsearch', set=text) + xbmc.executebuiltin('ActivateWindow(1180)') + + def hex_contrast_check(**kwargs): image = ImageEditor() hex = kwargs.get('hex', '') @@ -99,32 +109,34 @@ def play_items(id, **kwargs): else: method = f'Container({id}).ListItemAbsolute' - for count in range(int(xbmc.getInfoLabel(f'Container({id}).NumItems'))): - - if xbmc.getCondVisibility(f'String.IsEqual({method}({count}).DBType,movie)'): - media_type = 'movie' - elif xbmc.getCondVisibility(f'String.IsEqual({method}({count}).DBType,episode)'): - media_type = 'episode' - elif xbmc.getCondVisibility(f'String.IsEqual({method}({count}).DBType,song)'): - media_type = 'song' - elif xbmc.getCondVisibility(f'String.IsEqual({method}({count}).DBType,musicvideo)'): - media_type = 'musicvideo' - - dbid = int(xbmc.getInfoLabel(f'{method}({count}).DBID')) - url = xbmc.getInfoLabel(f'{method}({count}).Filenameandpath') - - if media_type and dbid: - json_call('Playlist.Add', - item={f'{media_type}id': dbid}, - params={'playlistid': playlistid}, - parent='play_items' - ) - elif url: - json_call('Playlist.Add', - item={'file': url}, - params={'playlistid': playlistid}, - parent='play_items' - ) + for count in range(int(infolabel(f'Container({id}).NumItems'))): + try: + dbid = int(xbmc.getInfoLabel(f'{method}({count}).DBID')) + url = xbmc.getInfoLabel(f'{method}({count}).Filenameandpath') + except ValueError: + break + else: + if condition(f'String.IsEqual({method}({count}).DBType,movie)'): + media_type = 'movie' + elif condition(f'String.IsEqual({method}({count}).DBType,episode)'): + media_type = 'episode' + elif condition(f'String.IsEqual({method}({count}).DBType,song)'): + media_type = 'song' + elif condition(f'String.IsEqual({method}({count}).DBType,musicvideo)'): + media_type = 'musicvideo' + + if media_type and dbid: + json_call('Playlist.Add', + item={f'{media_type}id': dbid}, + params={'playlistid': playlistid}, + parent='play_items' + ) + elif url: + json_call('Playlist.Add', + item={'file': url}, + params={'playlistid': playlistid}, + parent='play_items' + ) json_call('Playlist.GetItems', params={'playlistid': playlistid}, @@ -225,7 +237,7 @@ def shuffle_artist(**kwargs): item={'artistid': dbid}, options={'shuffled': True}, parent='shuffle_artist') - + def toggle_addon(id, **kwargs): if condition(f'System.AddonIsEnabled({id})'): @@ -239,118 +251,52 @@ def toggle_addon(id, **kwargs): parent='toggle_addon') DIALOG.notification(id, ADDON.getLocalizedString(32206)) + +def url_encode(name, string, **kwargs): + encoded = urllib.quote(string) + window_property(name, set=encoded) + + def widget_move(posa, posb, **kwargs): - tempa_name = '' - tempa_target = '' - tempa_sortmethod = '' - tempa_sortorder = '' - tempa_path = '' - tempa_limit = '' - tempa_thumb = False, - tempb_name = '' - tempb_target = '' - tempb_sortmethod = '' - tempb_sortorder = '' - tempb_path = '' - tempb_limit = '' - tempb_thumb = False - - tempa_view = infolabel(f'Skin.String(Widget{posa}_View)') - tempa_display = infolabel(f'Skin.String(Widget{posa}_Display)') - tempb_view = infolabel(f'Skin.String(Widget{posb}_View)') - tempb_display = infolabel(f'Skin.String(Widget{posb}_Display)') - - if condition(f'Skin.HasSetting(Widget{posa}_Content_Disabled)'): - tempa_content = 'Disabled' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_InProgress)'): - tempa_content = 'InProgress' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_NextUp)'): - tempa_content = 'NextUp' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_LatestMovies)'): - tempa_content = 'LatestMovies' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_LatestTVShows)'): - tempa_content = 'LatestTVShows' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_RandomMovies)'): - tempa_content = 'RandomMovies' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_RandomTVShows)'): - tempa_content = 'RandomTVShows' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_LatestAlbums)'): - tempa_content = 'LatestAlbums' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_RecentAlbums)'): - tempa_content = 'RecentAlbums' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_RandomAlbums)'): - tempa_content = 'RandomAlbums' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_LikedSongs)'): - tempa_content = 'LikedSongs' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_Favourites)'): - tempa_content = 'Favourites' - elif condition(f'Skin.HasSetting(Widget{posa}_Content_Custom)'): - tempa_content = 'Custom' - tempa_name = infolabel(f'Skin.String(Widget{posa}_Custom_Name)') - tempa_target = infolabel(f'Skin.String(Widget{posa}_Custom_Target)') - tempa_sortmethod = infolabel(f'Skin.String(Widget{posa}_Custom_SortMethod)') - tempa_sortorder = infolabel(f'Skin.String(Widget{posa}_Custom_SortOrder)') - tempa_path = infolabel(f'Skin.String(Widget{posa}_Custom_Path)') - tempa_limit = infolabel(f'Skin.String(Widget{posa}_Custom_Limit)') - tempa_thumb = True if condition(f'Skin.HasSetting(Widget{posa}_Episode_Thumbs)') else False - - if condition(f'Skin.HasSetting(Widget{posb}_Content_Disabled)'): - tempb_content = 'Disabled' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_InProgress)'): - tempb_content = 'InProgress' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_NextUp)'): - tempb_content = 'NextUp' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_LatestMovies)'): - tempb_content = 'LatestMovies' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_LatestTVShows)'): - tempb_content = 'LatestTVShows' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_RandomMovies)'): - tempb_content = 'RandomMovies' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_RandomTVShows)'): - tempb_content = 'RandomTVShows' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_LatestAlbums)'): - tempb_content = 'LatestAlbums' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_RecentAlbums)'): - tempb_content = 'RecentAlbums' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_RandomAlbums)'): - tempb_content = 'RandomAlbums' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_LikedSongs)'): - tempb_content = 'LikedSongs' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_Favourites)'): - tempb_content = 'Favourites' - elif condition(f'Skin.HasSetting(Widget{posb}_Content_Custom)'): - tempb_content = 'Custom' - tempb_name = infolabel(f'Skin.String(Widget{posb}_Custom_Name)') - tempb_target = infolabel(f'Skin.String(Widget{posb}_Custom_Target)') - tempb_sortmethod = infolabel(f'Skin.String(Widget{posb}_Custom_SortMethod)') - tempb_sortorder = infolabel(f'Skin.String(Widget{posb}_Custom_SortOrder)') - tempb_path = infolabel(f'Skin.String(Widget{posb}_Custom_Path)') - tempb_limit = infolabel(f'Skin.String(Widget{posb}_Custom_Limit)') - tempb_thumb = True if condition(f'Skin.HasSetting(Widget{posb}_Episode_Thumbs)') else False - - xbmc.executebuiltin(f'Skin.ToggleSetting(Widget{posa}_Content_{tempa_content})') - xbmc.executebuiltin(f'Skin.SetBool(Widget{posa}_Content_{tempb_content})') - xbmc.executebuiltin(f'Skin.ToggleSetting(Widget{posb}_Content_{tempb_content})') - xbmc.executebuiltin(f'Skin.SetBool(Widget{posb}_Content_{tempa_content})') - skin_string(f'Widget{posb}_View', set=tempa_view) - skin_string(f'Widget{posa}_View', set=tempb_view) - skin_string(f'Widget{posb}_Display', set=tempa_display) - skin_string(f'Widget{posa}_Display', set=tempb_display) - skin_string(f'Widget{posb}_Custom_Name', set=tempa_name) - skin_string(f'Widget{posa}_Custom_Name', set=tempb_name) - skin_string(f'Widget{posb}_Custom_Target', set=tempa_target) - skin_string(f'Widget{posa}_Custom_Target', set=tempb_target) - skin_string(f'Widget{posb}_Custom_SortMethod', set=tempa_sortmethod) - skin_string(f'Widget{posa}_Custom_SortMethod', set=tempb_sortmethod) - skin_string(f'Widget{posb}_Custom_SortOrder', set=tempa_sortorder) - skin_string(f'Widget{posa}_Custom_SortOrder', set=tempb_sortorder) - skin_string(f'Widget{posb}_Custom_Path', set=tempa_path) - skin_string(f'Widget{posa}_Custom_Path', set=tempb_path) - skin_string(f'Widget{posb}_Custom_Limit', set=tempa_limit) - skin_string(f'Widget{posa}_Custom_Limit', set=tempb_limit) - if tempa_thumb and not tempb_thumb: - xbmc.executebuiltin(f'Skin.ToggleSetting(Widget{posa}_Episode_Thumbs)') - xbmc.executebuiltin(f'Skin.SetBool(Widget{posb}_Episode_Thumbs)') - elif tempb_thumb and not tempa_thumb: - xbmc.executebuiltin(f'Skin.ToggleSetting(Widget{posb}_Episode_Thumbs)') - xbmc.executebuiltin(f'Skin.SetBool(Widget{posa}_Episode_Thumbs)') + # create list of (widget position, dictionary) + content_types = ['Disabled', 'InProgress', 'NextUp', 'LatestMovies', 'LatestTVShows', 'RandomMovies', + 'RandomTVShows', 'LatestAlbums', 'RecentAlbums', 'RandomALbums', 'LikedSongs', 'Favourites', 'Custom'] + template = { + 'View': '', 'Display': '', 'Content': '', 'Custom_Name': '', 'Custom_Target': '', 'Custom_SortMethod': '', 'Custom_SortOrder': '', 'Custom_Path': '', 'Custom_Limit': '', 'Autoscroll': False, + 'Trailer_Autoplay': False, 'Clearlogos_Enabled': False, 'Prefer_Keyart': False, 'Prefer_Landscape': False + } + dica, dicb = {}, {} + dica.update(template) + dicb.update(template) + + # populate dictionaries with values from Kodi + list = [(posa, dica), (posb, dicb)] + for item in list: + for content in content_types: + if condition(f'Skin.HasSetting(Widget{item[0]}_Content_{content})'): + # capture value of bool then reset it in Kodi + item[1]['Content'] = content + xbmc.executebuiltin( + f'Skin.Reset(Widget{item[0]}_Content_{content})') + break + for key, value in item[1].items(): + if type(value) == str and not value: + item[1][key] = infolabel(f'Skin.String(Widget{item[0]}_{key})') + elif type(value) == bool and not value: + if condition(f'Skin.HasSetting(Widget{item[0]}_{key})'): + # capture value of bool then reset it in Kodi + item[1][key] = True + xbmc.executebuiltin( + f'Skin.Reset(Widget{item[0]}_{key})') + # swap values + swapped_list = [(posa, dicb), (posb, dica)] + log(f'FUCKO_ {swapped_list}', force=True) + for item in swapped_list: + xbmc.executebuiltin(f'Skin.ToggleSetting(Widget{item[0]}_Content_{item[1]["Content"]})') + for key, value in item[1].items(): + if type(value) == str: + skin_string(f'Widget{item[0]}_{key}', set=value) + elif type(value) == bool and value and 'Content' not in key: + log(f'FUCKO_2_ {value}', force=True) + xbmc.executebuiltin( + f'Skin.ToggleSetting(Widget{item[0]}_{key})') diff --git a/script.copacetic.helper/resources/lib/service/art.py b/script.copacetic.helper/resources/lib/service/art.py index 7854279485..11b885f892 100644 --- a/script.copacetic.helper/resources/lib/service/art.py +++ b/script.copacetic.helper/resources/lib/service/art.py @@ -110,15 +110,20 @@ def _crop_image(self, url): converted_image = Image.new("RGBA", image.size) converted_image.paste(image) image = converted_image - image = image.crop(image.convert('RGBa').getbbox()) - with xbmcvfs.File(self.destination, 'wb') as f: - image.save(f, 'PNG') - self._image_functions(image) - log( - f'ImageEditor: Image cropped and saved: {url} --> {self.destination}') - if self.temp_folder in url: # If temp file created, delete it now - xbmcvfs.delete(url) - log(f'ImageEditor: Temporary file deleted --> {url}') + try: + image = image.crop(image.convert('RGBa').getbbox()) + except ValueError as error: + log( + f'ImageEditor: Error - could not convert image due to unsupport mode {image.mode} --> {error}', force=True) + else: + with xbmcvfs.File(self.destination, 'wb') as f: + image.save(f, 'PNG') + self._image_functions(image) + log( + f'ImageEditor: Image cropped and saved: {url} --> {self.destination}') + if self.temp_folder in url: # If temp file created, delete it now + xbmcvfs.delete(url) + log(f'ImageEditor: Temporary file deleted --> {url}') def _return_image_path(self, source, suffix): # Use source URL to generate cached url. If cached url doesn't exist, return source url @@ -219,6 +224,7 @@ def __init__(self): self.art_types = ['global', 'movies', 'tvshows', 'videos', 'artists', 'custom'] self.on_next_run_flag = True + self.custom_source = '' self.custom_path = infolabel( 'Skin.String(Background_Slideshow_Custom_Path)') self.refresh_count = self.refresh_interval = self._get_refresh_interval() @@ -231,16 +237,26 @@ def background_slideshow(self): self.fetch_interval = self.refresh_interval * 40 # Capture plugin art if it's available and on_next_run flag is true + if 'plugin://' in self.custom_path: + self.custom_source = 'plugin' + elif 'videodb://' in self.custom_path: + self.custom_source = 'library' + elif 'musicdb://' in self.custom_path: + self.custom_source = 'library' + elif 'library://' in self.custom_path: + self.custom_source = 'library' + else: + self.custom_source = 'other' if condition( 'Integer.IsGreater(Container(3300).NumItems,0)' - ) and 'plugin://' in self.custom_path and self.on_next_run_flag: - self._get_plugin_arts() + ) and not 'library' in self.custom_source and self.on_next_run_flag: + self._get_external_arts() # Fech art every 40 x refresh interval, reset if custom path changes if self.fetch_count >= self.fetch_interval or self.custom_path != infolabel('Skin.String(Background_Slideshow_Custom_Path)'): self.custom_path = infolabel( 'Skin.String(Background_Slideshow_Custom_Path)') - if 'plugin://' in self.custom_path and not self.on_next_run_flag: + if not 'library' in self.custom_source and not self.on_next_run_flag: self.on_next_run_flag = True log('Monitor fetching background art') self.art = self._get_art() @@ -288,21 +304,25 @@ def write_art(self): path.text = current_fanart lookup_tree.write(self.lookup, encoding="utf-8") - def _get_plugin_arts(self): + def _get_external_arts(self): if self.on_next_run_flag: self.art['custom'] = [] num_items = int(infolabel('Container(3300).NumItems')) for i in range(num_items): - item = { - 'title': infolabel( - f'Container(3300).ListItem({i}).Label'), - 'fanart': infolabel( - f'Container(3300).ListItem({i}).Art(fanart)'), - 'clearlogo': infolabel( - f'Container(3300).ListItem({i}).Art(clearlogo)') - } - if item['fanart']: - self.art['custom'].append(item) + fanart = infolabel( + f'Container(3300).ListItem({i}).Art(fanart)') + if not fanart and 'other' in self.custom_source: + fanart = infolabel( + f'Container(3300).ListItem({i}).Art(thumb)') + if fanart: + item = { + 'title': infolabel( + f'Container(3300).ListItem({i}).Label'), + 'fanart': fanart, + 'clearlogo': infolabel( + f'Container(3300).ListItem({i}).Art(clearlogo)') + } + self.art['custom'].append(item) self.on_next_run_flag = False def _get_art(self): @@ -311,7 +331,7 @@ def _get_art(self): self.art[type] = [] # Populate custom path/playlist slideshow if selected in skin settings - if self.custom_path and 'plugin://' not in self.custom_path and condition('Skin.String(Background_Slideshow,Custom)'): + if self.custom_path and 'library' in self.custom_source and condition('Skin.String(Background_Slideshow,Custom)'): query = json_call('Files.GetDirectory', params={'directory': self.custom_path}, sort={'method': 'random'}, @@ -366,11 +386,12 @@ def _get_refresh_interval(self): def _set_art(self, key, items): art = random.choice(items) art.pop('set.fanart', None) - # fanart = self._url_decode_path(art.get('fanart')) fanarts = {key: value for ( key, value) in art.items() if 'fanart' in key} fanart = random.choice(list(fanarts.values())) fanart = self._url_decode_path(fanart) + if 'transform?size=thumb' in fanart: + fanart = fanart[:-21] window_property(f'{key}_fanart', set=fanart) # clearlogo if present otherwise clear clearlogo = art.get('clearlogo', False) diff --git a/script.copacetic.helper/resources/lib/service/monitor.py b/script.copacetic.helper/resources/lib/service/monitor.py index 201aed1f0c..41b4c7cc62 100644 --- a/script.copacetic.helper/resources/lib/service/monitor.py +++ b/script.copacetic.helper/resources/lib/service/monitor.py @@ -164,7 +164,8 @@ def poller(self): 'Window.IsVisible(mediasource) | ' 'Window.IsVisible(smartplaylisteditor) | ' 'Window.IsVisible(musicplaylisteditor) | ' - 'Window.IsVisible(tvguide) | ' + 'Window.IsVisible(tvguide) | Window.IsVisible(radioguide) | ' + 'Window.IsVisible(tvchannels) | Window.IsVisible(radiochannels) | ' 'Container.Content(genres) | ' 'Container.Content(years) | ' 'Container.Content(playlists) | ' diff --git a/script.copacetic.helper/resources/lib/service/player.py b/script.copacetic.helper/resources/lib/service/player.py index 0701c13301..74469dd09b 100644 --- a/script.copacetic.helper/resources/lib/service/player.py +++ b/script.copacetic.helper/resources/lib/service/player.py @@ -28,7 +28,7 @@ def onAVStarted(self): # Get set id tag = self.getVideoInfoTag() dbid = tag.getDbId() - if dbid: + if dbid and condition('VideoPlayer.Content(movie)'): query = json_call( 'VideoLibrary.GetMovieDetails', params={'properties': [ diff --git a/script.copacetic.helper/resources/lib/service/settings.py b/script.copacetic.helper/resources/lib/service/settings.py index 6c424779f1..56d726df68 100644 --- a/script.copacetic.helper/resources/lib/service/settings.py +++ b/script.copacetic.helper/resources/lib/service/settings.py @@ -15,8 +15,8 @@ def __init__(self): 'videolibrary.tvshowsselectfirstunwatcheditem': 2, 'videolibrary.tvshowsincludeallseasonsandspecials': 3, 'videolibrary.artworklevel': 2, - 'videolibrary.movieartwhitelist': ['keyart', 'square', 'clearlogo', 'clearlogo-alt', 'clearlogo-billboard'], - 'videolibrary.tvshowartwhitelist': ['keyart', 'square', 'clearlogo', 'clearlogo-alt', 'clearlogo-billboard'], + 'videolibrary.movieartwhitelist': ['keyart', 'landscape', 'square', 'clearlogo', 'clearlogo-alt', 'clearlogo-billboard'], + 'videolibrary.tvshowartwhitelist': ['keyart', 'landscape', 'square', 'clearlogo', 'clearlogo-alt', 'clearlogo-billboard'], 'musiclibrary.showallitems': False, 'musiclibrary.showcompilationartists': False, 'pictures.generatethumbs': True diff --git a/script.copacetic.helper/resources/lib/utilities.py b/script.copacetic.helper/resources/lib/utilities.py index 84d5df2553..ab4af06782 100644 --- a/script.copacetic.helper/resources/lib/utilities.py +++ b/script.copacetic.helper/resources/lib/utilities.py @@ -220,18 +220,19 @@ def split(string, **kwargs): def split_random_return(string, **kwargs): import random - - separator = kwargs.get('separator', ' / ') + separator = kwargs.get('separator', '/') name = kwargs.get('name', 'SplitRandomReturn') string = random.choice(string.split(separator)) + string.replace(' ','') + string = 'Hip Hop' if 'Hip-Hop' in string else string random = random.choice(string.split(' & ')) - random = return_label(label=random, find='-', replace=' ', + random = return_label(label=random, property=False) if random != 'Sci-Fi' else random random = random.strip() window_property(name, set=random) return random - + def window_property(key, set=False, clear=False, window_id=10000, debug=False): window = Window(window_id) diff --git a/script.copacetic.helper/script.py b/script.copacetic.helper/script.py index b370407220..062f507ca0 100644 --- a/script.copacetic.helper/script.py +++ b/script.copacetic.helper/script.py @@ -1,18 +1,30 @@ # author: realcopacetic from resources.lib.script.actions import * -from resources.lib.utilities import clear_cache, sys +from resources.lib.utilities import clear_cache, sys, urllib class Main: def __init__(self, *args): try: self.params = dict(arg.split('=', 1) for arg in args) + log(f'FUCK_IN: {self.params}', force=True) + self._parse_params() except: self.params = {} function = eval(self.params['action']) function(**self.params) - + + def _parse_params(self): + try: + for key, value in self.params.items(): + if ('\'\"' and '\"\'') in value: + start_pos = value.find('\'\"') + end_pos = value.find('\"\'') + clean_title = value[start_pos+2:end_pos] + self.params[key] = clean_title + except Exception: + self.params = {} if __name__ == '__main__': Main(*sys.argv[1:])