diff --git a/script.copacetic.helper/README.md b/script.copacetic.helper/README.md index 7dc8e31f3b..284817f72b 100644 --- a/script.copacetic.helper/README.md +++ b/script.copacetic.helper/README.md @@ -14,6 +14,9 @@ All code contained in this project is licensed under GPL 3.0. ### Changelog +**1.0.6** +- Moved director/writer/studio/genre splitting to monitoring service + **1.0.5** - Added script for easily re-ordering widgets in Copacetic settings screen diff --git a/script.copacetic.helper/addon.xml b/script.copacetic.helper/addon.xml index 301e9b8fd9..1a0f95d05a 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/script/actions.py b/script.copacetic.helper/resources/lib/script/actions.py index 522c17d4b1..c76151d558 100644 --- a/script.copacetic.helper/resources/lib/script/actions.py +++ b/script.copacetic.helper/resources/lib/script/actions.py @@ -1,11 +1,9 @@ # author: realcopacetic -import urllib.parse as urllib - from resources.lib.service.art import ImageEditor -from resources.lib.utilities import (DIALOG, clear_playlists, condition, infolabel, - json_call, log, log_and_execute, skin_string, - window_property, xbmc) +from resources.lib.utilities import (DIALOG, clear_playlists, condition, + infolabel, json_call, log_and_execute, + skin_string, window_property, xbmc) def clean_filename(label=False, **kwargs): @@ -219,22 +217,6 @@ def rate_song(**kwargs): ''' -def return_label(property=True, **kwargs): - - label = kwargs.get('label', xbmc.getInfoLabel('ListItem.Label')) - find = kwargs.get('find', '.') - replace = kwargs.get('replace', ' ') - - count = label.count(find) - label = label.replace(urllib.unquote(find), - urllib.unquote(replace), - count) - if property: - window_property('Return_Label', set=label) - else: - return label - - def shuffle_artist(**kwargs): clear_playlists() @@ -243,29 +225,7 @@ def shuffle_artist(**kwargs): item={'artistid': dbid}, options={'shuffled': True}, parent='shuffle_artist') - - -def split(string, **kwargs): - separator = kwargs.get('separator', ' / ') - name = kwargs.get('name', 'Split') - - for count, value in enumerate(string.split(separator)): - window_property(f'{name}.{count}', set=value) - - -def split_random_return(string, **kwargs): - import random - - separator = kwargs.get('separator', ' / ') - name = kwargs.get('name', 'SplitRandomReturn') - string = random.choice(string.split(separator)) - random = random.choice(string.split(' & ')) - random = return_label(label=random, find='-', replace=' ', - property=False) if random != 'Sci-Fi' else random - random = random.strip() - - window_property(name, set=random) - return random + def widget_move(posa, posb, **kwargs): tempa_name = '' diff --git a/script.copacetic.helper/resources/lib/service/monitor.py b/script.copacetic.helper/resources/lib/service/monitor.py index 69159f9657..c5c105a0ef 100644 --- a/script.copacetic.helper/resources/lib/service/monitor.py +++ b/script.copacetic.helper/resources/lib/service/monitor.py @@ -10,10 +10,10 @@ from resources.lib.utilities import (CROPPED_FOLDERPATH, LOOKUP_XML, TEMP_FOLDERPATH, condition, create_dir, get_cache_size, infolabel, log, - log_and_execute, validate_path, + log_and_execute, split, + split_random_return, validate_path, window_property) - XMLSTR = ''' @@ -73,9 +73,17 @@ def _conditions_met(self): def _get_skindir(self): skindir = xbmc.getSkinDir() - if skindir == 'skin.copacetic': + if 'skin.copacetic' in skindir: return True + def _get_info(self): + split_random_return( + infolabel('ListItem.Director'), name='RandomDirector') + split_random_return( + infolabel('ListItem.Genre'), name='RandomGenre') + split(infolabel('ListItem.Writer'), name='WriterSplit') + split(infolabel('ListItem.Studio'), name='StudioSplit') + def poller(self): # video playing fullscreen if condition( @@ -83,6 +91,24 @@ def poller(self): ): self.waitForAbort(1) + # info screen visible and main menu selected + elif condition( + '[Window.Is(movieinformation) | ' + 'Window.Is(musicinformation) | ' + 'Window.Is(songinformation)] + ![' + 'Control.HasFocus(3201) | ' + 'Control.HasFocus(3202) | ' + 'Control.HasFocus(3203) | ' + 'Control.HasFocus(3204) | ' + 'Control.HasFocus(3205) | ' + 'Control.HasFocus(3206) | ' + 'Control.HasFocus(3207) | ' + 'Control.HasFocus(3208) | ' + 'Control.HasFocus(3209)]' + ): + self._on_scroll(crop=False, return_color=False, get_info=True) + self.waitForAbort(0.2) + # secondary list has focus and clearlogo view visible elif condition( 'Skin.HasSetting(Crop_Clearlogos) + ' @@ -164,15 +190,19 @@ def poller(self): self.check_settings = True self.waitForAbort(1) - def _on_scroll(self, key='ListItem', return_color=True): - current_item, current_dbid, current_dbtype = self._current_item(key) + def _on_scroll(self, key='ListItem', crop=True, return_color=True, get_info=False): + path, current_item, current_dbid, current_dbtype = self._current_item( + key) if ( current_item != self.position or current_dbid != self.dbid or current_dbtype != self.dbtype ) and not self._container_scrolling(key): - self._clearlogo_cropper( - source=key, return_color=return_color, reporting=window_property) + if crop: + self._clearlogo_cropper( + source=key, return_color=return_color, reporting=window_property) + if get_info: + self._get_info() self.position = current_item self.dbid = current_dbid self.dbtype = current_dbtype @@ -212,7 +242,7 @@ def _current_item(self, key='ListItem'): item = infolabel(f'{container}.CurrentItem') dbid = infolabel(f'{container}.ListItem.DBID') dbtype = infolabel(f'{container}.ListItem.DBType') - return (item, dbid, dbtype) + return (container, item, dbid, dbtype) def _container_scrolling(self, key='ListItem'): container = 'Container' if key == 'ListItem' else f'Container({key})' diff --git a/script.copacetic.helper/resources/lib/utilities.py b/script.copacetic.helper/resources/lib/utilities.py index baadb54acc..84d5df2553 100644 --- a/script.copacetic.helper/resources/lib/utilities.py +++ b/script.copacetic.helper/resources/lib/utilities.py @@ -1,8 +1,10 @@ # author: realcopacetic + import json import os import sys +import urllib.parse as urllib import xbmc import xbmcvfs @@ -114,6 +116,7 @@ def clear_cache(**kwargs): ET.SubElement(root, 'clearlogos') lookup_tree.write(LOOKUP_XML, encoding="utf-8") + def get_joined_items(item): if len(item) > 0 and item is not None: item = ' / '.join(item) @@ -173,6 +176,22 @@ def log_and_execute(action): xbmc.executebuiltin(action) +def return_label(property=True, **kwargs): + + label = kwargs.get('label', xbmc.getInfoLabel('ListItem.Label')) + find = kwargs.get('find', '.') + replace = kwargs.get('replace', ' ') + + count = label.count(find) + label = label.replace(urllib.unquote(find), + urllib.unquote(replace), + count) + if property: + window_property('Return_Label', set=label) + else: + return label + + def set_plugincontent(content=None, category=None): if category: setPluginCategory(int(sys.argv[1]), category) @@ -191,6 +210,29 @@ def skin_string(key, set=False, clear=False, debug=False): log(f'Skin string: Clear, {key}', force=debug) +def split(string, **kwargs): + separator = kwargs.get('separator', ' / ') + name = kwargs.get('name', 'Split') + + for count, value in enumerate(string.split(separator)): + window_property(f'{name}.{count}', set=value) + + +def split_random_return(string, **kwargs): + import random + + separator = kwargs.get('separator', ' / ') + name = kwargs.get('name', 'SplitRandomReturn') + string = random.choice(string.split(separator)) + random = random.choice(string.split(' & ')) + random = return_label(label=random, find='-', replace=' ', + 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) if set: