Skip to content

Commit

Permalink
plugin.audio.100fm-Digital
Browse files Browse the repository at this point in the history
  • Loading branch information
daggs1 committed Nov 15, 2019
1 parent 326a37f commit ba78311
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
26 changes: 26 additions & 0 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.audio.100fm-digital" version="1.0.0" name="100FM Digital" provider-name="daggs1">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.future" />
</requires>
<extension point="xbmc.python.pluginsource" library="main.py">
<provides>audio</provides>
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en">100FM Radius Digital - Music, that's all</summary>
<description lang="en">100FM radio station Kodi add-on. The add-on offers live listening to dozens different musical genres: 80's, 90's, Rock, Pop, Oldies and many more
</description>
<summary lang="he">100FM רדיוס דיגיטל - מוזיקה זה הכל</summary>
<description lang="he">תוסף קודי של תחנת הרדיו רדיוס FM100. התוסף מציע עשרות תחנות רדיו המנגנות מוזיקה לפי
ז׳אנרים: שנות ה- 80, 90, ישראלי, להיטים ועוד
</description>
<disclaimer lang="en">This is an unofficial 100FM Radius Digital Kodi add-on</disclaimer>
<assets>
<icon>resources/icon.png</icon>
<fanart>resources/fanart.jpg</fanart>
</assets>
</extension>
<license>GNU GENERAL PUBLIC LICENSE Version 2</license>
<source>https://github.com/daggs1/plugin.audio.100fm-digital</source>
</addon>
86 changes: 86 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import sys, os
from urllib.parse import urlencode, parse_qsl
import xbmcgui
import xbmcplugin
import xbmcaddon
from xml.dom import minidom
from urllib import request
from PIL import Image

addon_handle = int(sys.argv[1])

userdata_path = xbmc.translatePath('special://userdata/addon_data')
root = os.path.join(userdata_path, xbmcaddon.Addon().getAddonInfo('id'))

def compose_image(bg_local_path, fg_local_path, output):
bg = Image.open(bg_local_path)
fg = Image.open(fg_local_path)
(bg_h, bg_w) = bg.size
(fg_h, fg_w) = fg.size
h = int((bg_h - fg_h) / 2)
w = int((bg_w - fg_w) / 2)
bg.paste(fg, (h, w), fg)
bg.save(output, "JPEG", quality = 100, optimize = True, progressive = True)

def populate_list():
url = 'http://digital.100fm.co.il/ChannelList_Kodi.xml'
channels_file = root + '/list.xml'

if not os.path.exists(root):
os.makedirs(root)

request.urlretrieve(url, channels_file)
digital_sheet = minidom.parse(channels_file)
channels = digital_sheet.firstChild.getElementsByTagName('Channel')
entries = list()
default_pic = None
img_counter = 1

for channel in channels:
label = str(channel.getElementsByTagName('name')[-1].firstChild.nodeValue).encode('utf-8')
bg_path = channel.getElementsByTagName('img')[-1].firstChild.nodeValue
fg_path = channel.getElementsByTagName('font')[-1].firstChild.nodeValue
bg_local_path = root + '/' + os.path.basename(bg_path)
fg_local_path = root + '/' + os.path.basename(fg_path)

got_pics = False
try:
request.urlretrieve(bg_path, bg_local_path)
request.urlretrieve(fg_path, fg_local_path)
got_pics = True
except:
if not default_pic:
raise

if got_pics:
img_local_path = root + '/channel_id' + str(img_counter) + '.jpg'
img_counter += 1
compose_image(bg_local_path, fg_local_path, img_local_path)
if not default_pic:
default_pic = img_local_path
else:
img_local_path = default_pic

#xbmc.log('got: ' + str(label) + ', img: ' + str(bg_path) + ', font: ' + str(fg_path) + 'img_local_path: ' + img_local_path, xbmc.LOGNOTICE)
try:
stream = channel.getElementsByTagName('Feed')[-1].firstChild.nodeValue
except:
stream = channel.getElementsByTagName('Feed1')[-1].firstChild.nodeValue

entries.append((label, img_local_path, stream))

return entries

def load_channels():
for ent in populate_list():
(label, img_local_path, stream) = ent
channel_ent = xbmcgui.ListItem(label = label)
channel_ent.setArt({'thumb': img_local_path, 'icon': img_local_path, 'fanart': img_local_path})
channel_ent.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(addon_handle, stream, channel_ent, False)

xbmcplugin.addSortMethod(addon_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.endOfDirectory(addon_handle)

if __name__ == '__main__':
load_channels()
Binary file added resources/fanart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba78311

Please sign in to comment.