Skip to content

Commit

Permalink
[script.copacetic.helper 1.0.6]
Browse files Browse the repository at this point in the history
- Moved director/writer/studio/genre splitting to monitoring service
  • Loading branch information
realcopacetic committed Jul 11, 2023
1 parent 47dffbf commit ecbb64f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 53 deletions.
3 changes: 3 additions & 0 deletions script.copacetic.helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion script.copacetic.helper/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<addon id="script.copacetic.helper" name="Copacetic Helper" version="1.0.5" provider-name="realcopacetic">
<addon id="script.copacetic.helper" name="Copacetic Helper" version="1.0.6" provider-name="realcopacetic">
<requires>
<import addon="xbmc.python" version="3.0.1" />
<import addon="script.module.pil" version="5.1.0" />
Expand Down
48 changes: 4 additions & 44 deletions script.copacetic.helper/resources/lib/script/actions.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()

Expand All @@ -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 = ''
Expand Down
46 changes: 38 additions & 8 deletions script.copacetic.helper/resources/lib/service/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '''<?xml version="1.0" encoding="utf-8"?>
<data>
<clearlogos />
Expand Down Expand Up @@ -73,16 +73,42 @@ 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(
'VideoPlayer.IsFullscreen'
):
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) + '
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})'
Expand Down
42 changes: 42 additions & 0 deletions script.copacetic.helper/resources/lib/utilities.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# author: realcopacetic


import json
import os
import sys
import urllib.parse as urllib

import xbmc
import xbmcvfs
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit ecbb64f

Please sign in to comment.