1 ############################################################################
2 # Copyright (C) 2008 by Volker Christian #
3 # Volker.Christian@fh-hagenberg.at #
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. #
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. #
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 ############################################################################
21 from Plugins.Plugin import PluginDescriptor
22 from Tools.BoundFunction import boundFunction
24 from YouTubeList import YouTubeListScreen
25 from YouTubePlayList import YouTubePlaylistScreen
26 from YouTubeSearchDialog import YouTubeSearchDialog, SEARCH, STDFEEDS, PLAYLISTS, FAVORITES, CANCEL
27 from YouTubeUserList import YouTubeUserListScreen
28 from YouTubeUserConfig import youTubeUserConfig
29 from YouTubeStdFeedSelection import YouTubeStdFeedSelectionScreen
30 from YouTubeInterface import interface, YouTubeInterface
31 from SkinLoader import loadPluginSkin
32 from Screens.MessageBox import MessageBox
38 t = gettext.dgettext("YouTube", txt)
40 print "[YTB] fallback to default translation for", txt
41 t = gettext.gettext(txt)
45 class YouTubeManager():
46 def __init__(self, session):
47 self.session = session
51 def openSearchDialog(self):
52 self.session.openWithCallback(self.searchDialogClosed, YouTubeSearchDialog)
55 def searchDialogClosed(self, what, searchContext = None):
56 print "[YTB] searchDialogClosed: ", what
58 dlg = self.session.openWithCallback(self.youTubeListScreenClosed, YouTubeListScreen)
59 dlg.searchFeed(searchContext)
62 elif what == STDFEEDS:
63 self.openStandardFeeds()
66 callback = self.openPlaylists
67 elif what == FAVORITES:
68 callback = self.openFavorites
69 if not interface.isLoggedIn():
70 self.session.openWithCallback(callback, YouTubeUserListScreen, youTubeUserConfig.getDefaultUser())
72 callback(YouTubeUserListScreen.LOGIN_SUCCESS)
75 def openStandardFeeds(self):
76 self.session.openWithCallback(self.standardFeedSelected, YouTubeStdFeedSelectionScreen)
79 def standardFeedSelected(self, stdFeedUrl):
80 if stdFeedUrl is not None:
81 dlg = self.session.openWithCallback(self.youTubeListScreenClosed, YouTubeListScreen)
82 dlg.loadStandardFeed(stdFeedUrl)
84 self.openSearchDialog()
87 def openPlaylists(self, loginState):
88 if loginState == YouTubeUserListScreen.LOGIN_SUCCESS:
89 print "[YTB] logged in"
90 dlg = self.session.openWithCallback(self.playlistChoosen, YouTubePlaylistScreen)
92 elif loginState == YouTubeUserListScreen.LOGIN_FAILED:
93 print "[YTB] not logged in"
94 self.session.openWithCallback(self.backToSearchDialog, MessageBox, _("Login not successful"), MessageBox.TYPE_INFO)
96 self.backToSearchDialog()
99 def playlistChoosen(self, playlist):
100 if playlist is not None:
101 dlg = self.session.openWithCallback(self.youTubeListScreenClosed, YouTubeListScreen)
102 dlg.loadPlaylistFeed(playlist)
104 self.openSearchDialog()
107 def openFavorites(self, loginState):
108 if loginState == YouTubeUserListScreen.LOGIN_SUCCESS:
109 print "[YTB] logged in"
110 dlg = self.session.openWithCallback(self.youTubeListScreenClosed, YouTubeListScreen)
111 dlg.loadFavoritesFeed("default")
112 elif loginState == YouTubeUserListScreen.LOGIN_FAILED:
113 print "[YTB] not logged in"
114 self.session.openWithCallback(self.backToSearchDialog, MessageBox, _("Login not successful"), MessageBox.TYPE_INFO)
116 self.backToSearchDialog()
119 def backToSearchDialog(self, dummy = True):
120 self.openSearchDialog()
123 def youTubeListScreenClosed(self, proceed):
125 self.openSearchDialog()
130 def main(session, **kwargs):
131 YouTubeManager(session).openSearchDialog()
134 def Plugins(**kwargs):
135 loadPluginSkin(kwargs["path"])
136 return PluginDescriptor(
137 name="YouTube Player",
138 description=_("Search and play YouTube movies"),
139 where = [ PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU ],
140 icon = "plugin.png", fnc = boundFunction(main))