From 350943aa858b10279360d98f6eda980fd4f2b709 Mon Sep 17 00:00:00 2001 From: Keroosha Date: Tue, 7 Mar 2023 01:08:26 +0300 Subject: [PATCH 1/3] Change save path for YTDL service --- PublishHelperBot/Environment.fs | 1 + PublishHelperBot/Program.fs | 2 +- PublishHelperBot/YoutubeDl.fs | 11 ++++++----- PublishHelperBot/config.example.json | 3 ++- README.md | 3 ++- 5 files changed, 12 insertions(+), 8 deletions(-) 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 } ``` From c904d697be7319b92ee128b3fe8eff9565b97a98 Mon Sep 17 00:00:00 2001 From: Keroosha Date: Tue, 7 Mar 2023 02:26:44 +0300 Subject: [PATCH 2/3] Fix god damned poetry --- youtube-dl-api/poetry.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/youtube-dl-api/poetry.lock b/youtube-dl-api/poetry.lock index c2ddd92..16400ad 100644 --- a/youtube-dl-api/poetry.lock +++ b/youtube-dl-api/poetry.lock @@ -580,14 +580,14 @@ files = [ [[package]] name = "yt-dlp" -version = "2023.2.17" +version = "2023.3.4" description = "A youtube-dl fork with additional features and patches" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "yt-dlp-2023.2.17.tar.gz", hash = "sha256:9af92de5effc193bdb51216d9ebf28874d96180d202fae752b0d9f2a63380f3a"}, - {file = "yt_dlp-2023.2.17-py2.py3-none-any.whl", hash = "sha256:3b2df037c80922f0f83f63ee2f9253496b4a8668c0fe8d2a836ba9040f853b07"}, + {file = "yt-dlp-2023.3.4.tar.gz", hash = "sha256:265d5da97a76c15d7d9a4088a67b78acd5dcf6f8cfd8257c52f581ff996ff515"}, + {file = "yt_dlp-2023.3.4-py2.py3-none-any.whl", hash = "sha256:40ca421407ce07c8fd700854fd978d58526ec6fff3468caa34ff1c7333b8dc34"}, ] [package.dependencies] @@ -600,5 +600,5 @@ websockets = "*" [metadata] lock-version = "2.0" -python-versions = "^3.10" -content-hash = "51ec164c892a17017f004b82d07fc561a863fbe4859baff2482a44b5776f6494" +python-versions = "3.10.9" +content-hash = "a8eccae921b6740e35b430b05e2f972b6c891474517e84bf86e12728318fefd5" From 8ace6ca157365790d5f5c8f44bef4f41cf54db50 Mon Sep 17 00:00:00 2001 From: Keroosha Date: Tue, 7 Mar 2023 02:46:50 +0300 Subject: [PATCH 3/3] Fix docker i guess?!? --- PublishHelperBot/Program.fs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/PublishHelperBot/Program.fs b/PublishHelperBot/Program.fs index 0945c08..5f3f9e2 100644 --- a/PublishHelperBot/Program.fs +++ b/PublishHelperBot/Program.fs @@ -1,5 +1,6 @@ open System open System.Net.Http +open System.Threading open System.Threading.Tasks open PublishHelperBot.Environment open PublishHelperBot.YoutubeDl @@ -9,8 +10,8 @@ open Telegram.Bot.Polling open Telegram.Bot.Types open Telegram.Bot.Types.Enums +let cancellation = new CancellationTokenSource() let config = createConfig "SBPB_CONFIG_PATH" - let botClient = TelegramBotClient (config.token, new HttpClient()) let youtubeDlClient = @@ -56,5 +57,9 @@ botClient.StartReceiving( ) Logging.logger.Information("Я родился") - -Console.ReadKey() |> ignore \ No newline at end of file +Console.CancelKeyPress |> Event.add (fun _ -> cancellation.Cancel(); printfn "Сворачиваемся...") +Async.RunSynchronously( + async { + while (not(cancellation.Token.IsCancellationRequested)) do + do! Async.Sleep 500 |> Async.Ignore + }) \ No newline at end of file