Esempio n. 1
0
class IkaRename:

    def createMP4Filename(self, context):
        map = IkaUtils.map2text(context['game']['map'], unknown='マップ不明')
        rule = IkaUtils.rule2text(context['game']['rule'], unknown='ルール不明')
        won = IkaUtils.getWinLoseText(
            context['game']['won'], win_text='win', lose_text='lose')

        timestamp = time.localtime(os.stat(file).st_mtime)
        time_str = time.strftime("%Y%m%d_%H%M", timestamp)
        newname = '%s_%s_%s_%s.mp4' % (time_str, map, rule, won)

        return newname

    def onFrameReadFailed(self, context):
        print('%s: たぶんファイルの終端にたどり着きました' % self.file)
        # もういいので IkaEngine を止める
        self.engine.stop()

    def onGameIndividualResult(self, context):
        mp4_filename = self.createMP4Filename(context)
        destname = os.path.join(os.path.dirname(self.file), mp4_filename)

        print('%s: 新ファイル名 %s' % (self.file, destname))

        # 強制的にキャプチャを閉じて IkaEngine も止める
        self.engine.capture.cap.release()
        self.engine.capture.cap = None
        self.engine.stop()

        os.rename(self.file, destname)

    def __init__(self, file):
        self.file = file

        # インプットとして指定されたファイルを読む
        source = CVCapture()
        source.start_recorded_file(file)
        source.need_resize = True

        # 画面が見えないと進捗が判らないので
        screen = outputs.Screen(0, size=(640, 360))

        # プラグインとして自分自身(画面)を設定しコールバックを受ける
        outputPlugins = [self, screen]

        # IkaEngine を実行
        self.engine = IkaEngine()
        self.engine.pause(False)
        self.engine.set_capture(source)
        self.engine.set_plugins(outputPlugins)
        self.engine.run()
Esempio n. 2
0
class IkaRename:
    def createMP4Filename(self, context):
        map = IkaUtils.map2text(context['game']['map'], unknown='マップ不明')
        rule = IkaUtils.rule2text(context['game']['rule'], unknown='ルール不明')
        won = IkaUtils.getWinLoseText(context['game']['won'],
                                      win_text='win',
                                      lose_text='lose')

        timestamp = time.localtime(os.stat(file).st_mtime)
        time_str = time.strftime("%Y%m%d_%H%M", timestamp)
        newname = '%s_%s_%s_%s.mp4' % (time_str, map, rule, won)

        return newname

    def onFrameReadFailed(self, context):
        print('%s: たぶんファイルの終端にたどり着きました' % self.file)
        # もういいので IkaEngine を止める
        self.engine.stop()

    def onGameIndividualResult(self, context):
        mp4_filename = self.createMP4Filename(context)
        destname = os.path.join(os.path.dirname(self.file), mp4_filename)

        print('%s: 新ファイル名 %s' % (self.file, destname))

        # 強制的にキャプチャを閉じて IkaEngine も止める
        self.engine.capture.cap.release()
        self.engine.capture.cap = None
        self.engine.stop()

        os.rename(self.file, destname)

    def __init__(self, file):
        self.file = file

        # インプットとして指定されたファイルを読む
        source = CVCapture()
        source.start_recorded_file(file)
        source.need_resize = True

        # 画面が見えないと進捗が判らないので
        screen = outputs.Screen(0, size=(640, 360))

        # プラグインとして自分自身(画面)を設定しコールバックを受ける
        outputPlugins = [self, screen]

        # IkaEngine を実行
        self.engine = IkaEngine()
        self.engine.pause(False)
        self.engine.set_capture(source)
        self.engine.set_plugins(outputPlugins)
        self.engine.run()
Esempio n. 3
0
    pos_msec = args.get('time_msec') or time_to_msec(args.get('time') or '0:0')
    if pos_msec:
        capture.set_pos_msec(pos_msec)


if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal_handler)

    args = get_args()
    capture, output_plugins = config_loader.config(args)

    if isinstance(capture, inputs.CVFile):
        init_for_cvfile(args, capture)

    engine = IkaEngine(enable_profile=args.get('profile'))
    engine.pause(False)
    engine.set_capture(capture)

    epoch_time = get_epoch_time(args, capture)
    if epoch_time:
        engine.set_epoch_time(epoch_time)

    engine.set_plugins(output_plugins)
    for op in output_plugins:
        engine.enable_plugin(op)

    engine.close_session_at_eof = True
    engine.run()
    IkaUtils.dprint('bye!')
