YouTube-Player plugin added
[vuplus_dvbapp-plugin] / youtubeplayer / src / YouTubePlayList.py
1 ############################################################################
2 #    Copyright (C) 2008 by Volker Christian                                #
3 #    Volker.Christian@fh-hagenberg.at                                      #
4 #                                                                          #
5 #    This program is free software; you can redistribute it and#or modify  #
6 #    it under the terms of the GNU General Public License as published by  #
7 #    the Free Software Foundation; either version 2 of the License, or     #
8 #    (at your option) any later version.                                   #
9 #                                                                          #
10 #    This program is distributed in the hope that it will be useful,       #
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
13 #    GNU General Public License for more details.                          #
14 #                                                                          #
15 #    You should have received a copy of the GNU General Public License     #
16 #    along with this program; if not, write to the                         #
17 #    Free Software Foundation, Inc.,                                       #
18 #    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
19 ############################################################################
20
21 from YouTubeInterface import interface
22 from YouTubeAddPlayList import YouTubeAddPlaylistDialog
23 from Components.ActionMap import ActionMap
24 from Components.MenuList import MenuList
25 from Components.Label import Label
26 from Components.MultiContent import MultiContentEntryText
27 from Screens.MessageBox import MessageBox
28 from Screens.Screen import Screen
29 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, RT_VALIGN_TOP, RT_WRAP
30
31 from . import _
32
33
34 def YouTubePlaylistEntryComponent(entry):
35         res = [ entry ]
36
37         res.append(MultiContentEntryText(pos = (5, 5), size = (550, 18), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP| RT_WRAP, text = entry.getTitle()))
38         res.append(MultiContentEntryText(pos = (5, 23), size = (550, 14), font = 1, color = 0xFFA323, color_sel = 0xFFA323, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP| RT_WRAP, text = entry.getDescription()))
39
40         return res
41
42
43 class YouTubePlaylistList(MenuList):
44         def __init__(self, list, enableWrapAround = False):
45                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
46                 self.l.setFont(0, gFont("Regular", 18))
47                 self.l.setFont(1, gFont("Regular", 14))
48                 self.l.setItemHeight(41)
49
50
51 class YouTubePlaylistScreen(Screen):
52         def __init__(self, session):
53                 Screen.__init__(self, session)
54
55                 self.session = session
56
57                 self["red"] = Label(_("Delete Playlist"))
58                 self["green"] = Label(_("Add new Playlist"))
59                 
60                 self.list = []
61                 self["list"] = YouTubePlaylistList(self.list)
62                 
63                 self["actions"] = ActionMap(["YouTubePlaylistScreenActions"],
64                 {
65                         "ok"            :       self.choosePlaylist,
66                         "delete"        :       self.deletePlaylist,
67                         "add"           :       self.addPlaylist,
68                         "cancel"        :       self.close
69                 }, -1)
70
71
72         def loadPlaylist(self):
73                 self.list = []
74                 feed = interface.getPlaylistFeed()
75                 for entry in feed.getEntries():
76                         self.list.append(YouTubePlaylistEntryComponent(entry))
77                 self["list"].setList(self.list)
78
79
80         def choosePlaylist(self):
81                 Screen.close(self, self["list"].getCurrent()[0])
82
83
84         def deletePlaylist(self):
85                 playList = self["list"].getCurrent()[0]
86                 if playList is not None:
87                         self.session.openWithCallback(self.deleteCallback, MessageBox, _("Really delete %(playlist)s?") % {"playlist" : playList.getTitle()})
88
89
90         def deleteCallback(self, result):
91                 if result:
92                         if interface.deletePlaylist(self["list"].getCurrent()[0]):
93                                 self.list.remove(self["list"].getCurrent())
94                                 self["list"].setList(self.list)
95
96
97         def addPlaylist(self):
98                 self.session.openWithCallback(self.addCallback, YouTubeAddPlaylistDialog)
99
100
101         def addCallback(self, result, playlistContext):
102                 if result:
103                         entry = interface.addPlaylist(playlistContext.name.value, playlistContext.description.value, playlistContext.private.value)
104                         self.list.append(YouTubePlaylistEntryComponent(entry))
105                         self["list"].setList(self.list)
106
107
108         def close(self):
109                 Screen.close(self, None)