Skip to content

Commit

Permalink
Merge pull request #3799 from DimitarCC/convertors-extend
Browse files Browse the repository at this point in the history
Added possibility to make formatted string in converters
  • Loading branch information
littlesat authored Oct 18, 2023
2 parents abe5e14 + 3481845 commit 0e747fc
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 63 deletions.
7 changes: 7 additions & 0 deletions lib/python/Components/Converter/Converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ def __repr__(self):

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

def appendToStringWithSeparator(self, str, part):
if str == "":
str = part
else:
str = str + " " + self.separator + " " + part
return str
77 changes: 50 additions & 27 deletions lib/python/Components/Converter/EventName.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from Components.Converter.genre import getGenreStringSub
from Components.config import config
from Components.UsageConfig import dropEPGNewLines, replaceEPGSeparator
from time import time, localtime


class EventName(Converter):
Expand All @@ -20,37 +21,43 @@ class EventName(Converter):
PDCTIME = 11
PDCTIMESHORT = 12
ISRUNNINGSTATUS = 13
FORMAT_STRING = 14

def __init__(self, type):
Converter.__init__(self, type)
if type == "Description":
self.type = self.SHORT_DESCRIPTION
elif type == "ExtendedDescription":
self.type = self.EXTENDED_DESCRIPTION
elif type == "FullDescription":
self.type = self.FULL_DESCRIPTION
elif type == "ID":
self.type = self.ID
elif type == "NameNow":
self.type = self.NAME_NOW
elif type == "NameNext":
self.type = self.NAME_NEXT
elif type == "Genre":
self.type = self.GENRE
elif type == "Rating":
self.type = self.RATING
elif type == "SmallRating":
self.type = self.SRATING
elif type == "Pdc":
self.type = self.PDC
elif type == "PdcTime":
self.type = self.PDCTIME
elif type == "PdcTimeShort":
self.type = self.PDCTIMESHORT
elif type == "IsRunningStatus":
self.type = self.ISRUNNINGSTATUS
self.parts = type.split(",")
if len(self.parts) > 1:
self.type = self.FORMAT_STRING
self.separator = self.parts[0]
else:
self.type = self.NAME
if type == "Description":
self.type = self.SHORT_DESCRIPTION
elif type == "ExtendedDescription":
self.type = self.EXTENDED_DESCRIPTION
elif type == "FullDescription":
self.type = self.FULL_DESCRIPTION
elif type == "ID":
self.type = self.ID
elif type == "NameNow":
self.type = self.NAME_NOW
elif type == "NameNext":
self.type = self.NAME_NEXT
elif type == "Genre":
self.type = self.GENRE
elif type == "Rating":
self.type = self.RATING
elif type == "SmallRating":
self.type = self.SRATING
elif type == "Pdc":
self.type = self.PDC
elif type == "PdcTime":
self.type = self.PDCTIME
elif type == "PdcTimeShort":
self.type = self.PDCTIMESHORT
elif type == "IsRunningStatus":
self.type = self.ISRUNNINGSTATUS
else:
self.type = self.NAME

@cached
def getBoolean(self):
Expand Down Expand Up @@ -152,5 +159,21 @@ def getText(self):
return _("reserved for future use")
return _("undefined")
return ""
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

text = property(getText)
49 changes: 35 additions & 14 deletions lib/python/Components/Converter/MovieInfo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from os.path import basename, normpath
from Components.Converter.Converter import Converter
from Components.Element import cached, ElementError
from enigma import iServiceInformation, eServiceReference
from ServiceReference import ServiceReference
from Components.UsageConfig import dropEPGNewLines, replaceEPGSeparator
from Components.config import config
from time import localtime, strftime


class MovieInfo(Converter):
Expand All @@ -14,23 +16,29 @@ class MovieInfo(Converter):
MOVIE_REC_FILESIZE = 3 # filesize of recording
MOVIE_FULL_DESCRIPTION = 4 # short and exended description
MOVIE_NAME = 5 # recording name
FORMAT_STRING = 6 # it is formatted string based on parameter and with defined separator

