Skip to content

Commit

Permalink
[Fixed] Some converters
Browse files Browse the repository at this point in the history
[Added] AudioIcon, AudioInfo, VolumeText converter and renderers
  • Loading branch information
DimitarCC committed Dec 9, 2023
1 parent 6f1e33c commit 34536ad
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/python/Components/Addons/ScreenHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def buildEntry(self, sequence):
pos=(0, yPos),
size=(self.instance.size().width(), itemHeight),
font=2 if isOneItem and idx == 0 else idx, flags=RT_HALIGN_LEFT | RT_VALIGN_CENTER,
text=x.text,
text=x.text.rstrip(">"),
color=foreColor, color_sel=foreColor,
backcolor=self.backgroundColor, backcolor_sel=self.backgroundColor))
return res
Expand Down
48 changes: 31 additions & 17 deletions lib/python/Components/Converter/PliExtraInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
from Tools.Transponder import ConvertToHumanReadable
from Tools.GetEcmInfo import GetEcmInfo
from Components.Converter.Poll import Poll
from Tools.Directories import pathExists
from skin import parameters

caid_data = (
("0x0100", "0x01ff", "Seca", "S", True),
("0x0500", "0x05ff", "Via", "V", True),
("0x0600", "0x06ff", "Irdeto", "I", True),
("0x0900", "0x09ff", "NDS", "Nd", True),
("0x0b00", "0x0bff", "Conax", "Co", True),
("0x0d00", "0x0dff", "CryptoW", "Cw", True),
("0x0e00", "0x0eff", "PowerVU", "P", False),
("0x1000", "0x10FF", "Tandberg", "TB", False),
("0x1700", "0x17ff", "Beta", "B", True),
("0x1800", "0x18ff", "Nagra", "N", True),
("0x2600", "0x2600", "Biss", "Bi", False),
("0x2700", "0x2710", "Dre3", "D3", False),
("0x4ae0", "0x4ae1", "Dre", "D", False),
("0x4aee", "0x4aee", "BulCrypt", "B1", False),
("0x5581", "0x5581", "BulCrypt", "B2", False),
("0x5601", "0x5604", "Verimatrix", "Vm", False)
("0x100", "0x1ff", "Seca", "S", "SECA", True),
("0x500", "0x5ff", "Via", "V", "VIA", True),
("0x600", "0x6ff", "Irdeto", "I", "IRD", True),
("0x900", "0x9ff", "NDS", "Nd", "NDS", True),
("0xb00", "0xbff", "Conax", "Co", "CONAX", True),
("0xd00", "0xdff", "CryptoW", "Cw", "CRW", True),
("0xe00", "0xeff", "PowerVU", "P", "PV", False),
("0x1000", "0x10FF", "Tandberg", "TB", "TAND", False),
("0x1700", "0x17ff", "Beta", "B", "BETA", True),
("0x1800", "0x18ff", "Nagra", "N", "NAGRA", True),
("0x2600", "0x2600", "Biss", "Bi", "BiSS", False),
("0x2700", "0x2710", "Dre3", "D3", "DRE3", False),
("0x4ae0", "0x4ae1", "Dre", "D", "DRE", False),
("0x4aee", "0x4aee", "BulCrypt", "B1", "BUL", False),
("0x5581", "0x5581", "BulCrypt", "B2", "BUL", False)
)

# stream type to codec map
Expand Down Expand Up @@ -138,13 +138,23 @@ def createCryptoBar(self, info):
except:
pass

if color != "\c%08x" % colors[2] or caid_entry[4]:
if color != "\c%08x" % colors[2] or caid_entry[5]:
if res:
res += " "
res += color + caid_entry[3]

res += "\c%08x" % colors[3] # white (this acts like a color "reset" for following strings
return res

def createCurrentCaidLabel(self):
res = ""
if not pathExists("/tmp/ecm.info"):
return "FTA"
for caid_entry in caid_data:
if int(caid_entry[0], 16) <= int(self.current_caid, 16) <= int(caid_entry[1], 16):
res = caid_entry[4]

return res

def createCryptoSpecial(self, info):
caid_name = "FTA"
Expand Down Expand Up @@ -315,6 +325,10 @@ def getText(self):
return addspace(self.createCryptoBar(info)) + self.createCryptoSpecial(info)
else:
return addspace(self.createCryptoBar(info)) + addspace(self.current_source) + self.createCryptoSpecial(info)

if self.type == "CurrentCrypto":
self.getCryptoInfo(info)
return self.createCurrentCaidLabel()

if self.type == "CryptoBar":
self.getCryptoInfo(info)
Expand Down
8 changes: 1 addition & 7 deletions lib/python/Components/Converter/ServiceName.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def getText(self):
text = property(getText)

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

