Ejemplo n.º 1
0
    def _skip_head(current_index):

        logger.debug('==start==')
        logger.debug(f'cur index: {current_index}')
        logger.debug(
            f"position_in_playlist: {play_list.playlist_init_position}")
        logger.debug(f'current_video_position: {ac.current_video_position}')
        logger.debug(f'seek to {format_time(play_list.playlist.skip_head)}')
        logger.debug('== end ==')

        if play_list.playlist_init_position > 0 and play_list.playlist_init_index == ac.current_idx:
            if play_list.playlist_init_position > ac.current_video_position:
                resume_position = play_list.playlist_init_position - 5
                if resume_position < 0:
                    resume_position = 0
                time_str = format_time(resume_position)
                ac.device.seek(time_str)
                play_list.playlist.current_pos = play_list.playlist_init_position
                play_list.playlist.save_playlist(force=True)
                play_list.playlist_init_position = -1
        elif play_list.playlist.skip_head > 0:
            time.sleep(0.5)
            time_str = format_time(play_list.playlist.skip_head)
            ac.device.seek(time_str)
            play_list.playlist.current_pos = play_list.playlist.skip_head
            play_list.playlist.save_playlist(force=True)
Ejemplo n.º 2
0
    def draw(self):

        columns, lines = shutil.get_terminal_size((80, 20))

        text = '\r'
        text += format_time(self.cur_pos) + '/' + format_time(
            self.duration) + ' | '
        text += self.player_status.value
        text += ' current: '
        text_columns = sum(wcwidth(c) for c in text)
        remain_columns = columns - text_columns - 5
        if remain_columns > 0:

            msg = self._video_file_name

            if self._exception is not None:
                msg = str(self._exception)

            name_columns = sum(wcwidth(c) for c in msg)
            if name_columns <= remain_columns:
                text += msg
                text += ' ' * (remain_columns - name_columns)
            else:
                # 剩余空间太小就不显示
                if remain_columns > 5:
                    # 截取头部和尾部显示
                    part_len = int((remain_columns - 2) / 2)
                    text += msg[:part_len - 1] + '..' + msg[-part_len + 1:]
                else:
                    text += ' ' * (remain_columns - name_columns)

        stdout.write(text)
Ejemplo n.º 3
0
 def _forward(event, times):
     target_position = ac.current_video_position + 10 * times
     if ac.current_video_duration == 0:
         time_str = format_time(target_position)
         ac.device.seek(time_str)
         return
     if target_position >= ac.get_max_video_position():
         target_position = ac.get_max_video_position() - 10
     time_str = format_time(target_position)
     ac.device.seek(time_str)
Ejemplo n.º 4
0
    def resume(self, stop=False, seek_to: int = 0, ):
        self.enable_hook = False
        try:
            time_str = format_time(self.current_video_position)
            if seek_to > 0:
                time_str = format_time(seek_to)
                self.current_video_position = seek_to

            if stop:
                self.device.stop()
                self.device.set_AV_transport_URI(self.server_file_path)

            self.device.play()
            self.player.player_status = PlayerStatus.PLAY
            self.ensure_player_is_playing()
            if seek_to > 0:
                self.device.seek(time_str)
            # 强制下一次轮询时强制更新
            if self.device.sync_thread is not None:
                self.device.sync_thread.last_status = None
        finally:
            self.events['resume'].fire(self.current_idx)
            self.enable_hook = True
Ejemplo n.º 5
0
    def render_request(self):
        request_command = request.params.get('command')
        if request_command == 'status':
            return self.get_dlna_status()
        elif request_command == 'pause':
            self.ac.pause()
            return ''
        elif request_command == 'play':
            self.ac.resume()
            return ''
        elif request_command == 'stop':
            self.ac.stop()
            return ''
        elif request_command == 'index':
            return self.index()
        elif request_command == 'seek':
            pos = int(request.params.get('pos'))
            self.ac.device.seek(format_time(pos + self.ac.current_video_position))
            return ''
        elif request_command == 'getAllPlaylist':
            return self.get_all_playlist()
        elif request_command == 'switchPlayList':
            return self.switch_playlist()
        elif request_command == 'playAtApp':
            index = int(request.params.get('index'))
            return self.play_at_app(index)
        elif request_command == 'backToDlna':
            self.back_to_dlna()
            return ''
        elif request_command == 'selectDevice':
            self.select_device()
            return ''
        elif request_command == 'refreshDevice':
            self.refresh_device()
            return ''

        abort(404, "错误的命令")
Ejemplo n.º 6
0
 def _backward(event, times):
     target_position = ac.current_video_position - 10 * times
     if target_position <= 0:
         target_position = 1
     time_str = format_time(target_position)
     ac.device.seek(time_str)