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


Python History.rescale方法代码示例

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


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

示例1: BasePlayer

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import rescale [as 别名]

#.........这里部分代码省略.........
            }
        }
        # xbmc.log(json.dumps(req))
        rpcresp = xbmc.executeJSONRPC(json.dumps(req))
        # xbmc.log(str(rpcresp))
        rpcresp = json.loads(rpcresp)

        found = False
        foundTrack = False
        if 'error' in rpcresp:
            log(str(rpcresp))
            pass
        elif 'result' in rpcresp:
            found = 0 < int(rpcresp['result']['limits']['end'])
            pass

        if found:
            found = False
            artistname_stripped = strip_accents(artistname)
            for a in rpcresp['result']['artists']:
                if strip_accents(a['artist'].strip().lower()) == artistname_stripped:
                    #xbmc.log('Found artist: ' + str(artistname.encode('utf-8')))
                    found = True
                    # xbmc.log(str(rpcresp['result']))
                    for t in tracks:
                        item = self.findTrack(a['artist'], t)
                        if item is not None:
                            foundTrack = True
                            ret.append(item)

        if foundTrack:
            #log(len(ret))
            a = ret[len(ret) - 1]['artist'][0]
            if artistname.lower() <> a.lower():
                log("WARNING: artist name has some differencies: '" + str(artistname.encode('utf-8')) + "' --- '" + str(a.encode('utf-8')) + "'")

        if not found:
            log('NOT found artist: "' + str(artistname.encode('utf-8')) + '"')
            pass

        return ret

    def _preGenerateTrack(self, artist):
        return True

    def generateNextTrack(self):
        #log('Generating the next track')
        found = False
        item = None
        while not found:
            # Choose an artist
            a = random.randint(0, len(self.tracks) - 1)
            #log('Generated artist number %i' % a)
            artists = self.tracks.keys()
            artist = artists[a]
            #log('Generated artist "%s"' % artist)
            if self.history.isArtistRecentlyPlayed(artist):
                continue

            tryCount = 5
            while not found and 0 < tryCount:
                if not self._preGenerateTrack(artist):
                    break
                tryCount = tryCount - 1
                # Choose a track
                t = random.randint(0, len(self.tracks[artist]) - 1)
                #log('Generated track number %i' % t)
                res = self.findTracks(artist, [self.tracks[artist][t]])
                if len(res) == 0:
                    # Track not found
                    log('Track not found: %s - "%s", removing...' % (artist, self.tracks[artist][t]))
                    # Remove non-existent track from the list
                    del self.tracks[artist][t]
                    if 0 == len(self.tracks[artist]):
                        log('Artist "%s" has no more tracks, removing...' % artist)
                        del self.tracks[artist]
                        # Go to the another artist
                        tryCount = 0

                    # Rescale the history
                    artistCount = len(self.tracks.keys())
                    trackCount = len(self.tracks.values())
                    self.history.rescale(artistCount if artistCount < MAX_ARTIST_COUNT else MAX_ARTIST_COUNT, trackCount * 2 / 3)
                    # Try to choose another track of the same artist

                elif not self.history.isTrackRecentlyPlayed(self.tracks[artist][t]):
                    item = res[0]
                    log('The next track is: %s - "%s"' % (item['artist'][0], item['title']))
                    found = True

                else:
                    log('Track was recently played: %s - "%s", skipping...' % (artist, self.tracks[artist][t]))
                    # Try to choose another track of the same artist

        thumb = item['thumbnail']
        xlistitem = xbmcgui.ListItem(item['title'])
        xlistitem.setInfo("music", infoLabels={"Title": item['title']})
        xlistitem.setArt({'thumb': thumb})  # , 'fanart': thumb})

        return [item['file'], xlistitem]
开发者ID:wkia,项目名称:kodi-addon-repo,代码行数:104,代码来源:player.py


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