def onPlayBackStarted(self): ''' Called when playback started. Checks database to see if video has been watched before. If video has been viewed before and it has been viewed for longer than 30 seconds, ask the user if they want to jump to the last viewed place or to start the video over. ''' win = xbmcgui.Window(10000) win.setProperty('pbe.playing.playbackstopped', 'false') self.addon_id = win.getProperty('pbe.playing.addon_id') self.video_type = win.getProperty('pbe.playing.video_type') self.title = common.str_conv(win.getProperty('pbe.playing.title')) self.season = win.getProperty('pbe.playing.season') self.year = win.getProperty('pbe.playing.year') self.episode = win.getProperty('pbe.playing.episode') self.hash = win.getProperty('pbe.playing.hash') self.imdb_id = win.getProperty('pbe.playing.imdb') common.addon.log( '-' + HELPER + '- -' + 'Beginning Playback: addon: %s, title: %s, year: %s, season: %s, episode: %s' % (self.addon_id, self.title, self.year, self.season, self.episode)) self._totalTime = self.getTotalTime() self._tracker = threading.Thread(target=self._trackPosition) self._tracker.start() self._connect_to_db() sql_select = "SELECT bookmark FROM bookmarks WHERE hash='%s'" % self.hash common.addon.log('-' + HELPER + '- -' + sql_select, 2) self.dbcur.execute(sql_select) bookmark = self.dbcur.fetchone() self._close_db() if bookmark: bookmark = float(bookmark['bookmark']) if not self._sought and bookmark - 30 > 0: common.addon.log('-' + HELPER + '- -' + 'Showing Dialog') question = xbmc.getLocalizedString(12022) % format_time( bookmark) # 12022 = Resume from %s resume = xbmcgui.Dialog() resume = resume.yesno( self.title, '', question, '', xbmc.getLocalizedString(20132), xbmc.getLocalizedString( 13404)) # 20132 = Restart Video 13404 = Resume if resume: self.seekTime(bookmark) self._sought = True
def onPlayBackStarted(self): """ Called when playback started. Checks database to see if video has been watched before. If video has been viewed before and it has been viewed for longer than 30 seconds, ask the user if they want to jump to the last viewed place or to start the video over. """ win = xbmcgui.Window(10000) win.setProperty("pbe.playing.playbackstopped", "false") self.addon_id = win.getProperty("pbe.playing.addon_id") self.video_type = win.getProperty("pbe.playing.video_type") self.title = common.str_conv(win.getProperty("pbe.playing.title")) self.season = win.getProperty("pbe.playing.season") self.year = win.getProperty("pbe.playing.year") self.episode = win.getProperty("pbe.playing.episode") self.hash = win.getProperty("pbe.playing.hash") self.imdb_id = win.getProperty("pbe.playing.imdb") common.addon.log( "-" + HELPER + "- -" + "Beginning Playback: addon: %s, title: %s, year: %s, season: %s, episode: %s" % (self.addon_id, self.title, self.year, self.season, self.episode) ) self._totalTime = self.getTotalTime() self._tracker = threading.Thread(target=self._trackPosition) self._tracker.start() self._connect_to_db() sql_select = "SELECT bookmark FROM bookmarks WHERE hash='%s'" % self.hash common.addon.log("-" + HELPER + "- -" + sql_select, 2) self.dbcur.execute(sql_select) bookmark = self.dbcur.fetchone() self._close_db() if bookmark: bookmark = float(bookmark["bookmark"]) if not self._sought and bookmark - 30 > 0: common.addon.log("-" + HELPER + "- -" + "Showing Dialog") question = xbmc.getLocalizedString(12022) % format_time(bookmark) # 12022 = Resume from %s resume = xbmcgui.Dialog() resume = resume.yesno( self.title, "", question, "", xbmc.getLocalizedString(20132), xbmc.getLocalizedString(13404) ) # 20132 = Restart Video 13404 = Resume if resume: self.seekTime(bookmark) self._sought = True
def onPlayBackStarted(self): ''' Called when playback started. Checks database to see if video has been watched before. If video has been viewed before and it has been viewed for longer than 30 seconds, ask the user if they want to jump to the last viewed place or to start the video over. ''' win = xbmcgui.Window(10000) win.setProperty('pbe.playing.playbackstopped', 'false') self.addon_id = win.getProperty('pbe.playing.addon_id') self.video_type = win.getProperty('pbe.playing.video_type') self.title = common.str_conv(win.getProperty('pbe.playing.title')) self.season = win.getProperty('pbe.playing.season') self.year = win.getProperty('pbe.playing.year') self.episode = win.getProperty('pbe.playing.episode') self.hash = win.getProperty('pbe.playing.hash') self.imdb_id = win.getProperty('pbe.playing.imdb') common.addon.log('-' + HELPER + '- -' +'Beginning Playback: addon: %s, title: %s, year: %s, season: %s, episode: %s' % ( self.addon_id, self.title, self.year, self.season, self.episode) ) self._totalTime = self.getTotalTime() self._tracker = threading.Thread(target=self._trackPosition) self._tracker.start() self._connect_to_db() sql_select = "SELECT bookmark FROM bookmarks WHERE hash='%s'" % self.hash common.addon.log('-' + HELPER + '- -' +sql_select, 2) self.dbcur.execute(sql_select) bookmark = self.dbcur.fetchone() self._close_db() print '<<<<<< -------- OUT OF BOOKMARK ------ <<<<<<<<' print bookmark if bookmark: bookmark = float(bookmark['bookmark']) print 'HERE IS BOOKMARK ------ >>>>>>>>>>>>>>>>>>>>>>>>.' print bookmark #show dialog if at least 10 seconds were viewed earlier if not self._sought and bookmark-10 > 0: common.addon.log('-' + HELPER + '- -' +'Showing Dialog') question = xbmc.getLocalizedString(12022) % format_time(bookmark) # 12022 = Resume from %s resume = xbmcgui.Dialog() resume = resume.yesno(self.title, '', question, '', xbmc.getLocalizedString(20132), xbmc.getLocalizedString(13404)) # 20132 = Restart Video 13404 = Resume if resume: self.seekTime(bookmark) self._sought = True
def add_item(self, title, url, fmtd_title = '', level='0', parent_title='', indent_title='', infolabels='', img='', fanart='', is_playable=False, is_folder=False): ''' Add an item to watch history. Args: title (str): title of the item; used to generate title-hash and sorting url (str): the compelte plugin url that would be called when this item is selected Kwargs: fmtd_title (str): title of the item as it will be displayed in the list. if fmtd_title is None: fmtd_title = title level (str): item level in the hierarchy. Used if playable-item's parent is also being added to the favorites. Non-parent's level is '0' Parent's level starts with '1' Should be covnertiable to integer parent_title (str): If the item has a parent, then the title used to identify the parent indent_title (str): Title to be used in parent-indent mode (WIP) If indent_title is None: indent_title = fmtd_title info_labels (hash): Any information that the calling plugin might need when the item is being retreived goes here. This is also used to set support for metadata for the item with watch history. infolabels = { 'supports_meta' : 'true', 'video_type':video_type, 'name':title, 'imdb_id':imdb_id, 'season':season, 'episode':episode, 'year':year } img (str): url or path of the image to be used as thumbnail and icon of the item fanart (str): url or path of the image to be used as fanart of the item is_playable (bool): set the item isPlayable property is_folder (bool): set the item isFolder property ''' if url.find('&watchhistory=true'): url = url.replace('&watchhistory=true', '') elif url.find('?watchhistory=true&'): url = url.replace('?watchhistory=true&', '?') title = common.str_conv(title) if not fmtd_title: fmtd_title = title else: fmtd_title = common.str_conv(fmtd_title) if not indent_title: indent_title = fmtd_title else: indent_title = common.str_conv(indent_title) hash_title = hashlib.md5(title).hexdigest() if parent_title: parent_title = common.str_conv(parent_title) if parent_title: parent_title = hashlib.md5(parent_title).hexdigest() row_exists = True try: if DB == 'mysql': sql_select = "SELECT * FROM watch_history WHERE addon_id = %s AND hash_title = %s" else: sql_select = "SELECT * FROM watch_history WHERE addon_id = ? AND hash_title = ?" common.addon.log('-' + HELPER + '- -' + '%s : %s, %s' %(sql_select, self.addon_id, hash_title), 2 ) self.dbcur.execute(sql_select, (self.addon_id, hash_title)) common.addon.log('-' + HELPER + '- -' + str(self.dbcur.fetchall()[0]), 2) except: row_exists = False sql_update_or_insert = '' if row_exists == True: if DB == 'mysql': sql_update_or_insert = "UPDATE watch_history SET lastwatched = %s WHERE addon_id = %s AND hash_title = %s" else: sql_update_or_insert = "UPDATE watch_history SET lastwatched = ? WHERE addon_id = ? AND hash_title = ?" common.addon.log('-' + HELPER + '- -' + '%s : %s, %s, %s' %(sql_update_or_insert, 'datetime.datetime.now()', self.addon_id, hash_title), 2 ) self.dbcur.execute(sql_update_or_insert, (datetime.datetime.now(), self.addon_id, hash_title)) else: if DB == 'mysql': sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" else: sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" if infolabels: infolabels = common.encode_dict(infolabels) is_playable = common.bool2str(is_playable) is_folder = common.bool2str(is_folder) infolabels = str(infolabels) common.addon.log('-' + HELPER + '- -' + '%s : %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' %(sql_update_or_insert, self.addon_id, hash_title, title, fmtd_title, common.str_conv(url), infolabels, img, fanart, is_playable, is_folder, 'datetime.datetime.now()', level, parent_title, indent_title), 2 ) self.dbcur.execute(sql_update_or_insert, (self.addon_id, hash_title, title, fmtd_title, url, infolabels, img, fanart, is_playable, is_folder, datetime.datetime.now(), level, parent_title, indent_title)) self.dbcon.commit()
def add_item(self, title, url, fmtd_title='', level='0', parent_title='', indent_title='', infolabels='', img='', fanart='', is_playable=False, is_folder=False): ''' Add an item to watch history. Args: title (str): title of the item; used to generate title-hash and sorting url (str): the compelte plugin url that would be called when this item is selected Kwargs: fmtd_title (str): title of the item as it will be displayed in the list. if fmtd_title is None: fmtd_title = title level (str): item level in the hierarchy. Used if playable-item's parent is also being added to the favorites. Non-parent's level is '0' Parent's level starts with '1' Should be covnertiable to integer parent_title (str): If the item has a parent, then the title used to identify the parent indent_title (str): Title to be used in parent-indent mode (WIP) If indent_title is None: indent_title = fmtd_title info_labels (hash): Any information that the calling plugin might need when the item is being retreived goes here. This is also used to set support for metadata for the item with watch history. infolabels = { 'supports_meta' : 'true', 'video_type':video_type, 'name':title, 'imdb_id':imdb_id, 'season':season, 'episode':episode, 'year':year } img (str): url or path of the image to be used as thumbnail and icon of the item fanart (str): url or path of the image to be used as fanart of the item is_playable (bool): set the item isPlayable property is_folder (bool): set the item isFolder property ''' if url.find('&watchhistory=true'): url = url.replace('&watchhistory=true', '') elif url.find('?watchhistory=true&'): url = url.replace('?watchhistory=true&', '?') title = common.str_conv(title) if not fmtd_title: fmtd_title = title else: fmtd_title = common.str_conv(fmtd_title) if not indent_title: indent_title = fmtd_title else: indent_title = common.str_conv(indent_title) hash_title = hashlib.md5(title).hexdigest() if parent_title: parent_title = common.str_conv(parent_title) if parent_title: parent_title = hashlib.md5(parent_title).hexdigest() row_exists = True try: if DB == 'mysql': sql_select = "SELECT * FROM watch_history WHERE addon_id = %s AND hash_title = %s" else: sql_select = "SELECT * FROM watch_history WHERE addon_id = ? AND hash_title = ?" common.addon.log( '-' + HELPER + '- -' + '%s : %s, %s' % (sql_select, self.addon_id, hash_title), 2) self.dbcur.execute(sql_select, (self.addon_id, hash_title)) common.addon.log( '-' + HELPER + '- -' + str(self.dbcur.fetchall()[0]), 2) except: row_exists = False sql_update_or_insert = '' if row_exists == True: if DB == 'mysql': sql_update_or_insert = "UPDATE watch_history SET lastwatched = %s WHERE addon_id = %s AND hash_title = %s" else: sql_update_or_insert = "UPDATE watch_history SET lastwatched = ? WHERE addon_id = ? AND hash_title = ?" common.addon.log( '-' + HELPER + '- -' + '%s : %s, %s, %s' % (sql_update_or_insert, 'datetime.datetime.now()', self.addon_id, hash_title), 2) self.dbcur.execute( sql_update_or_insert, (datetime.datetime.now(), self.addon_id, hash_title)) else: if DB == 'mysql': sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" else: sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" if infolabels: infolabels = common.encode_dict(infolabels) is_playable = common.bool2str(is_playable) is_folder = common.bool2str(is_folder) infolabels = str(infolabels) common.addon.log( '-' + HELPER + '- -' + '%s : %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' % (sql_update_or_insert, self.addon_id, hash_title, title, fmtd_title, common.str_conv(url), infolabels, img, fanart, is_playable, is_folder, 'datetime.datetime.now()', level, parent_title, indent_title), 2) self.dbcur.execute( sql_update_or_insert, (self.addon_id, hash_title, title, fmtd_title, url, infolabels, img, fanart, is_playable, is_folder, datetime.datetime.now(), level, parent_title, indent_title)) self.dbcon.commit()