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


Python Store.update_or_new方法代码示例

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


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

示例1: AddYoutubeListThread

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import update_or_new [as 别名]
class AddYoutubeListThread(threading.Thread):
    def __init__(self, jukebox, list_url, add_playlist):
        threading.Thread.__init__(self)
        self.jukebox = jukebox
        self.list_url = list_url
        self.add_playlist = add_playlist
        self.store = Store()

    def run(self):
        infos = youtube.get_video_infos_from_list(self.list_url)
        for info in infos:
            print(info)
            try:
                song = Song()
                song.url = info["url"]
                song.uid = info["uid"]
                song.title = info["title"]
                song.img_url = info["image_url"]
                song.duration = info['duration']

                if song.title and song.duration:
                    # 데이터가 valid 할 때만 추가
                    
                    self.store.update_or_new(song)

                    if self.add_playlist:
                        self.jukebox.append_song_playlist(song)
                
            except Exception as e:
                print(e)
开发者ID:mycat83,项目名称:book_python_example,代码行数:32,代码来源:jukebox.py

示例2: JukeBox

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import update_or_new [as 别名]
class JukeBox(object):
    ''' 쥬크박스.

    기능:
     - 음악리스트를 관리한다.
     - 랜덤플레이를 지원한다.
     - 자동플레이를 지원한다.
     - 현재 실행 중인 곡을 알 수 있다.

    '''

    
    music_player = None

    def __init__(self):
        if JukeBox.music_player == None:
            JukeBox.music_player = AsyncMusicPlayer()
            JukeBox.music_player.start()
        self.store = Store()
        
        songs = self.store.get_songs()
        self.append_song_list(songs)

    def append_song_to_db(self, song):
        self.store.update_or_new(song)        

    def append_song_list(self, songs):
        for song in songs:
            self.append_song_playlist(song)

    def append_song_playlist(self, song):
        playlist_lock.acquire()
        playlist.append(song)
        playlist_lock.release()

    def append_playlist_song_by_dbid(self, dbid):
        song = self.store.find_by_id(dbid)
        playlist_lock.acquire()
        playlist.append(song)
        playlist_lock.release()

    def play_right_next(self, song):
        playlist_lock.acquire()
        playlist.insert(0, song)        
        playlist.append(song)

    def current_song(self):
        return self.music_player.current_song

    def current_playlist(self):
        playlist_lock.acquire()
        songs = playlist[:]
        playlist_lock.release()
        
        return songs

    def get_db_songs(self):
        return self.store.get_songs()

    def stop(self):
        print("stop in juke box")
        cmd = ('stop',None)
        command_list.put(cmd)

    def play(self):
        cmd = ('play',None)
        command_list.put(cmd)

    def forward(self):
        cmd = ('forward',None)
        command_list.put(cmd)

    def rewind(self):
        pass

    def clear(self):
        playlist_lock.acquire()
        playlist.clear()
        playlist.append(song)

        self.store.remove_all()
开发者ID:mycat83,项目名称:book_python_example,代码行数:83,代码来源:jukebox.py


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