def getName(self, ref, info):
Expand Down Expand Up @@ -116,12 +116,6 @@ def getOrbitalPos(self, ref, info):
else:
tp_data = info.getInfoObject(iServiceInformation.sTransponderData)

if not tp_data and not ref:
service = self.source.service
if service:
feraw = service.frontendInfo()
tp_data = feraw and feraw.getAll(config.usage.infobar_frontend_source.value == "settings")

if tp_data is not None:
try:
position = tp_data["orbital_position"]
Expand Down
159 changes: 159 additions & 0 deletions lib/python/Components/Converter/VAudioInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# copied from OpenViX

from enigma import iPlayableService

from Components.Converter.Converter import Converter
from Components.Converter.Poll import Poll
from Components.Element import cached

# Common function to standardize the display of Audio Codecs
# _acedits is a list of text conversions (from, to) that are done in the
# order given.
#
_acedits = (
("A_", ""),
("AC-3", "AC3"),
("(ATSC A/52)", ""),
("(ATSC A/52B)", ""),
(" Layer 2 (MP2)", ""),
(" Layer 3 (MP3)", "MP3"),
("-1", ""),
("-2", ""),
("2-", ""),
("-4 AAC", "AAC"),
("4-AAC", "HE-AAC"),
("audio", ""),
("/L3", ""),
("/mpeg", "AAC"),
("/x-", ""),
("raw", "Dolby TrueHD"),
("E-AC3", "AC3+"),
("EAC3", "AC3+"),
("IPCM", "AC3"),
("LPCM", "AC3+"),
("AAC_PLUS", "AAC+"),
("AAC_LATM", "AAC"),
("WMA/PRO", "WMA Pro"),
("MPEG", "MPEG1 Layer II"),
("MPEG1 Layer II AAC", "AAC"),
("MPEG1 Layer IIAAC", "AAC"),
("MPEG1 Layer IIMP3", "MP3"),
)


def StdAudioDesc(description):
for orig, repl in _acedits:
description = description.replace(orig, repl)
return description


class VAudioInfo(Poll, Converter, object):
GET_AUDIO_ICON = 0
GET_AUDIO_CODEC = 1

def __init__(self, type):
Converter.__init__(self, type)
Poll.__init__(self)
self.type = type
self.poll_interval = 1000
self.poll_enabled = True
self.lang_strings = ("english", "englisch", "eng")
self.codecs = {
"01_dolbydigitalplus": ("digital+", "digitalplus", "ac3+",),
"02_dolbydigital": ("ac3", "dolbydigital",),
"03_mp3": ("mp3",),
"04_wma": ("wma",),
"05_flac": ("flac",),
"06_he-aac": ("he-aac",),
"07_aac": ("aac",),
"08_lpcm": ("lpcm",),
"09_dts-hd": ("dts-hd",),
"10_dts": ("dts",),
"11_pcm": ("pcm",),
"12_mpeg": ("mpeg",),
"13_dolbytruehd": ("truehd",),
"14_aacplus": ("aac+",),
"15_ipcm": ("ipcm",),
"16_wma-pro": ("wma pro",),
"17_vorbis": ("vorbis",),
"18_opus": ("opus",),
"19_amr": ("amr",),
}
self.codec_info = {
"dolbytruehd": ("51", "20", "71"),
"dolbydigitalplus": ("51", "20", "71"),
"dolbydigital": ("51", "20", "71"),
"wma": ("8", "9"),
}
self.type, self.interesting_events = {
"AudioIcon": (self.GET_AUDIO_ICON, (iPlayableService.evUpdatedInfo,)),
"AudioCodec": (self.GET_AUDIO_CODEC, (iPlayableService.evUpdatedInfo,)),
}[type]

def getAudio(self):
service = self.source.service
audio = service.audioTracks()
if audio:
self.current_track = audio.getCurrentTrack()
self.number_of_tracks = audio.getNumberOfTracks()
if self.number_of_tracks > 0 and self.current_track > -1:
self.audio_info = audio.getTrackInfo(self.current_track)
return True
return False

def getLanguage(self):
languages = self.audio_info.getLanguage()
for lang in self.lang_strings:
if lang in languages:
languages = "English"
break
languages = languages.replace("und", "")
return languages

def getAudioCodec(self, info):
description_str = _("N/A")
if self.getAudio():
languages = self.getLanguage()
description = StdAudioDesc(self.audio_info.getDescription()) or ""
description_str = description.split(" ")
if len(description_str) and description_str[0] in languages:
return languages
if description.lower() in languages.lower():
languages = ""
description_str = description
return description_str