Esempio n. 4
0
    if not capture.is_active():
        IkaUtils.dprint('Failed to initialize with: %s' % capture._source_file)
        sys.exit(1)

    pos_msec = args.get('time_msec') or time_to_msec(args.get('time') or '0:0')
    if pos_msec:
        capture.set_pos_msec(pos_msec)


if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal_handler)

    args = get_args()
    capture, OutputPlugins = config_loader.config(args)

    if isinstance(capture, inputs.CVFile):
        init_for_cvfile(args, capture)

    engine = IkaEngine(enable_profile=args.get('profile'))
    engine.pause(False)
    engine.set_capture(capture)

    epoch_time = get_epoch_time(args, capture)
    if epoch_time:
        engine.set_epoch_time(epoch_time)

    engine.set_plugins(OutputPlugins)
    engine.close_session_at_eof = True
    engine.run()
    IkaUtils.dprint('bye!')
Esempio n. 5
0

def get_pos_msec(args):
    if args['time_msec']:
        return args['time_msec']
    elif args['time']:
        minute, sec = args['time'].split(':')
        return (int(minute) * 60 + int(sec)) * 1000
    else:
        return 0


if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal_handler)

    args = get_args()
    capture, output_plugins = config_loader.config(args)
    capture.set_pos_msec(get_pos_msec(args))

    engine = IkaEngine(enable_profile=args.get('profile'))
    engine.pause(False)
    engine.set_capture(capture)

    engine.set_plugins(output_plugins)
    for op in output_plugins:
        engine.enable_plugin(op)

    engine.close_session_at_eof = True
    engine.run()
    IkaUtils.dprint('bye!')
Esempio n. 6
0
class TestSceneLobbyVideos(unittest.TestCase):

    scene_name = 'lobby'

    def _load_screenshot(self, filename):
        filepath = os.path.join('test_data', 'movies',
                                self.scene_name, filename)

    def noop(self, context):
        pass

    def on_frame_read_failed(self, context):
        self.engine.stop()

    def onUncatchedEvent(self, event_name, context):
        if not (event_name in self.event_tickets):
            self.errors.append('Unexpected event %s triggered' % event_name)

        if self.event_tickets[event_name] is None:
            return

        self.event_tickets[event_name] = self.event_tickets[event_name] - 1

        if not (0 <= self.event_tickets[event_name]):
            self.errors.append('Too many events triggered: %s' % event_name)

    def _test_engine(self, mp4_filename):
        from ikalog.inputs.cvcapture import CVCapture
        from ikalog.engine import IkaEngine
        from ikalog.outputs.preview import Screen
        from ikalog.outputs.debug import DebugLog

        self.errors = []
        source = CVCapture()
        source.start_recorded_file(mp4_filename)
        source.need_resize = True
        outputPlugins = [
            self,
            Screen(0, size=(640, 360)),
            DebugLog(dir='./debug/', screenshot=True),
        ]

        self.engine = IkaEngine()

        self.engine.set_capture(source)
        self.engine.set_plugins(outputPlugins)
        self.engine.pause(False)

        print('Engine started')
        self.engine.run()
        print('Engine stopped')

        # 期待されたイベントが全て発生しているか確認
        for event_name in list(self.event_tickets.keys()):
            if self.event_tickets[event_name] is None:
                continue
            assert self.event_tickets[event_name] == 0, 'Missed event %s? %s tickets remained.' % (
                event_name, self.event_tickets[event_name])

        assert len(self.errors) == 0, '\n'.join(self.errors)

        # unreference the engine
        engine = self.engine
        self.engine = None
        return engine

    def test_lobby_tag_2_matching_to_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,
            'on_lobby_matching': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/lobby/lobby_tag_2_matching_to_matched.mp4')

        assert engine.context['lobby']['type'] == 'tag'
        assert engine.context['lobby']['state'] == 'matched'
        assert engine.context['lobby']['team_members'] == 2

    def test_lobby_tag_2_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }
        engine = self._test_engine(
            'test_data/movies/lobby/lobby_tag_2_matched.mp4')

        assert engine.context['lobby']['type'] == 'tag'
        assert engine.context['lobby']['state'] == 'matched'
        assert engine.context['lobby']['team_members'] == 2

    def test_lobby_tag_4_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/lobby/lobby_tag_4_matched.mp4')

        assert engine.context['lobby']['type'] == 'tag'
        assert engine.context['lobby']['state'] == 'matched'
        assert engine.context['lobby']['team_members'] == 4

    def test_lobby_public_matching_to_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,
            'on_lobby_matching': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/lobby/lobby_public_matching_to_matched.mp4')

        assert engine.context['lobby']['type'] == 'public'
        assert engine.context['lobby']['state'] == 'matched'

    def test_lobby_fes_matching_to_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,
            'on_lobby_matching': None,  # フェスのマッチング中は未実装

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/lobby/lobby_fes_matching_to_matched.mp4')

        assert engine.context['lobby']['type'] == 'festa'
        assert engine.context['lobby']['state'] == 'matched'