def __init__(self, type):
if type == "ShortDescription":
self.type = self.MOVIE_SHORT_DESCRIPTION
elif type == "MetaDescription":
self.type = self.MOVIE_META_DESCRIPTION
elif type == "RecordServiceName":
self.type = self.MOVIE_REC_SERVICE_NAME
elif type == "FileSize":
self.type = self.MOVIE_REC_FILESIZE
elif type == "FullDescription":
self.type = self.MOVIE_FULL_DESCRIPTION
elif type == "Name":
self.type = self.MOVIE_NAME
else:
raise ElementError("'%s' is not <ShortDescription|MetaDescription|RecordServiceName|FileSize|FullDescription|Name> for MovieInfo converter" % type)
Converter.__init__(self, type)
self.parts = type.split(",")
if len(self.parts) > 1:
self.type = self.FORMAT_STRING
self.separator = self.parts[0]
else:
if type == "ShortDescription":
self.type = self.MOVIE_SHORT_DESCRIPTION
elif type == "MetaDescription":
self.type = self.MOVIE_META_DESCRIPTION
elif type == "RecordServiceName":
self.type = self.MOVIE_REC_SERVICE_NAME
elif type == "FileSize":
self.type = self.MOVIE_REC_FILESIZE
elif type == "FullDescription":
self.type = self.MOVIE_FULL_DESCRIPTION
elif type == "Name":
self.type = self.MOVIE_NAME
else:
raise ElementError("'%s' is not <ShortDescription|MetaDescription|RecordServiceName|FileSize|FullDescription|Name> for MovieInfo converter" % type)

@cached
def getText(self):
Expand Down Expand Up @@ -82,6 +90,19 @@ def getText(self):
elif filesize >= 1024:
return "%.0f %s" % (filesize / 1024.0, _("kB"))
return "%d %s" % (filesize, _("B"))
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 ""

text = property(getText)
96 changes: 74 additions & 22 deletions lib/python/Components/Converter/ServiceName.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ class ServiceName(Converter):
REFERENCE = 2
EDITREFERENCE = 3
NUMBER = 4
FORMAT_STRING = 5

def __init__(self, type):
Converter.__init__(self, type)

if type == "Provider":
self.type = self.PROVIDER
elif type == "Reference":
self.type = self.REFERENCE
elif type == "EditReference":
self.type = self.EDITREFERENCE
elif type == "Number":
self.type = self.NUMBER
self.parts = type.split(",")
if len(self.parts) > 1:
self.type = self.FORMAT_STRING
self.separator = self.parts[0]
else:
self.type = self.NAME
if type == "Provider":
self.type = self.PROVIDER
elif type == "Reference":
self.type = self.REFERENCE
elif type == "EditReference":
self.type = self.EDITREFERENCE
elif type == "Number":
self.type = self.NUMBER
else:
self.type = self.NAME

@cached
def getText(self):
Expand All @@ -38,12 +44,9 @@ def getText(self):
if not info:
return ""
if self.type == self.NAME:
name = ref and info.getName(ref)
if name is None:
name = info.getName()
return name.replace('\xc2\x86', '').replace('\xc2\x87', '').replace('_', ' ')
return self.getName(ref, info)
elif self.type == self.PROVIDER:
return info.getInfoString(iServiceInformation.sProvider)
return self.getProvider(ref, info)
elif self.type == self.REFERENCE or self.type == self.EDITREFERENCE and hasattr(self.source, "editmode") and self.source.editmode:
if not ref:
return info.getInfoString(iServiceInformation.sServiceref)
Expand All @@ -52,17 +55,66 @@ def getText(self):
ref = nref
return ref.toString()
elif self.type == self.NUMBER:
if not ref:
ref = eServiceReference(info.getInfoString(iServiceInformation.sServiceref))
num = ref and ref.getChannelNum() or None
if num is None:
num = '---'
else:
num = str(num)
return num
return self.getNumber(ref, info)
elif self.type == self.FORMAT_STRING:
name = self.getName(ref, info)
num = self.getNumber(ref, info)
provider = self.getProvider(ref, info)
orbpos = self.getOrbitalPos(ref, 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 None:
num = '---'
else:
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 0e747fc

Please sign in to comment.