Skip to content

Commit

Permalink
added ui methods
Browse files Browse the repository at this point in the history
  • Loading branch information
codingPF committed Oct 8, 2023
1 parent 9584286 commit 798d0f9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
41 changes: 41 additions & 0 deletions resources/lib/kodiUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import time
import xbmcplugin
import xbmcgui
import xbmc
import datetime
import resources.lib.appContext as appContext
import resources.lib.utils as pyUtils

class KodiUI(object):

Expand All @@ -35,7 +37,45 @@ def __init__(self, pAddon, pContentType = 'video', pSortMethods = None, pCacheTo
self.listItems = []
self.startTime = 0
self.tzBase = datetime.datetime.fromtimestamp(0)
# just for documentation
self.docuContentTypes = ['','video','movies']

######################################

def addDirectories(self, pDataArray, pmode = None):
self.logger.debug('addDirectory')
for e in pDataArray:
self.logger.debug('addDirectory {} : {} - {} - {} - {}', (pmode or e.mode), e.id, e.title, e.url, e.image)
tgtUrl = self.addon.generateUrl({
'mode': (pmode or e.mode),
'urlB64': pyUtils.b64encode(e.url)
})
self.addDirectoryItem(pTitle = e.title, pUrl = tgtUrl, pIcon = e.image)

def addItems(self, pDataArray, pmode = None):
self.logger.debug('addItems')
for e in pDataArray:
self.logger.debug('addItems {} : {} - {} - {} - {} - {} - {} - {}', (pmode or e.mode), e.id, e.title, e.channel, e.aired, e.duration, e.image, e.url)
tgtUrl = self.addon.generateUrl({
'mode': (pmode or e.mode),
'urlB64': pyUtils.b64encode(e.url)
})
self.addListItem(pTitle = e.title, pUrl = tgtUrl, pPlot = e.title, pDuration = e.duration, pAired = e.aired, pIcon = e.image)

######################################

def addDirectoryItem(self, pTitle, pUrl, pSortTitle = None, pIcon = None, pContextMenu = None):
self.addListItem(
pTitle=pTitle,
pUrl=pUrl,
pSortTitle=None,
pPlot=None,
pDuration= None,
pAired= None,
pIcon=pIcon,
pContextMenu=pContextMenu,
pPlayable='False',
pFolder=True)

def addListItem(self, pTitle, pUrl, pSortTitle = None, pPlot = None, pDuration = None, pAired = None, pIcon = None, pContextMenu = None, pPlayable = 'True', pFolder = False):
#
Expand Down Expand Up @@ -89,6 +129,7 @@ def addListItem(self, pTitle, pUrl, pSortTitle = None, pPlot = None, pDuration =
self.listItems.append((pUrl, listItem, pFolder))
#

# add aöö generated list items in one go
def render(self):
#
for method in self.allSortMethods:
Expand Down
34 changes: 21 additions & 13 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import string
import json
import datetime
import time
import base64
from contextlib import closing
from codecs import open
Expand Down Expand Up @@ -87,6 +88,11 @@ def epoch_from_timestamp(pTimestampString, pTsPatter='%Y-%m-%dT%H:%M:%S.%f%z'):
new_time = datetime.datetime.strptime(pTimestampString, pTsPatter)
return int(new_time.timestamp())

def datetime_from_utc_to_local(utc_datetime):
now_timestamp = time.time()
offset = datetime.datetime.fromtimestamp(now_timestamp) - datetime.datetime.utcfromtimestamp(now_timestamp)
return utc_datetime + offset

#########################################################################
# FILE functions

Expand Down Expand Up @@ -188,19 +194,6 @@ def file_cleanupname(val):
cStr = re.sub(r'(?u)[^-\w.]', '', cStr)
return cStr

#########################################################################################


def loadJson(filename):
with closing(open(filename, encoding='utf-8')) as json_file:
data = json.load(json_file)
return data


def saveJson(filename, data):
with closing(open(filename, 'w', encoding='utf-8')) as json_file:
json.dump(cache, json_file)

def extractJsonValue(rootElement, *args):
if rootElement is None:
return None
Expand All @@ -218,6 +211,20 @@ def extractJsonValue(rootElement, *args):
else:
return None
return root;

#########################################################################################


def loadJson(filename):
with closing(open(filename, encoding='utf-8')) as json_file:
data = json.load(json_file)
return data


def saveJson(filename, data):
with closing(open(filename, 'w', encoding='utf-8')) as json_file:
json.dump(cache, json_file)

##########################################################################################


Expand All @@ -234,6 +241,7 @@ def b64decode(pMessage):
message = message_bytes.decode('ascii')
return message

###########################################################################################

def url_to_string(url, chunk_size=65536):
output = ''
Expand Down

0 comments on commit 798d0f9

Please sign in to comment.