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


Python Book.set_progress方法代码示例

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


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

示例1: Player

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import set_progress [as 别名]

#.........这里部分代码省略.........
        self.status_light.interrupt('blink_fast', 3)
        with self.mpd_client:
            self.mpd_client.setvol(volume)
            print "volume set to %d" % volume


    def stop(self):
        """On stopping, reset the current playback and stop and clear the playlist

        In contract to pausing, stopping is actually meant to completely stop playing
        the current book and start listening to another"""

        self.playing = False
        self.book.reset()

        self.status_light.action = 'on'

        with self.mpd_client:
            self.mpd_client.stop()
            self.mpd_client.clear()


    def play(self, book_id, progress=None):
        """Play the book as defined in self.book

        1. Get the parts from the current book and add them to the playlsit
        2. Start playing the playlist
        3. Immediately set the position the last know position to resume playback where
           we last left off"""

        def sorter(file1, file2):

            """sorting algorithm for files in playlist"""
            pattern = '(\d+)(-(\d+))?\.mp3'

            try:
                file1_index = re.search(pattern, file1).groups()[2] or 0
                file2_index = re.search(pattern, file2).groups()[2] or 0

                return -1 if int(file1_index) < int(file2_index) else 1
            except:
                return 0


        with self.mpd_client:

            parts = self.mpd_client.search('filename', book_id)

            if not parts:
                self.status_light.interrupt('blink_fast', 3)
                return

            self.mpd_client.clear()

            for part in sorted(parts, cmp=sorter):
                self.mpd_client.add(part['file'])

            self.book.book_id = book_id

            if progress:
                # resume at last known position
                self.book.set_progress(progress)
                self.mpd_client.seek(int(self.book.part) - 1, int(self.book.elapsed))
            else:
                # start playing from the beginning
                self.mpd_client.play()

        self.status_light.action = 'blink'
        self.book.file_info = self.get_file_info()


    def is_playing(self):
        return self.get_status()['state'] == 'play'

    def finished_book(self):
        """return if a book has finished, in which case we need to delete it from the db
        or otherwise we could never listen to that particular book again"""

        status = self.get_status()
        return self.book.book_id is not None and \
               status['state'] == 'stop' and \
               self.book.part == int(status['playlistlength']) and \
               'time' in self.book.file_info and float(self.book.file_info['time']) - self.book.elapsed < 20



    def get_status(self):
        with self.mpd_client:
            return self.mpd_client.status()


    def get_file_info(self):
        with self.mpd_client:
            return self.mpd_client.currentsong()


    def close(self):
        self.stop()
        self.mpd_client.close()
        self.mpd_client.disconnect()
开发者ID:wkjagt,项目名称:BookPlayer,代码行数:104,代码来源:player.py

示例2: Player

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import set_progress [as 别名]

#.........这里部分代码省略.........

        def sorter(file1, file2):

            """sorting algorithm for files in playlist"""
            pattern = "(\d+)(-(.+))?\.mp3"

            try:
                file1_index = re.search(pattern, file1).groups()[1] or 0
                file2_index = re.search(pattern, file2).groups()[1] or 0

                return -1 if int(file1_index) < int(file2_index) else 1
            except:
                return 0

        with self.mpd_client:

            self.set_title_index(book_title)

            parts = self.mpd_client.search("filename", book_title)

            if not parts:
                self.status_light.interrupt("blink_fast", 3)
                return

            self.mpd_client.clear()

            for part in sorted(parts, cmp=sorter):
                self.mpd_client.add(part["file"])

            self.book.book_title = book_title

            if progress:
                # resume at last known position
                self.book.set_progress(progress)
                self.mpd_client.seek(int(self.book.part) - 1, int(self.book.elapsed))
            else:
                # start playing from the beginning
                self.mpd_client.play()

            # print("Now playing: %s %s" % (self.book.book_title, self.book.part))

        self.status_light.action = "blink"
        self.book.file_info = self.get_file_info()

    def get_book_titles(self):
        return self.book_titles

    def first_title(self):
        if len(self.book_titles) == 0:
            self.status_light.interrupt("blink_fast", 3)
            return ""

        with self.index_lock:
            self.current_index = 0

            return self.book_titles[0]

    def next_title(self, channel):
        with self.index_lock:
            if len(self.book_titles) <= self.current_index + 1:
                return self.first_title()

            self.current_index += 1
            return self.book_titles[self.current_index]

    def get_title(self):
开发者ID:grvrulz,项目名称:BookPlayer,代码行数:70,代码来源:player.py


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