AnnouncementsMatrixEventsFunnyVideosMusicAncapsTechnologyEconomicsPrivacyGIFSCringeAnarchyFilmPicsThemesIdeas4MatrixAskMatrixHelpTop Subs
1
-module(catbox).
-export([init/0,upload/1,transfer/1,transfer_loop/0]).

-define(URL,"https://catbox.moe/user/api.php").
-define(USERAGENT,"depthbomb/node-catbox").
-define(Headers,[{<<"User-Agent">>,?USERAGENT}]).
-define(Options,[]).

init()->
 application:ensure_all_started(hackney).

formBody(Path)->
 PathBin = list_to_binary(Path),
 ReqTypePart = {<<"reqtype">>,<<"fileupload">>},
 %FilePart = {<<"fileToUpload">>,{file,Path}},
 FilePart = {file,PathBin,<<"fileToUpload">>,[]},
 Parts = [ReqTypePart,FilePart],
 Body = {multipart, Parts},
 Body.


upload(Path)->
 {ok, _ , _ , ClientRef} = hackney:post(?URL,?Headers,formBody(Path),?Options),
 {ok, Bin} = hackney:body(ClientRef),
 Result = binary_to_list(Bin),
 Result.

randpath()->"/tmp/"++binary_to_list(base64:encode(crypto:strong_rand_bytes(12)))++".mp4".

transfer(Url)->
 Tmp = randpath(),
 io:format("Temp path: ~p~n",[Tmp]),
 Cmd = "yt-dlp '"++Url++"' -o '"++Tmp++"'",
 io:format("Cmd: ~p~n",[Cmd]),
 os:cmd(Cmd),
 %io:format("Shell: ~p~n",[Shell]),
 NewURL = upload(Tmp),
 NewURL.
Comment preview