Posts: 128
Joined: Apr 2014
So I updated the code to something like this:
Code:
def _get_skin_resolution(self):
aspect_ratio = xbmc.getInfoLabel('Skin.AspectRatio')
xml = os.path.join(xbmc.translatePath("special://skin/"), "addon.xml")
with open(xml) as f:
xml_file = f.read()
res_extension_point = common.parseDOM(xml_file, 'extension', attrs={'point': 'xbmc.gui.skin'})[0]
res_lines = res_extension_point.splitlines()
skin_resolution = [res for res in res_lines if aspect_ratio in res][0]
xval = int(re.findall('width="(\d{3,4})"', skin_resolution)[0])
yval = int(re.findall('height="(\d{3,4})"', skin_resolution)[0])
return xval, yval
Its using parsedom instead of minidom and regex pattern. It has been tested.
Posts: 1,607
Joined: Apr 2016
Nice, I'll test it. From what I've read, Kodi tries to find closest resolution in the skin, if it is not there, it uses next lower one.
This gets the first resolution with corresponding aspect ratio?
Posts: 128
Joined: Apr 2014
(2018-01-09, 20:10)DaLanik Wrote: Nice, I'll test it. From what I've read, Kodi tries to find closest resolution in the skin, if it is not there, it uses next lower one.
This gets the first resolution with corresponding aspect ratio?
Yes and no. Yes because it gets current used aspect ratio and finds matching resolution from a skin. No because the code will probably need a fallback in case there is no match, a rare occasion but can happen at some setups, especially on raspberry pis with CRT monitors.
Posts: 1,607
Joined: Apr 2016
2018-01-09, 21:18
(This post was last modified: 2018-01-09, 21:18 by User 325245.)
Hmm, thinking of it, aspect_ratio = xbmc.getInfoLabel('Skin.AspectRatio') gets SKIN a/r... so it must be something from the skin's addon.xml file? Then there MUST be a match in listed resolutions...
Posts: 1,607
Joined: Apr 2016
2018-01-09, 21:42
(This post was last modified: 2018-01-09, 21:43 by User 325245.)
OK, came up with something like this, just in case
Code:
def _get_skin_resolution(self):
aspect_ratio = xbmc.getInfoLabel('Skin.AspectRatio')
xmlFile = os.path.join(xbmc.translatePath("special://skin/"), "addon.xml")
with open(xmlFile) as f:
xml_file = f.read()
res_extension_point = common.parseDOM(xml_file, 'extension', attrs={'point': 'xbmc.gui.skin'})[0]
res_lines = res_extension_point.splitlines()
try:
skin_resolution = [res for res in res_lines if aspect_ratio in res][0]
except IndexError:
xmldoc = minidom.parse(xmlFile)
res = xmldoc.getElementsByTagName("res")
xval = int(res[0].attributes["width"].value)
yval = int(res[0].attributes["height"].value)
else:
xval = int(re.findall('width="(\d{3,4})"', skin_resolution)[0])
yval = int(re.findall('height="(\d{3,4})"', skin_resolution)[0])
return xval, yval
Posts: 128
Joined: Apr 2014
(2018-01-09, 21:18)DaLanik Wrote: Hmm, thinking of it, aspect_ratio = xbmc.getInfoLabel('Skin.AspectRatio') gets SKIN a/r... so it must be something from the skin's addon.xml file? Then there MUST be a match in listed resolutions...
It gets current resolution used, not the skin's. Kodi uses an aspect ratio that suits for current surface and if there is no matching one, the closest one is used. Estuary has most common aspect ratios, while confluence has just one.
IMHO this is a lot simpler, without the additional overhead of handling an exception, adding just an else into the list comprehension:
Code:
def _get_skin_resolution(self):
aspect_ratio = xbmc.getInfoLabel('Skin.AspectRatio')
xml = os.path.join(xbmc.translatePath("special://skin/"), "addon.xml")
with open(xml) as f:
xml_file = f.read()
res_extension_point = common.parseDOM(xml_file, 'extension', attrs={'point': 'xbmc.gui.skin'})[0]
res_lines = res_extension_point.splitlines()
skin_resolution = [res if aspect_ratio in res else res_lines for res in res_lines][0]
xval = int(re.findall('width="(\d{3,4})"', skin_resolution)[0])
yval = int(re.findall('height="(\d{3,4})"', skin_resolution)[0])
return xval, yval
Posts: 128
Joined: Apr 2014
2018-01-10, 11:20
(This post was last modified: 2018-01-10, 11:26 by twilight0.)
I took the liberty and forked your addon because I desperately needed a few changes asap.
https://github.com/Twilight0/service.banners.mod
It also looks like PIL doesn't like indexed pngs.
Posts: 1,607
Joined: Apr 2016
(2018-01-09, 22:10)twilight0 Wrote: Code:
skin_resolution = [res if aspect_ratio in res else res_lines for res in res_lines][0]
This crashes...
Posts: 128
Joined: Apr 2014
(2018-01-10, 11:42)DaLanik Wrote: (2018-01-09, 22:10)twilight0 Wrote: Code:
skin_resolution = [res if aspect_ratio in res else res_lines for res in res_lines][0]
This crashes...
Provide your log so we can sort it out. Also, which skin your using, kodi version, your aspect radio and finally screen resolution.
Posts: 352
Joined: Dec 2005
Reputation:
3
Hi DaLanik, i've been looking around your code trying to get my head around it to make a few changes for a local project i'm working on for a non-profit.
Im trying to make the banner display cover the entire width of the screen, and be a bit taller, touching the bottom of the display.
I've found where the overlay class is created but can't work out how the height and width is written - especially when called via JSON rather than a rotation.
Would you be able to point me at some line numbers?
Posts: 1,607
Joined: Apr 2016
Ugh, been awhile since I delved into code there
The function is scaleimage(self, width, height, yoffset)
Posts: 352
Joined: Dec 2005
Reputation:
3
Thanks man, it's a bit over my head atm (im still new to python) but hopefully will make some progress with a friend tomorrow
Posts: 1,607
Joined: Apr 2016
2018-01-16, 00:22
(This post was last modified: 2018-01-16, 00:23 by User 325245.)
I think it should be enough to set width to viewport_w (that's the width of the screen), but then you have to calculate height to be proportional to width...
Posts: 352
Joined: Dec 2005
Reputation:
3
Much appreciated, have managed to get an MVP going by increasing image size and setting image bottom to bottom of the viewport.
Will throw over a donation at the end of the month
Posts: 1,607
Joined: Apr 2016
v2.0
- Language file format related changes