Format and time parameter prepared
[enigma2-plugins.git] / youtubeplayer / src / YouTubeList.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
23 from Components.ActionMap import ActionMap
24 from Components.MenuList import MenuList
25 from Components.Label import Label
26 from Components.ScrollLabel import ScrollLabel
27 from Components.Pixmap import Pixmap
28 from Components.ProgressBar import ProgressBar
29
30 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
31 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
32 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, RT_VALIGN_TOP, RT_WRAP
33 from enigma import eTimer
34
35 from Tools.NumericalTextInput import NumericalTextInput
36
37 from Screens.Screen import Screen
38 from Screens.MessageBox import MessageBox
39
40 from Components.config import config
41
42 from Plugins.Extensions.VlcPlayer.VlcServerConfig import vlcServerConfig
43 from Plugins.Extensions.VlcPlayer.VlcServer import VlcServer
44 from Plugins.Extensions.VlcPlayer.VlcServerList import VlcServerListScreen
45
46 from YouTubeContextMenu import YouTubeEntryContextMenu, YouTubeEntryContextMenuList
47
48 from Tools.BoundFunction import boundFunction
49
50 from YouTubePlayer import YouTubePlayer
51
52 from YouTubeUserConfig import youTubeUserConfig
53 from YouTubeUserList import YouTubeUserListScreen
54 from YouTubePlayList import YouTubePlaylistScreen
55
56 from . import _
57
58 def YouTubeEntryComponent(entry):
59         res = [ entry ]
60 # 385
61         res.append(MultiContentEntryText(pos = (150, 5), size = (370, 42), font = 0, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP| RT_WRAP, text = entry.getTitle()))
62         res.append(MultiContentEntryText(pos = (150, 46), size = (370, 56), font = 1, color = 0xFFA323, color_sel = 0xFFA323, flags = RT_HALIGN_LEFT | RT_VALIGN_TOP| RT_WRAP, text = entry.getDescription()))
63
64         if entry.thumbnail["0"] is None:
65                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/plugin.png"))
66         else:
67                 png = entry.thumbnail["0"]
68         res.append(MultiContentEntryPixmapAlphaTest(pos = (10, 5), size = (130, 97), png = png))
69
70         return res
71
72
73 class YouTubeVideoDetailsScreen(Screen):
74         def __init__(self, session, entry):
75                 Screen.__init__(self, session)
76                 self.entry = entry
77                 self["video_description"] = ScrollLabel(entry.getDescription())
78                 durationInSecs = int(entry.getDuration())
79                 mins = int(durationInSecs / 60)
80                 secs = durationInSecs - mins * 60
81                 duration = "%d:%02d" % (mins, secs)
82                 
83                 self["label_video_duration"] = Label(_("Duration") + ":")
84                 self["video_duration"] = Label(duration)
85                 
86                 self["label_video_rating_average"] = Label(_("Rate") + ":")
87                 self["starsbg"] = Pixmap()
88                 self["stars"] = ProgressBar()
89
90                 self["label_video_numraters"] = Label(_("Ratings") + ":")
91                 self["video_numraters"] = Label(entry.getNumRaters())
92                 
93                 self["label_video_statistics_favorite_count"] = Label(_("Favorited") + ":")
94                 self["video_statistics_favorite_count"] = Label(entry.getFavoriteCount())
95                 
96                 self["label_video_statistics_view_count"] = Label(_("Views") + ":")
97                 self["video_statistics_view_count"] = Label(entry.getViewCount())
98
99                 self["label_video_author"] = Label(_("Author:") + ":")
100                 self["video_author"] = Label(entry.getAuthor())
101
102                 self["label_video_published_on"] = Label(_("Added") + ":")
103                 self["video_published_on"] = Label(entry.getPublishedOn().split("T")[0])
104
105                 self["label_video_category"] = Label(_("Category") + ":")
106                 self["video_category"] = Label(entry.getCategory())
107                 self["label_video_tags"] = Label(_("Tags") + ":")
108                 self["video_tags"] = Label(entry.getTags())
109                 
110                 self["video_thumbnail_1"] = Pixmap()
111                 self["video_thumbnail_2"] = Pixmap()
112                 self["video_thumbnail_3"] = Pixmap()
113
114                 self["actions"] = ActionMap(["YouTubeVideoDetailsScreenActions"],
115                 {
116                         "ok"            :       self.close,
117                         "cancel"        :       self.close,
118                         "up"            :       self.pageUp,
119                         "down"          :       self.pageDown,
120                         "left"          :       self.pageUp,
121                         "right"         :       self.pageDown
122                 })
123
124                 self.onFirstExecBegin.append(self.setPixmap)
125                 self.onFirstExecBegin.append(self.setInitialize)
126
127
128         def pageUp(self):
129                 self["video_description"].pageUp()
130
131
132         def pageDown(self):
133                 self["video_description"].pageDown()
134
135
136         def setInitialize(self):
137                 Screen.setTitle(self, self.entry.getTitle())
138                 if self.entry.getRatingAverage() != "not available":
139                         ratingStars = int(round(20 * float(self.entry.getRatingAverage()), 0))
140                         print "[YTB] Rating: ", ratingStars, "    ", self["stars"].getRange()
141                         self["stars"].setValue(ratingStars)
142                 else:
143                         self["stars"].hide()
144                         self["starsbg"].hide()
145
146
147         def setPixmap(self):
148                 self["video_thumbnail_1"].instance.setPixmap(self.entry.thumbnail["0"].__deref__())
149                 self.entry.loadThumbnail(1, self.setThumbnail_2)
150                 self.entry.loadThumbnail(2, self.setThumbnail_3)
151                 self["video_thumbnail_2"].hide()
152                 self["video_thumbnail_3"].hide()
153
154
155         def setThumbnail_2(self, entry):
156                 self["video_thumbnail_2"].instance.setPixmap(self.entry.thumbnail["1"].__deref__())
157                 self["video_thumbnail_2"].show()
158
159
160         def setThumbnail_3(self, entry):
161                 self["video_thumbnail_3"].instance.setPixmap(self.entry.thumbnail["2"].__deref__())
162                 self["video_thumbnail_3"].show()
163
164
165 class PatientMessageBox(MessageBox):
166         def __init__(self, session, text, type = 1, timeout = -1, close_on_any_key = False, default = True):
167                 MessageBox.__init__(self, session, text, type, timeout, close_on_any_key, default)
168                 self.skinName = "MessageBox"
169
170
171         def processDelayed(self, function):
172                 self.delay_timer = eTimer()
173                 self.delay_timer.callback.append(self.processDelay)
174                 self.delay_timer.start(0, 1)
175                 self.function = function
176
177
178         def processDelay(self):
179                 self.function()
180
181
182         def cancel(self):
183                 pass
184
185
186         def ok(self):
187                 pass
188
189
190         def alwaysOK(self):
191                 pass
192
193
194 class YouTubeList(MenuList):
195         def __init__(self, list, enableWrapAround = False):
196                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
197                 self.l.setFont(0, gFont("Regular", 18))
198                 self.l.setFont(1, gFont("Regular", 14))
199                 self.l.setItemHeight(105)
200
201
202 class YouTubeListScreen(Screen, NumericalTextInput):
203         def __init__(self, session):
204                 Screen.__init__(self, session)
205                 NumericalTextInput.__init__(self)
206
207                 self.session = session
208                 self.serverName = config.plugins.youtubeplayer.serverprofile.value
209                 self.currentServer = vlcServerConfig.getServerByName(self.serverName)
210
211                 self["red"] = Label(_("Select a VLC-Server"))
212                 self["green"] = Label(_("New YouTube search"))
213                 
214                 self.list = []
215                 self["list"] = YouTubeList(self.list)
216
217                 self["label_total_results"] = Label(_("Total results") + ":")
218                 self["total_results"] = Label("")
219
220                 self["label_currently_shown"] = Label(_("Shown") + ":")
221                 self["currently_shown"] = Label("")
222
223                 self.history = []
224                 self.historyIndex = 0
225
226                 self.isFavoritesFeed = False
227
228                 self.patientDialog = None
229                 
230                 self["actions"] = ActionMap(["YouTubeVideoListActions"],
231                 {
232                         "play"                  :       self.tryToPlay,
233                         "select"                :       self.justSelectServer,
234                         "search"                :       self.searchAgain,
235                         "menu"                  :       self.openContextMenu,
236                         "forward"               :       self.forwardInHistory,
237                         "backward"              :       self.backInHistory,
238                         "left"                  :       self.keyLeft,
239                         "right"                 :       self.keyRight,
240                         "up"                    :       self.keyUp,
241                         "down"                  :       self.keyDown,
242                         "info"                  :       self.showVideoInfo,
243                         "cancel"                :       self.close
244                 }, -1)
245
246
247         def keyLeft(self):
248                 self["list"].pageUp()
249
250
251         def keyRight(self):
252                 if self["list"].getSelectionIndex() == len(self.list) - 1 and self.feed.getNextFeed() is not None:
253                         dlg = self.session.openWithCallback(self.loadNextFeed, MessageBox, _("Load further entries of current Feed?"))
254                 else:
255                         self["list"].pageDown()
256
257
258         def keyUp(self):
259                 self["list"].up()
260
261
262         def keyDown(self):
263                 if self["list"].getSelectionIndex() == len(self.list) - 1 and self.feed.getNextFeed() is not None:
264                         dlg = self.session.openWithCallback(self.loadNextFeed, MessageBox, _("Load further entries of current Feed?"))
265                 else:
266                         self["list"].down()
267
268
269         def insertEntry(self, entry):
270                 print "[YTB] YouTubeTest::updateFinished()"
271                 self.list.append(YouTubeEntryComponent(entry))
272                 self.list.sort(cmp = lambda x, y : cmp(x[0].sequenceNumber, y[0].sequenceNumber))
273                 currentlyShown = "%d" % len(self.list)
274                 self["currently_shown"].setText(currentlyShown)
275                 self["list"].setList(self.list)
276
277
278         def closePatientDialogDelayed(self):
279                 if self.patientDialog:
280                         self.patientDialog.close()
281                         self.patientDialog = None
282                 self["list"].setList(self.list)
283
284
285         def showFeed(self, feed, append):
286                 if feed is not None:
287                         self.feed = feed
288                         self.setTitle(feed.getTitle())
289                         self["total_results"].setText(feed.getTotalResults())
290                         if not append:
291                                 self.list = []
292                                 self["list"].setList(self.list)
293                         self.feed.loadThumbnails(self.insertEntry)
294                 self.delay_timer = eTimer()
295                 self.delay_timer.callback.append(self.closePatientDialogDelayed)
296                 self.delay_timer.start(100, 1)
297
298
299         def addToHistory(self, feed):
300                 if feed is not None:
301                         del self.history[self.historyIndex : len(self.history)]
302                         self.history.insert(self.historyIndex, feed.getSelfFeed())
303                         self.historyIndex = self.historyIndex + 1
304
305                 
306         def searchFeedReal(self, searchContext):
307                 print "[YTB] searchFeedReal"
308                 try:
309                         feed = interface.search(searchContext.searchTerm.value, 
310                                         orderby = searchContext.orderBy.value,
311                                         racy = searchContext.racy.value,
312                                         time = searchContext.time.value,
313                                         lr = searchContext.lr.value,
314                                         categories = [ searchContext.categories.value ],
315                                         sortOrder = searchContext.sortOrder.value,
316                                         format = config.plugins.youtubeplayer.quality)
317                 except Exception, e:
318                         feed = None
319                         self.session.open(MessageBox, _("Error querying feed for search term %s:\n%s" %
320                                         (searchContext.searchTerm.value, e)), MessageBox.TYPE_ERROR)
321                 self.showFeed(feed, False)
322                 self.addToHistory(feed)
323
324
325         def searchFeed(self, searchContext):
326                 self.patientDialog = self.session.open(PatientMessageBox, _("Searching, be patient ..."))
327                 self.patientDialog.processDelayed(boundFunction(self.searchFeedReal, searchContext = searchContext))
328                 self.isFavoritesFeed = False
329
330
331         def loadPlaylistFeedReal(self, playlist):
332                 try:
333                         feed = interface.getUserPlaylistFeed(playlist)
334                 except Exception, e:
335                         feed = None
336                         self.session.open(MessageBox, _("Error querying playlist-feed for playlist %s:\n%s" %
337                                         (playlist.getTitle(), e)), MessageBox.TYPE_ERROR)
338                 self.showFeed(feed, False)
339                 self.addToHistory(feed)
340
341
342         def loadPlaylistFeed(self, playlist):
343                 self.patientDialog = self.session.open(PatientMessageBox, _("Loading playlist, be patient ..."))
344                 self.patientDialog.processDelayed(boundFunction(self.loadPlaylistFeedReal, playlist = playlist))
345
346
347         def loadFavoritesFeedReal(self, userName = "default"):
348                 try:
349                         feed = interface.getUserFavoritesFeed(userName)
350                 except Exception, e:
351                         feed = None
352                         self.session.open(MessageBox, _("Error querying favorites feed:\n%s" %
353                                         e), MessageBox.TYPE_ERROR)
354                 self.showFeed(feed, False)
355                 self.addToHistory(feed)
356
357
358         def loadFavoritesFeed(self, userName = "default"):
359                 self.patientDialog = self.session.open(PatientMessageBox, _("Loading favorits, be patient ..."))
360                 self.patientDialog.processDelayed(boundFunction(self.loadFavoritesFeedReal, userName = userName))
361                 self.isFavoritesFeed = True
362
363
364         def loadStandardFeed(self, url):
365                 self.loadFeed(_("Loading standard feed, be patient ..."), url, "standard feed")
366
367
368         def loadFeedReal(self, feedUrl, feedName, append = False, addToHistory = True):
369                 try:
370                         feed = interface.getFeed(feedUrl)
371                 except Exception, e:
372                         feed = None
373                         self.session.open(MessageBox, _("Error querying feed %s:\n%s" %
374                                         (feedName, e)), MessageBox.TYPE_ERROR)
375                 self.showFeed(feed, append)
376                 if addToHistory:
377                         self.addToHistory(feed)
378
379
380         def loadFeed(self, text, feedUrl, feedName, append = False, addToHistory = True):
381                 self.patientDialog = self.session.open(PatientMessageBox, text)
382                 self.patientDialog.processDelayed(boundFunction(self.loadFeedReal, feedName = feedName,
383                                                                                         feedUrl = feedUrl, append = append, addToHistory = addToHistory))
384
385
386         def loadPreviousFeed(self, result):
387                 if not result:
388                         return
389                 prevUrl = self.feed.getPreviousFeed()
390                 if prevUrl is not None:
391                         self.loadFeed(_("Loading additional videos, be patient ..."), prevUrl, _("additional videos"),
392                         True, True)
393
394
395         def loadNextFeed(self, result):
396                 if not result:
397                         return
398                 nextUrl = self.feed.getNextFeed()
399                 if nextUrl is not None:
400                         self.loadFeed(_("Loading additional videos, be patient ..."), nextUrl, _("additional videos"),
401                         True, True)
402
403
404         def getRelated(self):
405                 self.loadFeed(_("Loading related videos, be patient ..."), self["list"].getCurrent()[0].getRelatedFeed(), _("related videos"), False, True)
406                 self.isFavoritesFeed = False
407
408
409         def getResponses(self):
410                 self.loadFeed(_("Loading response videos, be patient ..."), self["list"].getCurrent()[0].getResponsesFeed(), _("response videos"), False, True)
411                 self.isFavoritesFeed = False
412
413
414         def backInHistory(self):
415                 if self.historyIndex > 1:
416                         self.historyIndex = self.historyIndex - 1
417                         self.loadFeed(_("Back in history, be patient ..."), self.history[self.historyIndex - 1], _("back in history"), False, False)
418
419
420         def forwardInHistory(self):
421                 if self.historyIndex < len(self.history):
422                         self.historyIndex = self.historyIndex + 1
423                         self.loadFeed(_("Forward in history, be patient ..."), self.history[self.historyIndex - 1], _("forward in history"), False, False)
424
425
426         def showVideoInfo(self):
427                 self.session.open(YouTubeVideoDetailsScreen, self["list"].getCurrent()[0])
428
429
430         def justSelectServer(self):
431                 defaultServer = vlcServerConfig.getServerByName(config.plugins.youtubeplayer.serverprofile.value)
432                 self.selectServer(self.serverSelectedCB, defaultServer)
433
434
435         def selectServer(self, callback, currentServer):
436                 self.session.openWithCallback(callback, VlcServerListScreen, currentServer)
437
438
439         def serverSelectedCB(self, selectedServer, defaultServer):
440                 if selectedServer is not None:
441                         self.currentServer = selectedServer
442                 elif defaultServer is not None:
443                                 self.currentServer = defaultServer
444                 if defaultServer is not None:
445                         config.plugins.youtubeplayer.serverprofile.value = defaultServer.getName()
446                         config.plugins.youtubeplayer.serverprofile.save()
447
448
449         def selectAndPlayCB(self, selectedServer, defaultServer):
450                 self.serverSelectedCB(selectedServer, defaultServer)
451                 self.tryToPlay()
452
453
454         def tryToPlay(self):
455                 if self.currentServer is not None:
456                         self.play()
457                 else:
458                         self.selectServer(self.selectAndPlayCB, None)
459
460
461         def login(self, callback):
462                 self.session.openWithCallback(callback, YouTubeUserListScreen, youTubeUserConfig.getDefaultUser())
463
464
465         def addToFavoritesReal(self):
466                 try:
467                         interface.addToFavorites(self["list"].getCurrent()[0])
468                 except Exception, e:
469                         self.session.open(MessageBox, _("Error adding video to favorites:\n%s" %
470                                         e), MessageBox.TYPE_ERROR)
471
472
473         def addToFavoritesLogin(self, loginState):
474                 if loginState == YouTubeUserListScreen.LOGIN_SUCCESS:
475                         self.addToFavoritesReal()
476                 elif loginState == YouTubeUserListScreen.LOGIN_FAILED:
477                         self.session.open(MessageBox, _("Login not successful"), MessageBox.TYPE_INFO)
478                 else:
479                         pass
480
481
482         def addToFavorites(self):
483                 if not interface.isLoggedIn():
484                         self.login(self.addToFavoritesLogin)
485                 else:
486                         self.addToFavoritesReal()
487
488
489         def removeFromFavoritesReal(self):
490                 try:
491                         if interface.removeFromFavorites(self["list"].getCurrent()[0]):
492                                 self.list.remove(self["list"].getCurrent())
493                                 self["list"].setList(self.list)
494                 except Exception, e:
495                         self.session.open(MessageBox, _("Error removing video from favorites:\n%s" %
496                                         e), MessageBox.TYPE_ERROR)
497
498
499         def removeFromFavoritesLogin(self, loginState):
500                 if loginState == YouTubeUserListScreen.LOGIN_SUCCESS:
501                         self.removeFromFavoritesReal()
502                 elif loginState == YouTubeUserListScreen.LOGIN_FAILED:
503                         self.session.open(MessageBox, _("Login not successful"), MessageBox.TYPE_INFO)
504                 else:
505                         pass
506
507
508         def removeFromFavorites(self):
509                 if not interface.isLoggedIn():
510                         self.login(self.removeFromFavoritesLogin)
511                 else:
512                         self.removeFromFavoritesReal()
513
514
515         def removeFromPlaylistReal(self):
516                 try:
517                         if interface.removeFromPlaylist(self["list"].getCurrent()[0]):
518                                 self.list.remove(self["list"].getCurrent())
519                                 self["list"].setList(self.list)
520                 except Exception, e:
521                         self.session.open(MessageBox, _("Error removing video from playlist:\n%s" %
522                                         e), MessageBox.TYPE_ERROR)
523
524
525         def removeFromPlaylistLogin(self, loginState):
526                 if loginState == YouTubeUserListScreen.LOGIN_SUCCESS:
527                         self.removeFromPlaylistReal()
528                 elif loginState == YouTubeUserListScreen.LOGIN_FAILED:
529                         self.session.open(MessageBox, _("Login not successful"), MessageBox.TYPE_INFO)
530                 else:
531                         pass
532
533
534         def removeFromPlaylist(self):
535                 if not interface.isLoggedIn():
536                         self.login(self.removeFromPlaylistLogin)
537                 else:
538                         self.removeFromPlaylistReal()
539
540
541         def playlistChoosen(self, playlist):
542                 if playlist is not None:
543                         try:
544                                 interface.addToPlaylist(playlist, self["list"].getCurrent()[0])
545                         except Exception, e:
546                                 self.session.open(MessageBox, _("Error adding video to playlist:\n%s" %
547                                         e), MessageBox.TYPE_ERROR)
548
549
550         def addToPlaylistReal(self):
551                 dlg = self.session.openWithCallback(self.playlistChoosen, YouTubePlaylistScreen)
552                 dlg.loadPlaylist()
553
554
555         def addToPlaylistLogin(self, loginState):
556                 if loginState == YouTubeUserListScreen.LOGIN_SUCCESS:
557                         self.addToPlaylistReal()
558                 elif loginState == YouTubeUserListScreen.LOGIN_FAILED:
559                         self.session.open(MessageBox, _("Login not successful"), MessageBox.TYPE_INFO)
560                 else:
561                         pass
562
563
564         def addToPlaylist(self):
565                 if not interface.isLoggedIn():
566                         self.login(self.addToPlaylistLogin)
567                 else:
568                         self.addToPlaylistReal()
569
570
571         def getVideoUrl(self, youTubeEntry, fmt):
572                 mrl = youTubeEntry.getVideoUrl(fmt)
573                 if mrl is None:
574                         self.session.open(MessageBox, _("Could not retrive video url for:\n%s") % youTubeEntry.getYouTubeId(), MessageBox.TYPE_ERROR)
575                 return mrl
576
577
578 # http://cacan.blog385.com/index.php/2008/05/09/youtube-high-quality-hacks/
579 # add the &fmt=6 onto the end:
580 #
581 # http://youtube.com/watch?v=CQzUsTFqtW0&fmt=6
582 #
583 # If the YouTube video just sits there loading then that
584 # is a sign that the video has not been converted to the
585 # higher resolution yet. To really see the difference you
586 # should view the video in full screen mode by clicking
587 # the button in the bottom-right corner of the player.
588 #
589 # Note: Alternatively you can add &fmt=18 and it will play
590 # the high-resolution version when available, otherwise it
591 # will play the regular version. Here?s a Greasemonkey
592 # script that will automatically add &fmt=18 onto the end
593 # of each YouTube URL.
594         def play(self):
595                 print "[YTB] Play()"
596                 youTubeEntry = self["list"].getCurrent()[0]
597                 mrl = self.getVideoUrl(youTubeEntry, config.plugins.youtubeplayer.quality.value)
598 ############## To be resolved
599 #Traceback (most recent call last):
600 #  File "/usr/lib/enigma2/python/Components/ActionMap.py", line 46, in action
601 #    res = self.actions[action]()
602 #  File "/usr/lib/enigma2/python/Plugins/Extensions/YouTubePlayer/YouTubeList.py", line 425, in tryToPlay
603 #    self.play()
604 #  File "/usr/lib/enigma2/python/Plugins/Extensions/YouTubePlayer/YouTubeList.py", line 543, in play
605 #    mrl = youTubeEntry.getVideoUrl("&fmt=18")
606 #  File "/usr/lib/enigma2/python/Plugins/Extensions/YouTubePlayer/YouTubeInterface.py", line 216, in getVideoUrl
607 #    conn.request("GET", "/v/" + quote(self.getYouTubeId()))
608 #  File "/usr/lib/python2.5/httplib.py", line 862, in request
609 #    self._send_request(method, url, body, headers)
610 #  File "/usr/lib/python2.5/httplib.py", line 885, in _send_request
611 #    self.endheaders()
612 #  File "/usr/lib/python2.5/httplib.py", line 856, in endheaders
613 #    self._send_output()
614 #  File "/usr/lib/python2.5/httplib.py", line 728, in _send_output
615 #    self.send(msg)
616 #  File "/usr/lib/python2.5/httplib.py", line 695, in send
617 #    self.connect()
618 #  File "/usr/lib/python2.5/httplib.py", line 663, in connect
619 #    socket.SOCK_STREAM):
620 #socket.gaierror: (2, 'temporary failure in name resolution.')
621
622                 if mrl is not None:
623                         entries = []
624                         entries.append((_("Show video detail info"), [self.showVideoInfo, False]))
625                         if self["list"].getCurrent()[0].belongsToFavorites():
626                                 entries.append((_("Remove from favorites"), [self.removeFromFavorites, False]))
627                         else:
628                                 entries.append((_("Add to favorites"), [self.addToFavorites, False]))
629                                 
630                         if self["list"].getCurrent()[0].isPlaylistEntry():
631                                 entries.append((_("Remove from playlist"), [self.removeFromPlaylist, False]))
632                         else:
633                                 entries.append((_("Add to playlist"), [self.addToPlaylist, False]))
634                         entries.append((_("Get related videos"), [self.getRelated, True]))
635                         entries.append((_("Get video responses"), [self.getResponses, True]))
636                         
637                         self.currentServer.play(self.session, mrl, youTubeEntry.getTitle(), self,
638                                                                 player = boundFunction(YouTubePlayer, contextMenuEntries = entries, infoCallback = self.showVideoInfo, name = self["list"].getCurrent()[0].getTitle()))
639                 else:
640                         print "[YTB] No valid flv-mrl found"
641
642
643         def getNextFile(self):
644                 i = self["list"].getSelectedIndex() + 1
645                 if i < len(self.list):
646                         self["list"].moveToIndex(i)
647                         youTubeEntry = self["list"].getCurrent()[0]
648                         return self.getVideoUrl(youTubeEntry, config.plugins.youtubeplayer.quality.value), youTubeEntry.getTitle()
649                 return None, None
650
651
652         def getPrevFile(self):
653                 i = self["list"].getSelectedIndex() - 1
654                 if i >= 0:
655                         self["list"].moveToIndex(i)
656                         youTubeEntry = self["list"].getCurrent()[0]
657                         return self.getVideoUrl(youTubeEntry, config.plugins.youtubeplayer.quality.value), youTubeEntry.getTitle()
658                 return None, None
659
660
661         def openContextMenu(self):
662                 contextMenuList = YouTubeEntryContextMenuList()
663                 contextMenuList.appendEntry((_("Show video detail info"), self.showVideoInfo))
664                 if self["list"].getCurrent()[0].belongsToFavorites():
665                         contextMenuList.appendEntry((_("Remove from favorites"), self.removeFromFavorites))
666                 else:
667                         contextMenuList.appendEntry((_("Add to favorites"), self.addToFavorites))
668                 if self["list"].getCurrent()[0].isPlaylistEntry():
669                         contextMenuList.appendEntry((_("Remove from playlist"), self.removeFromPlaylist))
670                 else:
671                         contextMenuList.appendEntry((_("Add to playlist"), self.addToPlaylist))
672                 contextMenuList.appendEntry((_("Get related videos"), self.getRelated))
673                 contextMenuList.appendEntry((_("Get video responses"), self.getResponses))
674                 self.session.openWithCallback(self.menuActionCoosen, YouTubeEntryContextMenu, contextMenuList, self["list"].getCurrent()[0].getTitle())
675
676
677         def menuActionCoosen(self, function):
678                 if function is not None:
679                         function()
680
681
682         def searchAgain(self):
683                 Screen.close(self, True)
684
685
686         def close(self):
687                 Screen.close(self, False)