Skip to content

Commit

Permalink
SPG v.0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunatixz committed Jan 6, 2025
1 parent 759a232 commit 3346ffe
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 45 deletions.
2 changes: 1 addition & 1 deletion addons.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addons>
<addon id="plugin.program.smartplaylist.generator" version="0.1.6" name="Smartplaylist Generator" provider-name="Lunatixz">
<addon id="plugin.program.smartplaylist.generator" version="0.1.7" name="Smartplaylist Generator" provider-name="Lunatixz">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.six" version="1.0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion addons.xml.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73f4c0b8e17bdc6fef89646af386047e
d8df488cebfe28435351e026801d0161
8 changes: 4 additions & 4 deletions plugin.program.smartplaylist.generator/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.program.smartplaylist.generator" version="0.1.6" name="Smartplaylist Generator" provider-name="Lunatixz">
<addon id="plugin.program.smartplaylist.generator" version="0.1.7" name="Smartplaylist Generator" provider-name="Lunatixz">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.six" version="1.0.0"/>
Expand All @@ -13,17 +13,17 @@
</extension>
<extension point="xbmc.service" library="resources/lib/service.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Generate Smartplaylists from third-party lists.</summary>
<description lang="en_GB">Generate Smartplaylists from third-party lists.</description>
<platform>all</platform>
<license>GPL-3.0-or-later</license>
<source>https://github.com/Lunatixz/KODI_Addons/tree/master/plugin.program.smartplaylist.generator</source>
<forum>https://forum.kodi.tv/showthread.php?tid=379825</forum>
<disclaimer lang="en_GB">BETA PROJECT; SUBJECT TO BUGS</disclaimer>
<reuselanguageinvoker>false</reuselanguageinvoker>
<assets>
<icon>resources/images/icon.png</icon>
<fanart>resources/images/fanart.jpg</fanart>
</assets>
<summary lang="en_GB">Generate Smartplaylists from third-party lists.</summary>
<description lang="en_GB">Generate Smartplaylists from third-party lists.</description>
<disclaimer lang="en_GB">BETA PROJECT; SUBJECT TO BUGS</disclaimer>
</extension>
</addon>
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ msgstr ""
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgctxt "Addon Summary"
msgid "Generate Smartplaylists from third-party lists."
msgstr ""

msgctxt "Addon Description"
msgid "Generate Smartplaylists from third-party lists."
msgstr ""

msgctxt "Addon Disclaimer"
msgid "BETA PROJECT; SUBJECT TO BUGS"
msgstr ""

msgctxt "#32000"
msgid "General"
msgstr ""
Expand Down
64 changes: 48 additions & 16 deletions plugin.program.smartplaylist.generator/resources/lib/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ def __init__(self, sysARG=sys.argv):
self.cache = SimpleCache()
self.cache.enable_mem_cache = False

self.dia = None
self.msg = ''
self.pct = 0
self.tot = 0
self.cnt = 0
self.cntpct = 0
self.sysARG = sysARG
self.kodi = Kodi(self.cache)
self.modules = {LANGUAGE(32100):trakt.Trakt(self.cache)}
self.dia = None
self.msg = ''
self.pct = 0
self.tot = 0
self.cnt = 0
self.cntpct = 0
self.sysARG = sysARG
self.kodi = Kodi(self.cache)
self.modules = {LANGUAGE(32100):trakt.Trakt(self.cache)}
self.hasPseudo = xbmc.getCondVisibility('System.HasAddon(plugin.video.pseudotv.live)')


def log(self, msg, level=xbmc.LOGDEBUG):
Expand All @@ -47,11 +48,9 @@ def log(self, msg, level=xbmc.LOGDEBUG):

def build_lists(self, source, lists):
def __buildMenu(item): return self.kodi.buildMenuListItem(item.get('name'),item.get('description'),item.get('icon',ICON),url=item.get('id'))
with self.kodi.busy_dialog():
listitems = poolit(__buildMenu)(lists)
with self.kodi.busy_dialog(): listitems = poolit(__buildMenu)(lists)
selects = self.kodi.selectDialog(listitems,header='%s %s'%(source,ADDON_NAME),preselect=self.kodi.findItemsInLST(listitems, self.kodi.getCacheSetting('%s.%s'%(ADDON_ID,source)), item_key='getPath', val_key='id'),)
if not selects is None:
self.log('build_lists, source = %s, saving = %s'%(source,self.kodi.setCacheSetting('%s.%s'%(ADDON_ID,source),[{'name':listitems[select].getLabel(),'id':listitems[select].getPath(),'icon':listitems[select].getArt('icon')} for select in selects])))
if not selects is None: self.log('build_lists, source = %s, saving = %s'%(source,self.kodi.setCacheSetting('%s.%s'%(ADDON_ID,source),[{'name':listitems[select].getLabel(),'id':listitems[select].getPath(),'icon':listitems[select].getArt('icon')} for select in selects])))


def match_items(self, source_items):
Expand Down Expand Up @@ -87,7 +86,7 @@ def __match(list_item, type, kodi_items):
return matches


