예제 #1
0
 def _start_workflow(self, workflow_cls, resource_id, *args, **kwargs):
     workflow_id = IdentityService.id_workflow(workflow_cls, resource_id)
     workflow = getattr(self._workflow_factory,
                        name_factory_method(workflow_cls))(workflow_id,
                                                           self._app_facade,
                                                           *args, **kwargs)
     return self._workflow_manager.start(workflow)
예제 #2
0
    async def queue(self, req):
        source = req.query["url"]
        video_id = IdentityService.id_video(source)
        playlist_id = self._player_repo.get_player().queue

        if self._source_service.is_playlist(source):
            collection_id = IdentityService.random()
            self._evt_dispatcher.dispatch(
                Notification(
                    collection_id,
                    NotifLevel.INFO,
                    "unfolding playlist",
                    {"source": source},
                ))

            loop = asyncio.get_running_loop()
            with ThreadPoolExecutor() as pool:
                sources = await loop.run_in_executor(
                    pool, partial(self._source_service.unfold, source))
                if not sources:
                    return self._internal_error(
                        "Could not unfold the playlist URL")

                self._evt_dispatcher.dispatch(
                    Notification(
                        collection_id,
                        NotifLevel.INFO,
                        "downloading playlist",
                        {
                            "source": source,
                            "count": f"{len(sources)} media"
                        },
                    ))
                videos = [
                    Video(IdentityService.id_video(source), source,
                          collection_id) for source in sources
                ]

                workflow_id = IdentityService.id_workflow(
                    QueuePlaylistWorkflow, video_id)
                self._start_workflow(
                    QueuePlaylistWorkflow,
                    workflow_id,
                    self._data_facade,
                    videos,
                    playlist_id,
                )
                return self._no_content()

        video = Video(video_id, source, collection_id=None)
        self._start_workflow(
            QueueVideoWorkflow,
            video_id,
            self._data_facade,
            video,
            playlist_id,
            queue_front=False,
        )

        return self._no_content()
예제 #3
0
    def setUp(self):
        self.evt_dispatcher = Mock()
        self.manager = WorkflowManager(self.evt_dispatcher)

        video_id = IdentityService.id_video("source")
        self.workflow = Mock()
        self.queue_workflow_id = IdentityService.id_workflow(
            QueueVideoWorkflow, video_id)
예제 #4
0
 def test_collecting_to_queueing_with_workflow_completed(self):
     (video_workflow, ) = self.expect_workflow_creation(VideoWorkflow)
     self.workflow.to_COLLECTING()
     video_workflow.start.assert_called_once()
     video_workflow_id = IdentityService.id_workflow(
         VideoWorkflow, self.video.id)
     self.raise_event(video_workflow.Completed, video_workflow_id,
                      self.workflow.video.id)
     self.assertTrue(self.workflow.is_QUEUEING())
예제 #5
0
 def test_collecting_to_aborted(self):
     (video_workflow, ) = self.expect_workflow_creation(VideoWorkflow)
     self.workflow.to_COLLECTING()
     video_workflow.start.assert_called_once()
     video_workflow_id = IdentityService.id_workflow(
         VideoWorkflow, self.video.id)
     self.raise_event(video_workflow.Aborted, video_workflow_id,
                      video_workflow.video.id)
     self.assertTrue(self.workflow.is_ABORTED())
예제 #6
0
 def test_queueing_to_synchronizing_with_video_workflow_completed(self):
     (queue_workflow, ) = self.expect_workflow_creation(QueueVideoWorkflow)
     self.workflow.to_QUEUEING()
     queue_workflow.start.assert_called_once()
     video_workflow_id = IdentityService.id_workflow(
         VideoWorkflow, self.video.id)
     self.raise_event(VideoWorkflow.Completed, video_workflow_id,
                      self.video.id)
     self.assertTrue(self.workflow.is_SYNCHRONIZING())
예제 #7
0
 def on_enter_STARTING(self, _):
     video = self.videos.pop()
     workflow_id = IdentityService.id_workflow(StreamVideoWorkflow, video.id)
     workflow = self._factory.make_stream_video_workflow(
         workflow_id, self._app_facade, self._data_facade, video, self.playlist_id
     )
     self._observe_start(
         workflow,
     )
예제 #8
0
 def test_collecting_to_removing(self):
     (video_workflow, ) = self.expect_workflow_creation(VideoWorkflow)
     self.workflow.to_COLLECTING()
     video_workflow.start.assert_called_once()
     self.player_playlist.ids = [self.video.id]
     video_workflow_id = IdentityService.id_workflow(
         VideoWorkflow, self.video.id)
     self.raise_event(video_workflow.Completed, video_workflow_id,
                      self.workflow.video.id)
     self.assertTrue(self.workflow.is_REMOVING())
예제 #9
0
    def on_enter_QUEUEING(self):
        queue_workflow_id = IdentityService.id_workflow(
            QueueVideoWorkflow, self.video.id
        )
        queue_workflow = self._factory.make_queue_video_workflow(
            queue_workflow_id,
            self._app_facade,
            self._data_facade,
            self.video,
            self.playlist_id,
            queue_front=True,
        )

        video_workflow_id = IdentityService.id_workflow(VideoWorkflow, self.video.id)
        self._observe(
            video_workflow_id,
            [VideoWorkflow.Completed],
        )
        self._observe_start(queue_workflow)
예제 #10
0
 def on_enter_QUEUEING(self, _):
     video = self.videos.pop()
     workflow_id = IdentityService.id_workflow(QueueVideoWorkflow, video.id)
     workflow = self._factory.make_queue_video_workflow(
         workflow_id,
         self._app_facade,
         self._data_facade,
         video,
         self.playlist_id,
         queue_front=False,
     )
     self._observe_start(workflow)
예제 #11
0
    def on_enter_COLLECTING(self):
        workflow_id = IdentityService.id_workflow(VideoWorkflow, self.video.id)
        workflow = self._factory.make_video_workflow(
            workflow_id, self._app_facade, self._data_facade, self.video
        )

        create_cmd_id = IdentityService.id_command(VideoCmd.CreateVideo, self.video.id)
        self._observe_group(
            {
                workflow_id: [workflow.Completed, workflow.Aborted],
                create_cmd_id: [VideoEvt.VideoCreated],
            },
        )
        self._start_workflow(workflow)