当前位置: 首页>>代码示例>>Python>>正文


Python History.addEntry方法代码示例

本文整理汇总了Python中history.History.addEntry方法的典型用法代码示例。如果您正苦于以下问题:Python History.addEntry方法的具体用法?Python History.addEntry怎么用?Python History.addEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在history.History的用法示例。


在下文中一共展示了History.addEntry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BasePlayer

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import addEntry [as 别名]
class BasePlayer(xbmc.Player):

    WINDOW = 12006 # music visualization

    def __init__(self):
        log('creating player class')
        xbmc.Player.__init__(self)
        self.history = None
        self.tracks = None
        self.stopped = True
        self.dlgProgress = None
        pass

    def init(self):
        log('initializing player class')
        self.dlgProgress = xbmcgui.DialogProgress()
        self.dlgProgress.create('Openlast', 'Initializing addon...')
        self.dlgProgress.update(0)

        self.tracks = self.loadAllTracks()

        artistCount = len(self.tracks.keys())
        trackCount = len(self.tracks.values())
        self.history = History(artistCount if artistCount < MAX_ARTIST_COUNT else MAX_ARTIST_COUNT, trackCount * 2 / 3)
        random.seed()

        lastfmUser = ''
        try:
            lastfmAddon = xbmcaddon.Addon('service.scrobbler.lastfm')
            lastfmUser = lastfmAddon.getSetting('lastfmuser')
        except RuntimeError:
            pass
        if 0 < len(lastfmUser):
            self.loadRecentTracks(lastfmUser)

        if self.dlgProgress.iscanceled() or self.tracks is None:
            self.dlgProgress.close()
            self.dlgProgress = None
            return False

        return True

    def play(self):
        log('play')
        self.stopped = False
        nextItem = self.generateNextTrack()
        self.dlgProgress.update(100)
        playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
        playlist.clear()
        playlist.add(nextItem[0], nextItem[1])
        self.dlgProgress.close()
        xbmc.Player.play(self, playlist)
        xbmc.executebuiltin("ActivateWindow(%d)" % (self.WINDOW,))
        pass

    def onPlayBackStarted(self):
        #log('onPlayBackStarted')
        # tags are not available instantly and we don't what to announce right
        # away as the user might be skipping through the songs
        xbmc.sleep(500)

        # get tags
        entry = self._get_tags()
        self.history.addEntry(entry[0], entry[1])

        # choose the next track
        playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
        if playlist.getposition() + 1 == playlist.size():
            nextItem = self.generateNextTrack()
            playlist.add(nextItem[0], nextItem[1])
        pass

    def onPlayBackStopped(self):
        log('onPlayBackStopped')
        self.stopped = True
        pass

    def _get_tags(self):
        # get track tags
        artist = self.getMusicInfoTag().getArtist().decode("utf-8")
        album = self.getMusicInfoTag().getAlbum().decode("utf-8")
        title = self.getMusicInfoTag().getTitle().decode("utf-8")
        duration = str(self.getMusicInfoTag().getDuration())
        # get duration from xbmc.Player if the MusicInfoTag duration is invalid
        if int(duration) <= 0:
            duration = str(int(self.getTotalTime()))
        track = str(self.getMusicInfoTag().getTrack())
        path = self.getPlayingFile().decode("utf-8")
        thumb = xbmc.getCacheThumbName(path)
        #log('artist: ' + artist)
        #log('title: ' + title)
        #log('album: ' + album)
        #log('track: ' + str(track))
        #log('duration: ' + str(duration))
        #log('path: ' + path)
        #log('local path: ' + user)
        #log('thumb: ' + thumb)

        #log('cover art: ' + str(xbmc.getInfoLabel('MusicPlayer.Cover')))
        #log('thumb art: ' + str(xbmc.getInfoLabel('Player.Art(thumb)')))
#.........这里部分代码省略.........
开发者ID:wkia,项目名称:kodi-addon-repo,代码行数:103,代码来源:player.py


注:本文中的history.History.addEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。