def create_xsp(self, list_name, match_items, pretty_print=True):
def create_xsp(self, list_name, match_items, pretty_print=True):
def __indent(elem, level=0):
"""
Indent XML for pretty printing
Expand All @@ -106,6 +105,8 @@ def __indent(elem, level=0):
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i


mixed_names = []
for type, items in (list(match_items.items())):
if len(items) == 0: continue
match_item = {'movies' :{'match_type':type , 'match_field':'title' ,'match_key':'title','match_opr':'is'},
Expand All @@ -118,6 +119,7 @@ def __indent(elem, level=0):
root.set("type",match_item.get('match_type'))
name = ET.SubElement(root, "name")
name.text = "%s - %s"%(list_name,type.title().replace('Tvshows','TV Shows'))
mixed_names.append("%s - %s"%(list_name,type.title().replace('Tvshows','TV Shows')))
match = ET.SubElement(root, "match")
match.text = "all"
rule = ET.SubElement(root, "rule")
Expand All @@ -144,8 +146,38 @@ def __indent(elem, level=0):
tree.write(fle, encoding='utf-8', xml_declaration=True)
fle.close()

if REAL_SETTINGS.getSetting('Notify_Enable') == "true":
self.kodi.notificationDialog('%s %s:\n%s'%(LANGUAGE(32017),{True:LANGUAGE(32020),False:LANGUAGE(32021)}[xbmcvfs.exists(path)],list_name))
if REAL_SETTINGS.getSetting('Notify_Enable') == "true": self.kodi.notificationDialog('%s %s:\n%s'%(LANGUAGE(32017),{True:LANGUAGE(32020),False:LANGUAGE(32021)}[xbmcvfs.exists(path)],list_name))
else: self.kodi.notificationDialog(LANGUAGE(32024)%(validString(list_name)))

if self.hasPseudo and len(mixed_names) > 1:
root = ET.Element("smartplaylist")
root.set("type","mixed")
name = ET.SubElement(root, "name")
name.text = "%s - Mixed (PseudoTV)"%(list_name)
match = ET.SubElement(root, "match")
match.text = "all"

values = []
for idx, name in enumerate(mixed_names):
rule = ET.SubElement(root, "rule")
rule.set("field", "playlist")
rule.set("operator", "is")
values.append(name)
value = ET.SubElement(rule, "value")
value.text = name

if len(values) > 0:
self.log('create_xsp, Out: %s'%(ET.tostring(root, encoding='unicode')))
if pretty_print: __indent(root)
tree = ET.ElementTree(root)
path = REAL_SETTINGS.getSetting('XSP_LOC').replace(os.path.basename(os.path.normpath(REAL_SETTINGS.getSetting('XSP_LOC'))),"Mixed")
path = os.path.join(xbmcvfs.translatePath(path),'%s.xsp'%("%s - %s"%(validString(list_name),"Mixed")))
self.log('create_xsp, File: %s'%(path))
fle = xbmcvfs.File(path, 'w')
tree.write(fle, encoding='utf-8', xml_declaration=True)
fle.close()

if REAL_SETTINGS.getSetting('Notify_Enable') == "true": self.kodi.notificationDialog('%s %s:\n%s'%(LANGUAGE(32017),{True:LANGUAGE(32020),False:LANGUAGE(32021)}[xbmcvfs.exists(path)],list_name))
else: self.kodi.notificationDialog(LANGUAGE(32024)%(validString(list_name)))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ def executors(self, func, items=[], *args, **kwargs):
self.log("executors, func = %s, items = %s"%(func.__name__,len(items)))
results = []
with ThreadPoolExecutor(self.ThreadCount) as executor:
try:
for result in executor.map(self.wrapped_partial(func, *args, **kwargs), items):
results.append(result)
try: [results.append(result) for result in executor.map(self.wrapped_partial(func, *args, **kwargs), items)]
except Exception as e: self.log("executors, func = %s, items = %s failed! %s\nargs = %s, kwargs = %s"%(func.__name__,len(items),e,args,kwargs), xbmc.LOGERROR)
return results

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def convert_type(self, list_type):


def clean_string(self, string):
return string.replace('copy','').replace('\r\n\t','')
return string.replace('copy','').replace('\r\n\t','').rstrip()


@cacheit(expiration=datetime.timedelta(minutes=15))
Expand Down
11 changes: 4 additions & 7 deletions plugin.program.smartplaylist.generator/resources/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ def _start(self):
self.log('_start')
while not self.monitor.abortRequested():
if self.monitor.waitForAbort(300): break
else: self._run()
else: self._run(int(REAL_SETTINGS.getSetting('Run_Every')),strpTime(REAL_SETTINGS.getSetting('Last_Update')))


def _run(self):
run_every = int(REAL_SETTINGS.getSetting('Run_Every'))
def _run(self, run_every, last_update):
if run_every > 0:
last_update = strpTime(REAL_SETTINGS.getSetting('Last_Update'))
run_seconds = ((run_every * 3600) + 1800) #service run time in seconds with 30min padding to allow cache time to clear before run
now_time = datetime.datetime.now()
run_time = (last_update + datetime.timedelta(seconds=run_seconds))
if now_time >= run_time:
self.log('_run, now = %s, run = %s, running = %s'%(now_time,run_time,now_time >= run_time))
if datetime.datetime.now() >= run_time:
self.log('_run, Starting %s Service'%(ADDON_NAME))
self.kodi.executebuiltin('RunScript(special://home/addons/%s/resources/lib/default.py, Run_All)'%(ADDON_ID))

if __name__ == '__main__': Service()._start()
Binary file not shown.

0 comments on commit 3346ffe

Please sign in to comment.