def getAudioIcon(self, info):
description_str = self.get_short(self.getAudioCodec(info).translate(str.maketrans(' ', ' .')).lower())
return description_str

def get_short(self, audioName):
for return_codec, codecs in sorted(self.codecs.items()):
for codec in codecs:
if codec in audioName:
codec = return_codec.split('_')[1]
if codec in self.codec_info:
for ex_codec in self.codec_info[codec]:
if ex_codec in audioName:
codec += ex_codec
break
return codec
return audioName

@cached
def getText(self):
service = self.source.service
if service:
info = service and service.info()
if info:
if self.type == self.GET_AUDIO_CODEC:
return self.getAudioCodec(info)
if self.type == self.GET_AUDIO_ICON:
return self.getAudioIcon(info)
return _("invalid type")

text = property(getText)

def changed(self, what):
if what[0] != self.CHANGED_SPECIFIC or what[1] in self.interesting_events:
Converter.changed(self, what)
3 changes: 3 additions & 0 deletions lib/python/Components/MovieList.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def itemHeights(value):
if len(self.itemHeights) != 3:
warningWrongSkinParameter(attrib)

def itemHeight(value):
pass

def pbarShift(value):
self.pbarShift = parseScale(value)

Expand Down
63 changes: 63 additions & 0 deletions lib/python/Components/Renderer/AudioIcon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from Components.Renderer.Renderer import Renderer
from enigma import ePixmap
from Tools.Directories import fileExists, SCOPE_GUISKIN, resolveFilename
from Tools.LoadPixmap import LoadPixmap

class AudioIcon(Renderer):
def __init__(self):
Renderer.__init__(self)
self.size = None
self.width = 51
self.height = 30
self.nameAudioCache = { }
self.pngname = ""
self.path = ""

def applySkin(self, desktop, parent):
attribs = [ ]
for (attrib, value) in self.skinAttributes:
if attrib == "path":
self.path = value
if value.endswith("/"):
self.path = value
else:
self.path = value + "/"
else:
attribs.append((attrib,value))
if attrib == "size":
value = value.split(',')
if len(value) == 2:
self.width = int(value[0])
self.height = int(value[1])
self.size = value[0] + "x" + value[1]
self.skinAttributes = attribs
return Renderer.applySkin(self, desktop, parent)

GUI_WIDGET = ePixmap

def changed(self, what):
if self.instance:
pngname = ""
if what[0] != self.CHANGED_CLEAR:
sname = self.source.text
pngname = self.nameAudioCache.get(sname, "")
if pngname == "":
pngname = self.findAudioIcon(sname)
if pngname != "":
self.nameAudioCache[sname] = pngname
if pngname == "":
self.instance.hide()
else:
self.instance.show()
if pngname != "" and self.pngname != pngname:
is_svg = pngname.endswith(".svg")
png = LoadPixmap(pngname, width=self.width, height=0 if is_svg else self.height)
self.instance.setPixmap(png)
self.pngname = pngname

def findAudioIcon(self, audioName):
pngname = resolveFilename(SCOPE_GUISKIN, self.path + audioName + ".svg")
if fileExists(pngname):
return pngname
return ""

52 changes: 52 additions & 0 deletions lib/python/Components/Renderer/VolumeText.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#######################################################################
#
#
# Volume Text Renderer for Dreambox/Enigma-2
# Coded by Vali (c)2010
# Support: www.dreambox-tools.info
#
#
# This plugin is licensed under the Creative Commons
# Attribution-NonCommercial-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
# or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
#
# Alternatively, this plugin may be distributed and executed on hardware which
# is licensed by Dream Multimedia GmbH.
#
#
# This plugin is NOT free software. It is open source, you are allowed to
# modify it (if you keep the license), but it may not be commercially
# distributed other than under the conditions noted above.
#
#
#######################################################################

from enigma import eLabel, eDVBVolumecontrol, eTimer

from Components.Renderer.Renderer import Renderer
from Components.VariableText import VariableText


class VolumeText(Renderer, VariableText):
def __init__(self):
Renderer.__init__(self)
VariableText.__init__(self)
self.vol_timer = eTimer()
self.vol_timer.callback.append(self.pollme)
GUI_WIDGET = eLabel

def changed(self, what):
if not self.suspended:
self.text = str(eDVBVolumecontrol.getInstance().getVolume())

def pollme(self):
self.changed(None)

def onShow(self):
self.suspended = False
self.vol_timer.start(200)

def onHide(self):
self.suspended = True
self.vol_timer.stop()

0 comments on commit 34536ad

Please sign in to comment.