Fix file upload, cleanup

This commit is contained in:
Keroosha 2023-02-11 05:28:01 +03:00
parent 0f9b01568e
commit ae829d07d3
2 changed files with 6 additions and 3 deletions

View File

@ -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
}

View File

@ -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: