def _loadDetails(self): log("AudioBookHandler: Loading audio book %s (%s)" % (self.filePath, self.fileName)) # Check to see if we already have an image available self.coverImage = self._getExistingCoverImage() # Check in the database to see if this audio book is already recorded audiobookDB = AudioBooksDB() audiobookDetails = audiobookDB.getAudioBookDetails(self.filePath) if audiobookDetails not in [None, ""]: self.title = audiobookDetails['title'] self.numChapters = audiobookDetails['numChapters'] self.position = audiobookDetails['position'] self.chapterPosition = audiobookDetails['chapterPosition'] self.isComplete = audiobookDetails['complete'] else: self.position = 0 self.chapterPosition = 0 self.isComplete = False self._loadSpecificDetails() if self.title in [None, ""]: log("AudioBookHandler: No title found for %s, using filename" % self.filePath) self.title = self._getFallbackTitle() self.numChapters = len(self.chapters) # Now update the database entry for this audio book audiobookDB.addAudioBook(self.filePath, self.title, self.numChapters) del audiobookDB
def progress(self, fullpath, isComplete=True, startTime=0): # At the moment the only time progress is called is to mark as complete audiobookDB = AudioBooksDB() audiobookDB.setPosition(fullpath, startTime, isComplete) del audiobookDB xbmc.executebuiltin("Container.Refresh")
def _loadDetails(self): log("AudioBookHandler: Loading audio book %s (%s)" % (self.filePath, self.fileName)) # Check in the database to see if this audio book is already recorded audiobookDB = AudioBooksDB() audiobookDetails = audiobookDB.getAudioBookDetails(self.filePath) if audiobookDetails not in [None, ""]: self.title = audiobookDetails['title'] self.numChapters = audiobookDetails['numChapters'] self.position = audiobookDetails['position'] self.chapterPosition = audiobookDetails['chapterPosition'] self.isComplete = audiobookDetails['complete'] self.hasArtwork = audiobookDetails['hasArtwork'] else: self.position = 0 self.chapterPosition = 0 self.isComplete = False self._loadBookDetails() if self.title in [None, ""]: log("AudioBookHandler: No title found for %s, trying ffmpeg load" % self.filePath) self._loadDetailsFromFfmpeg() if self.title in [None, ""]: log("AudioBookHandler: No title found for %s, using filename" % self.filePath) self.title = self._getFallbackTitle() self.numChapters = len(self.chapters) # Now update the database entry for this audio book audiobookDB.addAudioBook(self.filePath, self.title, self.numChapters) del audiobookDB
def clear(self, fullpath): log("AudioBooksPlugin: Clearing history for %s" % fullpath) # Remove the item from the database, it will then be rescanned audiobookDB = AudioBooksDB() audiobookDB.deleteAudioBook(fullpath) del audiobookDB xbmc.executebuiltin("Container.Refresh")
def playAudioBook(audioBookHandler, startTime=-1, chapter=0): log("BookPlayer: Playing audio book = %s" % audioBookHandler.getFile()) bookPlayer = BookPlayer() playlist = audioBookHandler.getPlayList(startTime, chapter) bookPlayer.play(playlist) # Don't allow this to loop forever loopCount = 3000 while (not bookPlayer.isPlaying()) and (loopCount > 0): xbmc.sleep(1) loopCount = loopCount - 1 # Looks like the audiobook never started for some reason, do not go any further if loopCount == 0: return currentTime = 0 currentFile = '' waitingForComplete = 0 # Wait for the player to stop while waitingForComplete < 30: # There is a small gap when switching between different items in the same # playlist where it records it as not playing, so we need to give it a little # bit of time to start playing the next item in the playlist if there is one if bookPlayer.isPlaying(): # Keep track of where the current track is up to currentTime = int(bookPlayer.getTime()) currentFile = bookPlayer.getPlayingFile() waitingForComplete = 0 else: waitingForComplete += 1 xbmc.sleep(10) # Record the time that the player actually stopped log("BookPlayer: Played to time = %d, file = %s" % (currentTime, currentFile)) # Get the chapter number that was playing chapterPosition = audioBookHandler.getChapterPosition(currentFile) log("BookPlayer: Chapter position is %d" % chapterPosition) if (currentTime > 0) or (chapterPosition > 1): bookComplete = False duration = audioBookHandler.getTotalDuration() log("BookPlayer: Total book duration is %d" % duration) if duration > 1: if currentTime > (duration - 60): bookComplete = True audiobookDB = AudioBooksDB() audiobookDB.setPosition(audioBookHandler.getFile(), currentTime, chapterPosition, bookComplete) del audiobookDB
def _loadDetails(self): log("AudioBookHandler: Loading audio book %s (%s)" % (self.filePath, self.fileName)) # Check in the database to see if this audio book is already recorded audiobookDB = AudioBooksDB() audiobookDetails = audiobookDB.getAudioBookDetails(self.filePath) if audiobookDetails not in [None, ""]: # Convert to unicode when reading from DB. This fixes problems when # comparing to new items returned by mutagen which are unicode. try: self.title = audiobookDetails['title'].decode('utf-8') except: self.title = audiobookDetails['title'] self.numChapters = audiobookDetails['numChapters'] self.position = audiobookDetails['position'] self.chapterPosition = audiobookDetails['chapterPosition'] self.isComplete = audiobookDetails['complete'] self.hasArtwork = audiobookDetails['hasArtwork'] else: self.position = 0 self.chapterPosition = 0 self.isComplete = False self._loadBookDetails() if self.title in [None, ""]: log("AudioBookHandler: No title found for %s, trying ffmpeg load" % self.filePath) self._loadDetailsFromFfmpeg() if self.title in [None, ""]: log("AudioBookHandler: No title found for %s, using filename" % self.filePath) self.title = self._getFallbackTitle() self.numChapters = len(self.chapters) # Now update the database entry for this audio book audiobookDB.addAudioBook(self.filePath, self.title, self.numChapters) del audiobookDB
def getCoverImage(self, tryUtf8=False): if self.coverImage is None: # Check to see if we already have an image available self.coverImage = self._getExistingCoverImage() # Before we go checking the actual file, see if we recorded that # we have already checked and there was not any if self.hasArtwork != 0: # If nothing was cached, then see if it can be extracted from the metadata if self.coverImage is None: self.coverImage = self._saveAlbumArtFromMetadata(self.filePath) # Last resort is to try and extract with ffmpeg # Only do the ffmpeg check if using the ffmpeg executable as # that is the only one that will get the album artwork if (self.coverImage is None) and (Settings.getFFmpegSetting() == Settings.FFMPEG_EXEC): self._loadDetailsFromFfmpeg() # Check if we have now found artwork that we want to store audiobookDB = AudioBooksDB() self.hasArtwork = 0 if self.coverImage not in [None, ""]: self.hasArtwork = 1 # Update the database with the artwork status audiobookDB.setHasArtwork(self.filePath, self.hasArtwork) del audiobookDB coverImageValue = self.coverImage # Make sure the cover is correctly encoded if tryUtf8 and (coverImageValue not in [None, ""]): try: coverImageValue = coverImageValue.encode("utf-8") except: pass return coverImageValue
def playAudioBook(audioBookHandler, startTime=-1, chapter=0): log("BookPlayer: Playing audio book = %s" % audioBookHandler.getFile()) bookPlayer = BookPlayer() playlist = audioBookHandler.getPlayList(startTime, chapter) bookPlayer.play(playlist) # Don't allow this to loop forever loopCount = 3000 while (not bookPlayer.isPlaying()) and (loopCount > 0): xbmc.sleep(1) loopCount = loopCount - 1 # Looks like the audiobook never started for some reason, do not go any further if loopCount == 0: return currentTime = 0 currentFile = '' totalTrackTime = 0 waitingForComplete = 0 # Wait for the player to stop while waitingForComplete < 30: # There is a small gap when switching between different items in the same # playlist where it records it as not playing, so we need to give it a little # bit of time to start playing the next item in the playlist if there is one if bookPlayer.isPlaying(): # Keep track of where the current track is up to try: currentTime = int(bookPlayer.getTime()) currentFile = bookPlayer.getPlayingFile() totalTrackTime = bookPlayer.getTotalTime() waitingForComplete = 0 except: # If we get an exception there it is most probably because there is # a small gap between checking if something is playing and getting # each of the values waitingForComplete += 1 else: waitingForComplete += 1 xbmc.sleep(10) # Record the time that the player actually stopped log("BookPlayer: Played to time = %d, file = %s, totalTime = %s" % (currentTime, currentFile, totalTrackTime)) # Get the chapter number that was playing chapterPosition = audioBookHandler.getChapterPosition(currentFile) log("BookPlayer: Chapter position is %d" % chapterPosition) if (currentTime > 0) or (chapterPosition > 1): bookComplete = False duration = audioBookHandler.getTotalDuration() log("BookPlayer: Total book duration is %d" % duration) if duration > 1: if currentTime > (duration - 60): log("BookPlayer: Marking entire book as complete") bookComplete = True # If dealing with multiple files for a single book, need to check if the entire # book is complete if chapterPosition == len(audioBookHandler.getChapterDetails()): if (currentTime + 60) > totalTrackTime: log("BookPlayer: Marking book as complete") bookComplete = True audiobookDB = AudioBooksDB() audiobookDB.setPosition(audioBookHandler.getFile(), currentTime, chapterPosition, bookComplete) del audiobookDB