-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Added] AudioIcon, AudioInfo, VolumeText converter and renderers
- Loading branch information
Showing
7 changed files
with
310 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |