-
Notifications
You must be signed in to change notification settings - Fork 5
/
simplexbmc.py
155 lines (136 loc) · 5.53 KB
/
simplexbmc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- coding: utf-8 -*-
#-------------LicenseHeader--------------
# plugin.video.podcatcher- A plugin to organise Podcasts
# Copyright (C) 2010 Raptor 2101 [[email protected]]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import xbmc, xbmcgui, xbmcplugin,xbmcaddon, sys, re, time
__plugin__ = "PodCatcher"
regex_decimal = re.compile("\\d+");
regex_duration = re.compile("(\\d+:){0,2}\\d+");
settings = xbmcaddon.Addon(id='plugin.audio.podcatcher')
translation = settings.getLocalizedString
class SimpleXbmcGui(object):
def __init__(self,path):
self.path = path;
@staticmethod
def log(msg):
if not isinstance(msg,str) and not isinstance(msg,unicode):
xbmc.log("[%s]: %s" % (__plugin__, type(msg)))
else:
xbmc.log("[%s]: %s" % (__plugin__, msg.encode('utf8')))
def buildMediaItem(self, element, markUnread):
if(element.subTitle == ""):
title = "%s (%s)"%(element.title,element.duration);
else:
title = "%s - %s (%s)"%(element.title,element.subTitle,element.duration);
if(type(element).__name__ == 'FeedItem'):
title = "[%s] %s"%(time.strftime("%d.%m",element.date),title);
if(markUnread and not element.readed):
title = "(*) %s"%(title);
else:
title = "%s"%(title);
liz=xbmcgui.ListItem(title);
if(element.picture is not ""):
liz.setArt({"icon":"DefaultFolder.png", "thumb":element.picture});
else :
liz.setArt({"icon":"DefaultFolder.png"});
liz.setInfo("music",{
"size": element.size,
"date": time.strftime("%d.%m.%Y",element.date),
"duration": self.durationStringToSec(element.duration),
"year": int(time.strftime("%Y",element.date)),
"artist": element.author,
"title": title,
"comment": element.description
});
return liz;
def buildMenuEntry(self, menuElement, elementCount ):
if(self.path == ""):
path = "%d"%(self.counter);
else:
path = "%s.%d"%(self.path,self.counter);
self.log(type(menuElement).__name__);
if(type(menuElement).__name__ == 'FeedItem'):
liz = self.buildMediaItem(menuElement,True);
liz.addContextMenuItems([(translation(4020),"XBMC.RunPlugin(%s?path=%s&action=markRead)"%(sys.argv[0],path))],True)
u = "%s?path=%s&action=play&guid=%s" % (sys.argv[0],path,menuElement.guid)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
else:
if(menuElement.hasUnreadItems()):
title = "(*) %s"%(menuElement.title);
else:
title = "%s"%(menuElement.title);
self.log(menuElement.picture)
if(menuElement.picture is not ""):
liz=xbmcgui.ListItem(title, iconImage="DefaultFolder.png", thumbnailImage=menuElement.picture)
else :
liz=xbmcgui.ListItem(title, "")
contextMenuEntries = [
(translation(30010),"XBMC.RunPlugin(%s?path=%s&action=markRead)"%(sys.argv[0],path)),
(translation(30011),"XBMC.RunPlugin(%s?path=%s&action=play)"%(sys.argv[0],path)),
(translation(30030),"XBMC.RunPlugin(%s?path=%s&action=reload)"%(sys.argv[0],path))
]
liz.addContextMenuItems(contextMenuEntries,True)
u = "%s?path=%s&action=browse" % (sys.argv[0],path)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True,totalItems = elementCount)
self.counter+=1;
def play(self, playableObject):
player = xbmc.Player();
playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
playlist.clear();
playerItem = xbmcgui.ListItem(playableObject.title)
if(type(playableObject).__name__ == 'FeedItem'):
self.log("play(): " + playableObject.link);
player.play(str(playableObject.link),playerItem);
else:
items = [];
playableObject.getAllUnreadItems(items);
for item in items:
listItem = self.buildMediaItem(item,False);
playlist.add(url=item.link, listitem=listItem)
player.play(playlist, playerItem);
xbmc.executebuiltin("ActivateWindow(musicplaylist)");
def openMenuContext(self):
self.counter = 0;
self.dialogProgress = xbmcgui.DialogProgress();
@staticmethod
def closeMenuContext():
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@staticmethod
def refresh():
xbmc.executebuiltin("Container.Refresh")
@staticmethod
def durationStringToSec(durationString):
if(durationString is not None and regex_duration.match(durationString) is not None):
decimalArray = regex_decimal.findall(durationString);
if(len(decimalArray)==3):
return int(decimalArray[0])*3600 + int(decimalArray[1])*60 +int(decimalArray[2])
elif(len(decimalArray)==2):
return int(decimalArray[0])*60 +int(decimalArray[1])
else:
return int(decimalArray[0])
else:
return 0;
def errorOK(self,title="", msg=""):
e = str( sys.exc_info()[ 1 ] )
self.log(e)
if not title:
title = __plugin__
if not msg:
msg = "ERROR!"
if(e == None):
xbmcgui.Dialog().ok( title, msg, e )
else:
xbmcgui.Dialog().ok( title, msg)