Skip to content

Commit

Permalink
[script.copacetic.helper] 1.0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
realcopacetic committed May 25, 2024
1 parent 7ad8e23 commit 03d8030
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 182 deletions.
17 changes: 17 additions & 0 deletions script.copacetic.helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.13" provider-name="realcopacetic">
<addon id="script.copacetic.helper" name="Copacetic Helper" version="1.0.17" provider-name="realcopacetic">
<requires>
<import addon="xbmc.python" version="3.0.1" />
<import addon="script.module.pil" version="5.1.0" />
Expand Down
6 changes: 3 additions & 3 deletions script.copacetic.helper/resources/lib/plugin/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
230 changes: 87 additions & 143 deletions script.copacetic.helper/resources/lib/script/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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', '')
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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})'):
Expand All @@ -239,118 +251,50 @@ 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)]
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:
xbmc.executebuiltin(
f'Skin.ToggleSetting(Widget{item[0]}_{key})')
Loading

0 comments on commit 03d8030

Please sign in to comment.