diff --git a/PublishHelperBot/Environment.fs b/PublishHelperBot/Environment.fs index 0d90841..9fd8757 100644 --- a/PublishHelperBot/Environment.fs +++ b/PublishHelperBot/Environment.fs @@ -17,6 +17,7 @@ type public BotConfig = { chanelId: int64 adminChatId: int64 youtubeDlUrl: string + tmpYtdlSavePath: string Option } let private readConfig = diff --git a/PublishHelperBot/Program.fs b/PublishHelperBot/Program.fs index b199c0c..0945c08 100644 --- a/PublishHelperBot/Program.fs +++ b/PublishHelperBot/Program.fs @@ -28,7 +28,7 @@ let tgService = } let youtubeDlService = - YoutubeDlService.createService youtubeDlClient tgService + YoutubeDlService.createService youtubeDlClient tgService (config.tmpYtdlSavePath |> Option.defaultValue "/tmp") let isObsoleteUpdate = let startDate = DateTime.UtcNow diff --git a/PublishHelperBot/YoutubeDl.fs b/PublishHelperBot/YoutubeDl.fs index 7303d49..b10ae64 100644 --- a/PublishHelperBot/YoutubeDl.fs +++ b/PublishHelperBot/YoutubeDl.fs @@ -163,7 +163,7 @@ module YoutubeDlClient = [] module YoutubeDlService = type private Msg = - | AddJob of url: string * TaskCompletionSource + | AddJob of url: string * savePath: string * TaskCompletionSource | CheckJob type private JobState = @@ -235,14 +235,15 @@ module YoutubeDlService = (current: YoutubeDlJob option) = async { match! inbox.Receive() with - | AddJob (url, tcs) -> + | AddJob (url, savePath, tcs) -> Logging.logger.Information("Adding new url = {url}", url) let id = Guid.NewGuid() + let fullSavePath = $"{Path.Combine(savePath, Path.GetRandomFileName())}.mp4" let job = { InternalId = id State = Created Url = url - SavePath = $"{Path.GetTempFileName()}.mp4" + SavePath = fullSavePath } tcs.SetResult(id) jobQueue.Enqueue(job) @@ -315,10 +316,10 @@ module YoutubeDlService = loop (Queue()) None ) - let createService youtubeDlClient tgService = + let createService youtubeDlClient tgService (savePath: string) = let inbox = createServiceInbox youtubeDlClient tgService { new IYoutubeDlService with member this.AddJob(url) = let tcs = TaskCompletionSource<_>() - inbox.Post(AddJob(url, tcs)) + inbox.Post(AddJob(url, savePath, tcs)) tcs.Task |> Async.AwaitTask } \ No newline at end of file diff --git a/PublishHelperBot/config.example.json b/PublishHelperBot/config.example.json index afa1315..b2d650b 100644 --- a/PublishHelperBot/config.example.json +++ b/PublishHelperBot/config.example.json @@ -3,5 +3,6 @@ "chanelId": "123123123", "adminChatId": "123123123", "relayUrl": "https://t.me/pokupkabitka_bot", - "youtubeDlUrl": "http://localhost:8000/" + "youtubeDlUrl": "http://localhost:8000/", + "tmpYtdlSavePath": "/tmp" } \ No newline at end of file diff --git a/README.md b/README.md index da00b5f..8608a32 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ cd PublishHelperBot && dotnet restore "chanelId": "123123123", // Канал куда постить "adminChatId": "123123123", // Чат откуда будут слушаться команды "relayUrl": "https://t.me/pokupkabitka_bot", // ссылка на бота предложки (Нужно команде /post) - "youtubeDlUrl": "http://localhost:8000/" // апишка для скачивания видосиков + "youtubeDlUrl": "http://localhost:8000/", // апишка для скачивания видосиков + "tmpYtdlSavePath": "/tmp" // Промежуточное хранилище для YTDL } ```