Skip to content

Commit

Permalink
- added possibility in convertors to output info in one single string…
Browse files Browse the repository at this point in the history
… with separator character
  • Loading branch information
DimitarCC authored and Huevos committed Oct 9, 2023
1 parent 5455b31 commit 7278735
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 21 deletions.
8 changes: 8 additions & 0 deletions lib/python/Components/Converter/Converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ class Converter(Element):
def __init__(self, arguments):
Element.__init__(self)
self.converter_arguments = arguments
self.separatorChar = ""

def __repr__(self):
return str(type(self)) + "(" + self.converter_arguments + ")"

def handleCommand(self, cmd):
self.source.handleCommand(cmd)

def appendToStringWithSeparator(self, str, part):
if str == "":
str = part
else:
str = str + " " + self.separatorChar + " " + part
return str
26 changes: 25 additions & 1 deletion lib/python/Components/Converter/EventName.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from Components.Converter.genre import getGenreStringSub
from Components.config import config
from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
from time import localtime, mktime, strftime
from time import time, localtime, mktime, strftime


class ETSIClassifications(dict):
Expand Down Expand Up @@ -106,6 +106,8 @@ class EventName(Converter):
RATINGCOUNTRY = 32
RATINGICON = 33

FORMAT_STRING = 34

KEYWORDS = {
# Arguments...
"Name": ("type", NAME),
Expand Down Expand Up @@ -162,6 +164,12 @@ def __init__(self, type):
parse = ","
type.replace(";", parse) # Some builds use ";" as a separator, most use ",".
args = [arg.strip() for arg in type.split(parse)]
self.parts = args

if len(self.parts) > 1:
self.type = self.FORMAT_STRING
self.separatorChar = self.parts[0]

for arg in args:
name, value = self.KEYWORDS.get(arg, ("Error", None))
if name == "Error":
Expand Down Expand Up @@ -307,6 +315,22 @@ def getText(self):
rating = event.getParentalData()
if rating:
return rating.getCountryCode().upper()
elif self.type == self.FORMAT_STRING:
begin = event.getBeginTime()
end = begin + event.getDuration()
now = int(time())
t_start = localtime(begin)
t_end = localtime(end)
if begin <= now <= end:
duration = end - now
duration_str = "+%d min" % (duration / 60)
else:
duration = event.getDuration()
duration_str = "%d min" % (duration / 60)
start_time_str = "%2d:%02d" % (t_start.tm_hour, t_start.tm_min)
end_time_str = "%2d:%02d" % (t_end.tm_hour, t_end.tm_min)
res_str = "%s - %s %s %s" % (start_time_str, end_time_str, self.separator, duration_str)
return res_str
return ""

text = property(getText)
23 changes: 22 additions & 1 deletion lib/python/Components/Converter/MovieInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Components.Converter.Converter import Converter
from Components.Element import cached
from Components.Harddisk import bytesToHumanReadable
from time import localtime, strftime

# Handle any invalid utf8 in a description to avoid crash when
# displaying it.
Expand All @@ -28,6 +29,7 @@ class MovieInfo(Converter):
MOVIE_REC_FILESIZE = 4 # filesize of recording
MOVIE_FULL_DESCRIPTION = 5 # combination of short and long description when available
MOVIE_NAME = 6 # recording name
FORMAT_STRING = 6 # it is formatted string based on parameter and with defined separator

KEYWORDS = {
# Arguments...
Expand All @@ -46,6 +48,7 @@ class MovieInfo(Converter):
}

def __init__(self, type):
Converter.__init__(self, type)
self.textEvent = None
self.type = None
self.separator = "\n"
Expand All @@ -54,6 +57,12 @@ def __init__(self, type):
parse = ","
type.replace(";", parse) # Some builds use ";" as a separator, most use ",".
args = [arg.strip() for arg in type.split(parse)]

self.parts = args
if len(self.parts) > 1:
self.type = self.FORMAT_STRING
self.separatorChar = self.parts[0]

for arg in args:
name, value = self.KEYWORDS.get(arg, ("Error", None))
if name == "Error":
Expand All @@ -63,7 +72,6 @@ def __init__(self, type):
if ((name == "Error") or (type is None)):
print("[MovieInfo] Valid arguments are: ShortDescription|MetaDescription|FullDescription|RecordServiceName|RecordServiceRef|FileSize.")
print("[MovieInfo] Valid options for descriptions are: Separated|NotSeparated|Trimmed|NotTrimmed.")
Converter.__init__(self, type)

def destroy(self):
Converter.destroy(self)
Expand Down Expand Up @@ -133,6 +141,19 @@ def getText(self):
return info.getInfoString(service, iServiceInformation.sServiceref)
elif self.type == self.MOVIE_REC_FILESIZE:
return self.getFileSize(service, info)
elif self.type == self.FORMAT_STRING:
timeCreate = strftime("%A %d %b %Y", localtime(info.getInfo(service, iServiceInformation.sTimeCreate)))
duration = "%d min" % (info.getLength(service) / 60)
filesize = "%d MB" % (info.getInfoObject(service, iServiceInformation.sFileSize) / (1024*1024))
res_str = ""
for x in self.parts[1:]:
if x == "TIMECREATED" and timeCreate != '':
res_str = self.appendToStringWithSeparator(res_str, timeCreate)
if x == "DURATION" and duration != '':
res_str = self.appendToStringWithSeparator(res_str, duration)
if x == "FILESIZE" and filesize != '':
res_str = self.appendToStringWithSeparator(res_str, filesize)
return res_str
return ""

def __getCollectionDescription(self, service):
Expand Down
93 changes: 74 additions & 19 deletions lib/python/Components/Converter/ServiceName.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ class ServiceName(Converter):
PROVIDER = 3
REFERENCE = 4
EDITREFERENCE = 5
FORMAT_STRING = 6

def __init__(self, type):
Converter.__init__(self, type)
self.epgQuery = eEPGCache.getInstance().lookupEventTime
self.mode = ""
if ';' in type:
type, self.mode = type.split(';')
if type == "Provider":
self.type = self.PROVIDER
elif type == "Reference":
self.type = self.REFERENCE
elif type == "EditReference":
self.type = self.EDITREFERENCE
elif type == "NameOnly":
self.type = self.NAME_ONLY
elif type == "NameAndEvent":
self.type = self.NAME_EVENT
self.parts = type.split(",")
if len(self.parts) > 1:
self.type = self.FORMAT_STRING
self.separatorChar = self.parts[0]
else:
self.type = self.NAME
if ';' in type:
type, self.mode = type.split(';')
if type == "Provider":
self.type = self.PROVIDER
elif type == "Reference":
self.type = self.REFERENCE
elif type == "EditReference":
self.type = self.EDITREFERENCE
elif type == "NameOnly":
self.type = self.NAME_ONLY
elif type == "NameAndEvent":
self.type = self.NAME_EVENT
else:
self.type = self.NAME

@cached
def getText(self):
Expand All @@ -49,10 +55,7 @@ def getText(self):
return ""

if self.type == self.NAME or self.type == self.NAME_ONLY or self.type == self.NAME_EVENT:
name = service and info.getName(service)
if name is None:
name = info.getName()
name = name.replace('\xc2\x86', '').replace('\xc2\x87', '').replace('_', ' ')
name = self.getName(service, info)
if self.type == self.NAME_EVENT:
act_event = info and info.getEvent(0)
if not act_event and info:
Expand All @@ -64,15 +67,15 @@ def getText(self):
return "%s - %s" % (name, act_event.getEventName())
elif self.type != self.NAME_ONLY and config.usage.show_infobar_channel_number.value and hasattr(self.source, "serviceref") and self.source.serviceref and '0:0:0:0:0:0:0:0:0' not in self.source.serviceref.toString():
numservice = self.source.serviceref
num = numservice and numservice.getChannelNum() or None
num = self.getNumber(numservice, info)
if num is not None:
return str(num) + ' ' + name
else:
return name
else:
return name
elif self.type == self.PROVIDER:
return info.getInfoString(iServiceInformation.sProvider)
return self.getProvider(service, info)
elif self.type == self.REFERENCE or self.type == self.EDITREFERENCE and hasattr(self.source, "editmode") and self.source.editmode:
if not service:
refstr = info.getInfoString(iServiceInformation.sServiceref)
Expand All @@ -86,9 +89,61 @@ def getText(self):
if nref:
service = nref
return service.toString()
elif self.type == self.FORMAT_STRING:
name = self.getName(service, info)
num = self.getNumber(service, info)
provider = self.getProvider(service, info)
orbpos = self.getOrbitalPos(service, info)
res_str = ""
for x in self.parts[1:]:
if x == "NUMBER" and num != '':
res_str = self.appendToStringWithSeparator(res_str, num)
if x == "NAME" and name != '':
res_str = self.appendToStringWithSeparator(res_str, name)
if x == "ORBPOS" and orbpos != '':
res_str = self.appendToStringWithSeparator(res_str, orbpos)
if x == "PROVIDER" and provider is not None and provider != '':
res_str = self.appendToStringWithSeparator(res_str, provider)
return res_str

text = property(getText)

def changed(self, what):
if what[0] != self.CHANGED_SPECIFIC or what[1] in (iPlayableService.evStart,):
Converter.changed(self, what)

def getName(self, ref, info):
name = ref and info.getName(ref)
if name is None:
name = info.getName()
return name.replace('\xc2\x86', '').replace('\xc2\x87', '').replace('_', ' ')

def getNumber(self, ref, info):
if not ref:
ref = eServiceReference(info.getInfoString(iServiceInformation.sServiceref))
num = ref and ref.getChannelNum() or None
if num is not None:
num = str(num)
return num

def getProvider(self, ref, info):
if ref:
return info.getInfoString(ref, iServiceInformation.sProvider)
return info.getInfoString(iServiceInformation.sProvider)

def getOrbitalPos(self, ref, info):
orbitalpos = ""
if ref:
tp_data = info.getInfoObject(ref, iServiceInformation.sTransponderData)
else:
tp_data = info.getInfoObject(iServiceInformation.sTransponderData)
if tp_data is not None:
try:
position = tp_data["orbital_position"]
if position > 1800: # west
orbitalpos = "%.1f " %(float(3600 - position)/10) + _("W")
else:
orbitalpos = "%.1f " %(float(position)/10) + _("E")
except:
pass
return orbitalpos

0 comments on commit 7278735

Please sign in to comment.