def BuildCurrentAndNextItemsForLoadedPagesDict(self, sourceItem, pagesDict): currentItem = mc.ListItem(mc.ListItem.MEDIA_VIDEO_CLIP) currentItem.SetLabel(sourceItem.GetLabel()) currentItem.SetPath(sourceItem.GetPath()) if pagesDict.has_key("paging"): currentItem.SetTitle(pagesDict["paging"]) if pagesDict.has_key("search"): currentItem.SetProperty("search", pagesDict["search"]) if sourceItem.GetProperty("isSearch"): currentItem.SetProperty("isSearch", "true") mc.LogInfo("current item: %s %s" % (currentItem.GetTitle(), currentItem.GetPath())) if pagesDict.has_key("next"): nextItem = mc.ListItem(mc.ListItem.MEDIA_VIDEO_CLIP) nextEXItem = pagesDict["next"] nextItem.SetLabel(sourceItem.GetLabel()) nextItem.SetPath(nextEXItem["path"]) nextItem.SetTitle(nextEXItem["name"]) if nextEXItem.has_key("isSearch"): nextItem.SetProperty("isSearch", "true") mc.LogInfo("next item: %s %s" % (nextItem.GetTitle(), nextItem.GetPath())) return currentItem, nextItem else: return currentItem, None
def FixupNavigation(self): mc.LogInfo("Playback FixupNavigation") pagesList = self.GetPagesPanel().GetItems() panelUrl = '' if len(pagesList) > 0: panelUrl = pagesList[0].GetProperty("panelurl") listControl = self.GetNavigationContainer() navFocusedItem = self.GetListFocusedItem(listControl) if navFocusedItem.GetPath() != panelUrl: indexOfNavItemToFocus = self.FindIndexOfNavItemWithPanelUrl( panelUrl) listControl.SetFocusedItem(indexOfNavItemToFocus) # restore focused control navFocusedItem = self.GetListFocusedItem(listControl) controlIDToFocus = -1 if navFocusedItem.GetProperty("focusId"): controlIDToFocus = int(navFocusedItem.GetProperty("focusId")) if controlIDToFocus != -1: mc.LogInfo("FixupNavigation restored focus to control with id %s" % str(controlIDToFocus)) self.GetControl(controlIDToFocus).SetFocus() # restore focused item in pages panel and in sections list self.RestorePagesPanelFocusedItem() self.RestoreSectionsFocusedItem() if exPlayer.GetPlayer().referenceItem != None: exPlayer.GetPlayer().referenceItem = None
def OnLoadSectionPages(self, listItem, startNewSection=True, pushState=False, pushNavItem=True): url = listItem.GetPath() mc.LogInfo("url to load: %s" % url) mc.ShowDialogWait() if listItem.GetProperty("isSearch"): pagesDict = self.model.searchPagesDict(url) else: cleanURL = listItem.GetProperty('search') mc.LogInfo('cleanURL for input item is: %s' % cleanURL) pagesDict = self.model.pagesDict({ 'path': url, 'cleanUrl': cleanURL }) listItems = self.BuildPanelItemsList(pagesDict) currentNavItem, nextNavItem = self.BuildCurrentAndNextItemsForLoadedPagesDict( listItem, pagesDict) if pushState is True: self.SaveWindowState() if pushState or startNewSection: self.StartNavNewSection(listItem.GetLabel(), currentNavItem, nextNavItem) else: self.UpdateNavigationContainerForLoadedPages( currentNavItem, nextNavItem, pushNavItem) self.GetPagesPanel().SetItems(listItems) mc.HideDialogWait()
def InspectAndCleanUpPlaylistsDir(self): try: mediaDir = self.GetPlaylistsMediaDir() savedFilesList = os.listdir(mediaDir) # allow grow list to 150 items - then remove oldest 50 if (len(savedFilesList) - 50) >= 100: storedFileNames = self.GetStoredPlaylistNamesByPlayingTimes() savedFilesList = self.GetFilenamesSortedByModificationDate() mc.LogInfo("Deleting oldest files from list: %s" % str(savedFilesList)) for i in range(len(savedFilesList) - 50): fileName = savedFilesList[i] pathToRemove = os.path.join(mediaDir, fileName) mc.LogInfo("path to remove: %s" % pathToRemove) os.remove(pathToRemove) if storedFileNames.has_key(fileName): del storedFileNames[fileName] self.StorePlaylistNamesByPlayingTimes(storedFileNames) # clean up episodes episodesDir = self.GetEpisodesMediaDir() episodesSavedList = os.listdir(episodesDir) if len(episodesSavedList) >= 5: for file in episodesSavedList: os.remove(os.path.join(episodesDir, file)) except: pass
def RestorePagesPanelFocusedItem(self): mc.LogInfo("RestorePagesPanelFocusedItem") navFocusedItem = self.GetListFocusedItem(self.GetNavigationContainer()) if navFocusedItem.GetProperty("pagesFocusedIndex"): mc.LogInfo( "FixupNavigation restored pages panel focused index to %s" % str(navFocusedItem.GetProperty("pagesFocusedIndex"))) self.GetPagesPanel().SetFocusedItem( int(navFocusedItem.GetProperty("pagesFocusedIndex")))
def PlayEpisodesWithMenu(self, playListItem, episodesList): self.referenceItem = playListItem videoPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) videoPlaylist.Clear() for episode in episodesList: mc.LogInfo("added to playlist item with name: %s" % episode.GetLabel()) videoPlaylist.Add(episode) #show playlist selection dialog (playlistSelect.xml) mc.ActivateWindow(14100) mc.LogInfo("show playlist selection dialog called")
def GetPreviousNavItem(self): listControl = self.GetNavigationContainer() focusedIndex = listControl.GetFocusedItem() if focusedIndex - 1 < 0: mc.LogInfo("nav Items has no previous item") return None else: mc.LogInfo("return prev nav item: %s" % listControl.GetItem(focusedIndex - 1).GetTitle()) return listControl.GetItem(focusedIndex - 1)
def GetNavNextPageItem(self): listControl = self.GetNavigationContainer() focusedIndex = listControl.GetFocusedItem() mc.LogInfo("nav focused index: %s" % str(focusedIndex)) mc.LogInfo("nav items count: %s" % str(len(listControl.GetItems()))) if focusedIndex + 1 < len(listControl.GetItems()): mc.LogInfo("returning next nav item with paging: %s" % listControl.GetItem(focusedIndex + 1).GetTitle()) return listControl.GetItem(focusedIndex + 1) else: return None
def OnBack(self): if self.GetPreviousNavItem(): mc.LogInfo("backing to item: %s" % self.GetPreviousNavItem().GetLabel()) #load pages for "back" item without storing result in navigation stack self.OnLoadSectionPages(self.GetPreviousNavItem(), False, False, False)
def GeneratePlayFileForItem(self, playItem, isEpisode=False): tmpFileName = None try: playListContent = '#EXTM3U' + '\n' + '#EXTINF:-1,' + playItem.GetLabel( ) + '\n' playListContent += playItem.GetPath() + '\n' + '#EXT-X-ENDLIST' if isEpisode: mediaDir = self.GetEpisodesMediaDir() else: mediaDir = self.GetPlaylistsMediaDir() name = self.GetPlaylistFileNameForItem(playItem) tmpFileName = os.path.join(mediaDir, name) #mc.LogInfo("Playlist file path: %s" % tmpFileName) #mc.LogInfo("Opening file: %s" % tmpFileName) f = open(tmpFileName, 'w') f.write(playListContent) f.close() if False == isEpisode: self.StoreLastPlayedTimeForItemWithPath(name) except: mc.LogInfo( "Failed to open and write .m3u8 file - continue without it") tmpFileName = None return tmpFileName
def OnPageClick(self): focusedItem = self.GetPagesFocusedItem() self.SavePagesFocusedItem() self.SaveSectionsFocusedItem() url = focusedItem.GetPath() mc.ShowDialogWait() params = { 'path': url, 'name': focusedItem.GetLabel(), 'image': focusedItem.GetThumbnail(), 'referer': focusedItem.GetProperty('referer'), 'folder': focusedItem.GetProperty('folder') } mc.LogInfo("params for loading play list dict %s" % str(params)) playDict = self.model.pagePlaylistDict(params) mc.HideDialogWait() if playDict.has_key("playitems"): self.RunPlayerForItemsFromDict(focusedItem, playDict) elif playDict.has_key("subfolders"): self.OnLoadSubfolders(focusedItem, playDict) else: if self.GetNavNextPageItem() and self.GetNavNextPageItem().GetPath( ) == url: # go to next manually to not push window state self.OnNext() else: #we have link to dig into with pushing window state self.OnLoadSectionPages(focusedItem, True, True, True)
def OnSearchEverywhere(self): query = mc.ShowDialogKeyboard( mc.GetLocalizedString(137) + " EX.UA", "", False) if 0 != len(query): mc.LogInfo("string to search: %s" % query) pagesDict = self.model.searchAllPagesDict(query) self.UpdatePagesPanelWithSearchResults(query, pagesDict)
def UpdateNavigationContainerForLoadedPages(self, newCurrentNavItem, newNextNavItem, pushNavItem): #rebuild nav list for new items navList = mc.ListItems() for it in self.GetNavigationContainer().GetItems(): navList.append(it) # remove previosly stored next if any - it will be replaced by input new current item if len(navList) > 0: navList.pop() if pushNavItem: #moving to next navList.append(newCurrentNavItem) if newNextNavItem: navList.append(newNextNavItem) else: #moving to back - add next in case if list has inly one item that represents current item if len(navList) < 2 and newNextNavItem: navList.append(newNextNavItem) self.GetNavigationContainer().SetItems(navList) if newNextNavItem: indexToFocus = len(navList) - 2 else: indexToFocus = len(navList) - 1 if indexToFocus < 0: indexToFocus = 0 mc.LogInfo("focus index item: %s nav list len: %s" % (str(indexToFocus), str(len(navList)))) self.GetNavigationContainer().SetFocusedItem(indexToFocus)
def __init__(self): try: import mc import xbmc self.language = xbmc.getLanguage() mc.LogInfo("Current language: %s" % self.language) except: pass
def OnVideoResumeSelected(self): selectedIndex = self.exVideoResumeDialog.GetList().GetFocusedItem() if 0 == selectedIndex: if self.referenceItem.GetProperty("timeToResume"): timeToResumeInSeconds = float(self.referenceItem.GetProperty("timeToResume")) if 0 != timeToResumeInSeconds: t = threading.Thread(target=self.seekTo, args=(timeToResumeInSeconds,)) t.start() if self.exVideoResumeDialog.isPlaylistActive: mc.LogInfo("Start player with playlist item") #self.PlaySelected(self.GetLastViewedEpisodeIndexInPlaylist(), mc.PlayList.PLAYLIST_VIDEO) self.PlaySelectedIndexInPlaylistAsFile(self.GetLastViewedEpisodeIndexInPlaylist()) else: mc.LogInfo("Start player with item: %s" % self.exVideoResumeDialog.playItem.GetLabel()) #self.Play(self.exVideoResumeDialog.playItem) self.PlaySingleItemAsFile(self.exVideoResumeDialog.playItem) self.runEventLoop()
def SaveItem(self, item): mc.LogInfo("saving item: %s" % item.GetLabel()) if item: itemToRemove = self.GetItemIdenticalToItem(item) if itemToRemove: mc.LogInfo("Replace history item") self.historyItems.remove(itemToRemove) self.historyItems.insert(0, item) if self.historyItems[0].GetProperty("timeToResume"): mc.LogInfo( "item time to resume: %s" % str(self.historyItems[0].GetProperty("timeToResume"))) # limit number of saved items to 25 if len(self.historyItems) > 25: self.historyItems.pop() mc.LogInfo("number of saved items: %s" % str(len(self.historyItems))) self.StoreToDefaults()
def OnAction(self): index = self.GetActionsList().GetFocusedItem() item = self.GetActionsList().GetItem(index) if 0 == index: self.OnMoreInfoForItem(item) elif 1 == index: self.OnToggleFavorites(item) else: mc.LogInfo("selected action (%s) is not supported yet" % item.GetLabel());
def OnDialogLoad(self): # external caller is responsible to prepare shared boxee video playlist # before show this dialog videoPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) videos = mc.ListItems() for i in range(videoPlaylist.Size()): playlistItem = videoPlaylist.GetItem(i) item = mc.ListItem(mc.ListItem.MEDIA_VIDEO_EPISODE) item.SetLabel(playlistItem.GetLabel()) item.SetDescription(playlistItem.GetDescription()) item.SetPath(playlistItem.GetPath()) videos.append(item) self.GetPlaylistList().SetItems(videos) index = exPlayer.GetPlayer().GetLastViewedEpisodeIndexInPlaylist() self.GetPlaylistList().SetFocusedItem(index) self.GetPlaylistList().SetSelected(index, True) dialogTitle = mc.GetLocalizedString(559) + ": " + videoPlaylist.GetItem(0).GetTitle() self.GetDialogTitleLabel().SetLabel(dialogTitle) mc.LogInfo("Playlist thumbnail: %s" % videoPlaylist.GetItem(0).GetThumbnail()) self.GetFineArtImage().SetTexture(videoPlaylist.GetItem(0).GetThumbnail()) # fill up actions buttons list actionItems = mc.ListItems() actionItem = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN) # localize with 'more info' # actionItem.SetLabel(mc.GetLocalizedString(53710)) actionItem.SetLabel(exlocalizer.GetSharedLocalizer().localizedString('Info')) actionItem.SetThumbnail('action_more.png') actionItems.append(actionItem) actionItem = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN) # localize with 'add to favorites' #actionItem.SetLabel(mc.GetLocalizedString(53729)) actionItem.SetLabel(exlocalizer.GetSharedLocalizer().localizedString('Add to Favorites')) actionItem.SetThumbnail('action_queue_add.png') actionItems.append(actionItem) self.GetActionsList().SetItems(actionItems) mc.LogInfo("Select playlist window is loaded")
def OnMainWindowLoad(self): # load sections menu if it is empty #systemVersion = xbmc.getInfoLabel('System.BuildVersion') #mc.LogInfo("system version: %s" % systemVersion) mc.LogInfo("On Load Main Window") if 0 == len(self.GetSectionsList().GetItems()): tracker.trackMainView('UA-25431823-1') mc.LogInfo("On Load: Generate sections menu") sectionsMenu = mc.ListItems() sectionsList = self.LoadSectionsList() if 0 == len(sectionsList): mc.LogInfo("Failed to load data from url: %s" % self.model.URL) mc.ShowDialogOk( self.localizedString("No access to www.fs.to"), self.localizedString( "Please make sure you have proxy disabled and check access to www.fs.ua in your internet browser" )) mc.GetApp().Close() return mc.ShowDialogWait() # fill sections list with available items for section in sectionsList: item = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN) item.SetLabel(section["name"]) item.SetPath(section["path"]) item.SetProperty("search", str(section["cleanUrl"])) sectionsMenu.append(item) self.GetSectionsList().SetItems(sectionsMenu) self.GetSectionsList().SetFocusedItem(0) self.GetControl(self.SECTIONS_LIST_ID).SetVisible(True) self.OnSectionSelected() mc.HideDialogWait() else: mc.LogInfo("Main Window Re-load") self.FixupNavigation() if self.IsRecentlyViewedActive(): self.ReloadRecentlyViewedSection()
def runEventLoop(self): mc.LogInfo("Playback event monitoring started") #mc.LogInfo("player last event %s" % self.lastEventDescription()) self.time = 0.000 self.last = self.GetLastPlayerEvent() #mc.LogInfo("player last event %s" % self.lastEventDescription()) while True: event = self.GetLastPlayerEvent() if event != self.last: if event in self.call.keys(): self.last = event self.call[event]() if event in [self.EVENT_ENDED, self.EVENT_STOPPED]: mc.LogInfo("Playback event monitoring stopped") break try: self.time = self.GetTime() except: mc.LogInfo("Player not ready") if (self.last == self.EVENT_STARTED): break #mc.LogInfo("Time updated to %s" % str(self.time)) #mc.LogInfo("player last event %s" % self.lastEventDescription()) xbmc.sleep(5000)
def OnSearchInActiveSection(self): if self.GetNavSearchContext(): query = mc.ShowDialogKeyboard( mc.GetLocalizedString(137) + " " + mc.GetLocalizedString(1405) + " " + self.GetNavSectionName(), "", False) if 0 != len(query): pagesDict = self.model.searchInSectionPagesDict( self.GetNavSearchContext(), query) self.UpdatePagesPanelWithSearchResults(query, pagesDict) else: mc.LogInfo( "No search context present - unable to perform search in active section" )
def GetPlayableItemForItemInDict(self, item, playDict): mc.LogInfo("Flow: Created item of type MEDIA_VIDEO_CLIP") #mc.LogInfo("playDict image: %s" % playDict["image"]) type = mc.ListItem.MEDIA_VIDEO_CLIP playItem = mc.ListItem(type) playItem.SetThumbnail(playDict["image"]) #playItem.SetIcon(playDict["image"]) #playItem.SetImage(0, playDict["image"]) playItem.SetTitle(playDict["title"]) playItem.SetDescription(playDict["description"]) playItem.SetLabel(playDict["title"]) playItem.SetPath(item["path"]) playItem.SetAddToHistory(True) playItem.SetProviderSource('www.ex.ua') return playItem
def StartNavNewSection(self, name, currentItem, nextItem): mc.LogInfo("start new section navigation for name: %s" % name) nav = mc.ListItems() # build current item from scratch navItemCurrent = mc.ListItem(mc.ListItem.MEDIA_VIDEO_CLIP) navItemCurrent.SetLabel(name) navItemCurrent.SetTitle(currentItem.GetTitle()) navItemCurrent.SetPath(currentItem.GetPath()) if currentItem.GetProperty("search"): navItemCurrent.SetProperty("search", currentItem.GetProperty("search")) if currentItem.GetProperty("isSearch"): navItemCurrent.SetProperty("isSearch", "true") nav.append(navItemCurrent) # reuse input next item if any if nextItem: nextItem.SetLabel(name) nav.append(nextItem) self.GetNavigationContainer().SetItems(nav) # set current item as focused self.GetNavigationContainer().SetFocusedItem(0)
def log(self, text): try: import mc mc.LogInfo(text) except: print text
def seekTo(self, seconds): while(self.IsPlayingVideo() != True): i = 0 mc.LogInfo("Perform seek to: %s" % str(seconds)) seconds = float(seconds) self.SeekTime(seconds)
def GetFilenamesSortedByModificationDate(self): storedItems = self.GetStoredPlaylistNamesByPlayingTimes() filesList = sorted(storedItems.keys(), key = lambda x: storedItems[x]) mc.LogInfo("sorted list: %s" % str(filesList)) return filesList
def onPlaybackEnded(self, exPlayer, playItem): mc.LogInfo("Playback ended for item: %s" % playItem.GetLabel()) self.historyModel.SaveItem(playItem) exPlayer.referenceItem = None
def onPlaybackStopped(self, exPlayer, playItem, time): mc.LogInfo("Playback stopped for item: %s at time: %s" % (playItem.GetLabel(), str(time))) # update saved item with sto time self.historyModel.SaveItem(playItem) exPlayer.referenceItem = None
def onPlaybackStarted(self, exPlayer, playItem): mc.LogInfo("Playback started for item: %s" % playItem.GetLabel()) self.historyModel.SaveItem(playItem)
def OnNext(self): if self.GetNavNextPageItem(): mc.LogInfo("next item path: %s" % self.GetNavNextPageItem().GetPath()) self.OnLoadSectionPages(self.GetNavNextPageItem(), False, False, True)