Esempio n. 7
0
class TestSceneLobbyVideos(unittest.TestCase):

    scene_name = 'lobby'

    def _load_screenshot(self, filename):
        filepath = os.path.join('test_data', 'movies',
                                self.scene_name, filename)

    def noop(self, context):
        pass

    def on_frame_read_failed(self, context):
        self.engine.stop()

    def onUncatchedEvent(self, event_name, context):
        if not (event_name in self.event_tickets):
            self.errors.append('Unexpected event %s triggered' % event_name)

        if self.event_tickets[event_name] is None:
            return

        self.event_tickets[event_name] = self.event_tickets[event_name] - 1

        if not (0 <= self.event_tickets[event_name]):
            self.errors.append('Too many events triggered: %s' % event_name)

    def _test_engine(self, mp4_filename,game_lang=None):
        from ikalog.utils import Localization
        if game_lang:
            Localization.set_game_languages(game_lang)

        from ikalog.inputs import CVFile
        from ikalog.engine import IkaEngine
        from ikalog.outputs.preview import Screen
        from ikalog.outputs.debug import DebugLog

        self.errors = []
        source = CVFile()
        source.start_video_file(mp4_filename)
        source.need_resize = True
        outputPlugins = [
            self,
            Screen(0, size=(640, 360)),
            # DebugLog(dir='./debug/', screenshot=True),
        ]

        self.engine = IkaEngine()

        self.engine.set_capture(source)
        self.engine.set_plugins(outputPlugins)
        self.engine.pause(False)

        print('Engine started')
        try:
            self.engine.run()
        except EOFError:
            pass
        print('Engine stopped')

        # 期待されたイベントが全て発生しているか確認
        for event_name in list(self.event_tickets.keys()):
            if self.event_tickets[event_name] is None:
                continue
            assert self.event_tickets[event_name] == 0, 'Missed event %s? %s tickets remained.' % (
                event_name, self.event_tickets[event_name])

        assert len(self.errors) == 0, '\n'.join(self.errors)

        # unreference the engine
        engine = self.engine
        self.engine = None
        return engine

    def test_lobby_tag_2_matching_to_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,
            'on_lobby_matching': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/ja/lobby/lobby_tag_2_matching_to_matched.mp4')

        assert engine.context['lobby']['type'] == 'tag'
        assert engine.context['lobby']['state'] == 'matched'
        assert engine.context['lobby']['team_members'] == 2

    def test_lobby_tag_2_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }
        engine = self._test_engine(
            'test_data/movies/ja/lobby/lobby_tag_2_matched.mp4',
           game_lang='ja',
        )

        assert engine.context['lobby']['type'] == 'tag'
        assert engine.context['lobby']['state'] == 'matched'
        assert engine.context['lobby']['team_members'] == 2

    def test_lobby_tag_4_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/ja/lobby/lobby_tag_4_matched.mp4',
           game_lang='ja',
        )

        assert engine.context['lobby']['type'] == 'tag'
        assert engine.context['lobby']['state'] == 'matched'
        assert engine.context['lobby']['team_members'] == 4

    def test_lobby_public_matching_to_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,
            'on_lobby_matching': 1,

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/ja/lobby/lobby_public_matching_to_matched.mp4',
           game_lang='ja',
        )

        assert engine.context['lobby']['type'] == 'public'
        assert engine.context['lobby']['state'] == 'matched'

    def test_lobby_fes_matching_to_matched(self):
        self.event_tickets = {
            # Events expected
            'on_lobby_matched': 1,
            'on_lobby_matching': None,  # フェスのマッチング中は未実装

            # Events don't care
            'on_debug_read_next_frame': None,
            'on_frame_read': None,
        }

        engine = self._test_engine(
            'test_data/movies/ja/lobby/lobby_fes_matching_to_matched.mp4',
           game_lang='ja',
        )

        assert engine.context['lobby']['type'] == 'festa'
        assert engine.context['lobby']['state'] == 'matched'