From ae829d07d31a88c5d966677d66ab9749431dc4e0 Mon Sep 17 00:00:00 2001 From: Keroosha Date: Sat, 11 Feb 2023 05:28:01 +0300 Subject: [PATCH] Fix file upload, cleanup --- PublishHelperBot/YoutubeDl.fs | 5 +++-- youtube-dl-api/youtube_dl_api/__init__.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/PublishHelperBot/YoutubeDl.fs b/PublishHelperBot/YoutubeDl.fs index a9023a3..fb91dfa 100644 --- a/PublishHelperBot/YoutubeDl.fs +++ b/PublishHelperBot/YoutubeDl.fs @@ -113,7 +113,7 @@ type YoutubeDlBackgroundService(requirements: StartYoutubeDlServiceArgs) = savePath = job.savePath } let attachExternalId (id: Guid, job: YoutubeDlJobWithoutId): YoutubeDlCurrentJob = - Awaiting { internalId = job.internalId; state = job.state; url = job.state; externalId = id; savePath = job.savePath } + Awaiting { internalId = job.internalId; state = job.state; url = job.url; externalId = id; savePath = job.savePath } let tryAssignNewJob() = async { let (result, job) = jobPool.TryDequeue() @@ -147,6 +147,7 @@ type YoutubeDlBackgroundService(requirements: StartYoutubeDlServiceArgs) = } let cleanUp(job: YoutubeDlJobWithId) = async { + File.Delete <| job.savePath match! ytClient.CleanJob <| job.externalId with | Ok _ -> currentJob <- None () | Error _ -> currentJob <- None () @@ -171,6 +172,6 @@ type YoutubeDlBackgroundService(requirements: StartYoutubeDlServiceArgs) = member public this.StartYoutubeDlService() = loop() |> Async.Start member public this.EnqueueJob(url: string) = lock async { let id = Guid.NewGuid() - jobPool.Enqueue({ internalId = id; externalId = (); state = "new"; url = url; savePath = Path.GetTempFileName() }) + jobPool.Enqueue({ internalId = id; externalId = (); state = "new"; url = url; savePath = $"{Path.GetTempFileName()}.mp4" }) return id } \ No newline at end of file diff --git a/youtube-dl-api/youtube_dl_api/__init__.py b/youtube-dl-api/youtube_dl_api/__init__.py index 3524630..0189496 100644 --- a/youtube-dl-api/youtube_dl_api/__init__.py +++ b/youtube-dl-api/youtube_dl_api/__init__.py @@ -21,7 +21,9 @@ def report_state(id: str): def load_video(url: str, file_path: str, id: str): opts = { - "forcefilename": file_path, + "format": 'mp4', + "quiet": True, + "outtmpl": file_path, "progress_hooks": [report_state(id)] } with YoutubeDL(opts) as ydl: