33 Commits

Author SHA1 Message Date
VC
66f288c069 feat: add --vice option 2023-10-25 15:33:10 +02:00
VC
b208daa0ea Merge branch 'feat/remove_max_dl' into 'master'
Refactor: remove get_max_resolution_dl

See merge request veretcle/tootube!15
2023-10-19 09:19:02 +00:00
VC
f3ad81716d refactor: remove get_max_resolution_dl (ord makes it redundant) 2023-10-19 11:12:16 +02:00
VC
f18ce899aa chore: bump version + update dep 2023-10-19 11:01:14 +02:00
VC
bf0b1c4e3f Merge branch 'refactor_dl_url' into 'master'
refactor: regroup now_kiss and get_dl_video_stream functions

See merge request veretcle/tootube!14
2023-10-17 11:57:48 +00:00
VC
eb398a880a refactor: regroup now_kiss and get_dl_video_stream functions 2023-10-17 13:55:03 +02:00
VC
1db91ec3dc Merge branch '3-progress-bar-on-the-upload-download-code-portion' into 'master'
Progress bar on the upload/download code portion

Closes #3

See merge request veretcle/tootube!13
2023-10-17 07:47:09 +00:00
VC
1d4ae8f152 feat: add progress bar to the transferring process 2023-10-17 09:33:38 +02:00
VC
58f36a56f7 chore: bump version + add indicatif/async-stream 2023-10-17 09:25:12 +02:00
VC
e17ba6cf7e Merge branch '2-tootube-should-log-moar' into 'master'
Resolve "Tootube should log moar"

Closes #2

See merge request veretcle/tootube!12
2023-10-16 19:39:00 +00:00
VC
3d53ad7bbd doc: update documentation 2023-10-16 21:36:41 +02:00
VC
3f482ff258 feat: add relevant debug bits 2023-10-16 21:23:29 +02:00
VC
ae3fa74d9b chore: bump version 2023-10-16 21:23:15 +02:00
VC
62641f526f refactor: add Ord/PartialOrd/PartialEq for PeerTubeVideoStreamingPlaylistsFiles struct 2023-10-16 21:22:47 +02:00
VC
d83985394c Merge branch 'feat_pl' into 'master'
feat: add the newly added video to playlists if any

Closes #1

See merge request veretcle/tootube!11
2023-10-15 08:23:55 +00:00
VC
ebc42f915d feat: add the newly added video to playlists if any 2023-10-15 00:06:16 +02:00
VC
8d4d683f55 Merge branch 'wtf' into 'master'
feat: add reqwest multipart feature

See merge request veretcle/tootube!10
2023-10-14 17:30:11 +00:00
VC
2b508e90c1 feat: add reqwest multipart feature 2023-10-14 19:28:49 +02:00
VC
3482456adb Merge branch 'register_function' into 'master'
feat: add register command

See merge request veretcle/tootube!9
2023-10-14 17:22:17 +00:00
VC
568ca00d98 feat: add register command 2023-10-14 19:20:53 +02:00
VC
7fda7069a9 Merge branch 'revert-9ca27a26' into 'master'
Revert "Merge branch 'register_function' into 'master'"

See merge request veretcle/tootube!8
2023-10-14 17:16:47 +00:00
VC
3d9ebcc2a5 Revert "Merge branch 'register_function' into 'master'"
This reverts merge request !7
2023-10-14 17:15:34 +00:00
VC
9ca27a262f Merge branch 'register_function' into 'master'
Register function

See merge request veretcle/tootube!7
2023-10-14 17:14:14 +00:00
VC
d39c78c197 feat: add register command 2023-10-14 19:12:36 +02:00
VC
6867882ca0 doc: add registration documentation + update general documentation 2023-10-14 19:11:34 +02:00
VC
a00753b9eb feat: add multipart reqwest feature 2023-10-14 19:10:21 +02:00
VC
8a9a365a04 chore: update version 2023-10-14 18:17:11 +02:00
VC
4a47eb1d08 chore: cargo update 2023-10-14 18:16:20 +02:00
VC
1bdd747202 Merge branch 'feat_cargo_update+style' into 'master'
Feat cargo update+style

See merge request veretcle/tootube!6
2023-10-11 06:40:34 +00:00
VC
0640c4c263 style: regroup 'use' 2023-10-10 21:13:40 +02:00
VC
59ad8994b1 chore: cargo update 2023-10-10 21:09:10 +02:00
VC
f1d05e9785 Merge branch 'rev0-2' into 'master'
feat: async + stream

See merge request veretcle/tootube!5
2023-10-09 12:09:38 +00:00
VC
0451543d6d feat: async + stream 2023-10-09 13:07:03 +02:00
8 changed files with 806 additions and 249 deletions

450
Cargo.lock generated
View File

@@ -19,18 +19,18 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.1"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.1"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6cd65a4b849ace0b7f6daeebcc1a1d111282227ca745458c61dbf670e52a597"
checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
dependencies = [
"anstyle",
"anstyle-parse",
@@ -61,17 +61,39 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.0"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0238ca56c96dfa37bdf7c373c8886dd591322500aceeeccdb2216fe06dc2f796"
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
dependencies = [
"anstyle",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
name = "async-stream"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51"
dependencies = [
"async-stream-impl",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-stream-impl"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
@@ -109,9 +131,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bumpalo"
@@ -173,6 +195,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "console"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"unicode-width",
"windows-sys 0.45.0",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@@ -189,6 +224,12 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "encoding_rs"
version = "0.8.33"
@@ -213,23 +254,12 @@ dependencies = [
[[package]]
name = "errno"
version = "0.3.3"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd"
checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860"
dependencies = [
"errno-dragonfly",
"libc",
"windows-sys",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
"windows-sys 0.48.0",
]
[[package]]
@@ -289,6 +319,17 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
[[package]]
name = "futures-macro"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.28"
@@ -309,6 +350,8 @@ checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
dependencies = [
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
@@ -349,9 +392,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hermit-abi"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
[[package]]
name = "http"
@@ -450,6 +493,28 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "indicatif"
version = "0.17.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb28741c9db9a713d93deb3bb9515c20788cef5815265bee4980e87bde7e0f25"
dependencies = [
"console",
"instant",
"number_prefix",
"portable-atomic",
"unicode-width",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "ipnet"
version = "2.8.0"
@@ -464,7 +529,7 @@ checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi",
"rustix",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@@ -490,15 +555,25 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.148"
version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "linux-raw-sys"
version = "0.4.7"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128"
checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
@@ -508,9 +583,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.3"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "mime"
@@ -518,6 +593,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "miniz_oxide"
version = "0.7.1"
@@ -535,7 +620,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [
"libc",
"wasi",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@@ -566,6 +651,12 @@ dependencies = [
"libc",
]
[[package]]
name = "number_prefix"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "object"
version = "0.32.1"
@@ -587,7 +678,7 @@ version = "0.10.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"cfg-if",
"foreign-types",
"libc",
@@ -625,6 +716,29 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.4.1",
"smallvec",
"windows-targets 0.48.5",
]
[[package]]
name = "percent-encoding"
version = "2.3.0"
@@ -650,10 +764,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "proc-macro2"
version = "1.0.67"
name = "portable-atomic"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
checksum = "31114a898e107c51bb1609ffaf55a0e011cf6a4d7f1170d0015a165082c0338b"
[[package]]
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
@@ -677,10 +797,19 @@ dependencies = [
]
[[package]]
name = "regex"
version = "1.9.6"
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "regex"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
@@ -690,9 +819,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.3.9"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
@@ -701,15 +830,15 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.7.5"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "reqwest"
version = "0.11.20"
version = "0.11.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1"
checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
dependencies = [
"base64",
"bytes",
@@ -725,6 +854,7 @@ dependencies = [
"js-sys",
"log",
"mime",
"mime_guess",
"native-tls",
"once_cell",
"percent-encoding",
@@ -732,12 +862,15 @@ dependencies = [
"serde",
"serde_json",
"serde_urlencoded",
"system-configuration",
"tokio",
"tokio-native-tls",
"tokio-util",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"winreg",
]
@@ -750,15 +883,15 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustix"
version = "0.38.14"
version = "0.38.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f"
checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@@ -773,9 +906,15 @@ version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88"
dependencies = [
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "security-framework"
version = "2.9.2"
@@ -801,18 +940,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
dependencies = [
"proc-macro2",
"quote",
@@ -842,6 +981,15 @@ dependencies = [
"serde",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.9"
@@ -851,6 +999,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "socket2"
version = "0.4.9"
@@ -868,7 +1022,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e"
dependencies = [
"libc",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@@ -879,15 +1033,36 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "2.0.37"
version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "system-configuration"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "tempfile"
version = "3.8.0"
@@ -896,9 +1071,9 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"redox_syscall 0.3.5",
"rustix",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@@ -927,18 +1102,32 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.32.0"
version = "1.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9"
checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.5.4",
"windows-sys",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
@@ -976,13 +1165,17 @@ dependencies = [
[[package]]
name = "tootube"
version = "0.2.0"
version = "0.5.3"
dependencies = [
"async-stream",
"clap",
"env_logger",
"futures-util",
"indicatif",
"log",
"reqwest",
"serde",
"tokio",
"toml",
]
@@ -994,20 +1187,19 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
[[package]]
name = "tracing"
version = "0.1.37"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
]
@@ -1018,6 +1210,15 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.13"
@@ -1039,6 +1240,12 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "url"
version = "2.4.1"
@@ -1062,6 +1269,12 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "want"
version = "0.3.1"
@@ -1143,6 +1356,19 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "wasm-streams"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4609d447824375f43e1ffbc051b50ad8f4b3ae8219680c94452ea05eb240ac7"
dependencies = [
"futures-util",
"js-sys",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "web-sys"
version = "0.3.64"
@@ -1184,13 +1410,37 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
@@ -1199,51 +1449,93 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
@@ -1257,5 +1549,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
"windows-sys",
"windows-sys 0.48.0",
]

View File

@@ -1,18 +1,22 @@
[package]
name = "tootube"
authors = ["VC <veretcle+framagit@mateu.be>"]
version = "0.2.0"
version = "0.5.3"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "^0.11", features = ["blocking", "json"] }
reqwest = { version = "^0.11", features = ["json", "stream", "multipart"] }
tokio = { version = "^1", features = ["full"] }
clap = "^4"
serde = { version = "1.0", features = ["derive"] }
serde = { version = "^1", features = ["derive"] }
toml = "^0.5"
log = "^0.4"
env_logger = "^0.10"
indicatif = "^0.17"
async-stream = "^0.3"
futures-util = "^0.3"
[profile.release]
strip = true

View File

@@ -6,50 +6,57 @@ This program takes the very last video published on a PeerTube instance and push
This is an early prototype not really suited for production purposes for now:
* it still relies way too much on pre-determined value to upload the video to YouTube
* it cannot determine the playlists it needs to put them in
* it cannot determine the recording date (believe me, I tried!)
* there are still a lot of static values that I would rather not have static (like the cache directory…)
* it is 100% sync, meaning its clearly not optimal for now and probably wont be for the next releases
So consider this a work in progress that will slowly get better with time
So consider this a work in progress that will slowly get better with time.
# What does it do exactly?
* it downloads the latest PeerTube video from an instance
* stores it in cache directory
* uploads it to YouTube
* it retrieves the latest PeerTube video download URL from an instance
* it creates a resumable upload into the target YouTube account
* it downloads/uploads the latest PeerTube video to YouTube without using a cache (stream-to-stream)
# What doesnt it do exactly?
* it cannot register the original key (see below)
* it relies on a local cache despite the fact that it might well be possible to just download from PT/upload to YT at the same time (I dont see why not in fact)
* it doesnt retrieve ALL the original PeerTube video properties like licences, languages, categories, etc… again: early prototype
# Obtain Authorization Token from Google
# Howtos
## General usage
That the complicated part:
* create an OAuth2.0 application with authorization for Youtube DATA Api v3 Upload
Once you fill your `tootube.toml` config file (see below), you can run `tootube` like this:
```bash
tootube --config tootube.toml --playlist playlist_1 "Things You Might Like"
```
You can turn on debug using env var `RUST_LOG`.
## Obtain Authorization Token from Google
The complicated part:
* create an OAuth2.0 application with authorization for Youtube DATA Api v3 Upload and Youtube DATA Api v3 (generally referenced as `../auth/youtube.upload` and `../auth/youtube`)
* create a OAuth2.0 client with Desktop client
Youll need:
* the `client_id` from your OAuth2.0 client
* the `client_secret` from you OAuth2.0 client
Then enter in:
Create your `tootube.toml` config file:
```
https://accounts.google.com/o/oauth2/v2/auth?client_id=XXX.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/youtube.upload&response_type=code
```toml
[peertube]
base_url="https://p.nintendojo.fr"
[youtube]
refresh_token="" # leave empty for now
client_id="<YOUR CLIENT_ID>"
client_secret="<YOUR CLIENT_SECRET>"
```
And accept that your YouTube account might be modified. Youll get a code then; enter this `curl` post:
Then run:
```
curl -s \
--request POST \
--data "code=[THE_CODE]&client_id=XXX.apps.googleusercontent.com&client_secret=[THE_CLIENT_SECRET]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token
```bash
tootube register --config <PATH TO YOUR TOOTUBE.TOML FILE>
```
Youll get a Token. The only important part is the `refresh_token`
In your `tootube.toml` config file, put the `refresh_token`.
Youll be then prompted with all the necessary information to register `tootube`. Youll end with a `refresh_token` that you can now paste inside your tootube configuration.

View File

@@ -1,12 +1,13 @@
use std::fs::read_to_string;
use serde::Deserialize;
use std::fs::read_to_string;
// General configuration Struct
#[derive(Debug, Deserialize)]
pub struct Config {
pub peertube: PeertubeConfig,
pub youtube: YoutubeConfig,
#[serde(default)]
pub tootube: TootubeConfig,
}
#[derive(Debug, Deserialize)]
@@ -21,6 +22,21 @@ pub struct YoutubeConfig {
pub client_secret: String,
}
#[derive(Debug, Deserialize)]
pub struct TootubeConfig {
pub progress_bar: String,
pub progress_chars: String,
}
impl Default for TootubeConfig {
fn default() -> Self {
TootubeConfig {
progress_bar: "{msg}\n{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})".to_string(),
progress_chars: "#>-".to_string(),
}
}
}
/// Parses the TOML file into a Config struct
pub fn parse_toml(toml_file: &str) -> Config {
let toml_config =

View File

@@ -1,74 +1,54 @@
use std::{
error::Error,
fs::create_dir_all,
fs::{remove_file, File},
};
use reqwest::Url;
use log::debug;
mod error;
use error::TootubeError;
mod config;
pub use config::parse_toml;
use config::Config;
mod peertube;
use peertube::{get_latest_video, get_max_resolution_dl};
use peertube::get_latest_video;
mod youtube;
use youtube::{create_resumable_upload, upload_video};
pub use youtube::register;
use youtube::{add_video_to_playlists, create_resumable_upload, now_kiss};
const TMP_DIR: &str = "/tmp/tootube";
fn dl_video(u: &str) -> Result<String, Box<dyn Error>> {
// create dir
create_dir_all(TMP_DIR)?;
// get file
let mut response = reqwest::blocking::get(u)?;
// create local file
let url = Url::parse(u)?;
let dest_filename = url
.path_segments()
.ok_or_else(|| {
TootubeError::new(&format!(
"Cannot determine the destination filename for {u}"
))
})?
.last()
.ok_or_else(|| {
TootubeError::new(&format!(
"Cannot determine the destination filename for {u}"
))
})?;
let dest_filepath = format!("{TMP_DIR}/{dest_filename}");
let mut dest_file = File::create(&dest_filepath)?;
response.copy_to(&mut dest_file)?;
Ok(dest_filepath)
}
pub fn run(config: Config) {
#[tokio::main]
pub async fn run(config: Config, pl: Vec<String>) {
// Get the latest video object
let latest_vid = get_latest_video(&config.peertube.base_url).unwrap_or_else(|e| {
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
});
let latest_vid = get_latest_video(&config.peertube.base_url)
.await
.unwrap_or_else(|e| {
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
});
let dl_url = get_max_resolution_dl(latest_vid.streaming_playlists.as_ref().unwrap());
let local_path = dl_video(&dl_url)
.unwrap_or_else(|e| panic!("Cannot download video at URL {}: {}", dl_url, e));
let dl_url = latest_vid.streaming_playlists.as_ref().unwrap()[0]
.files
.iter()
.max()
.unwrap()
.file_download_url
.clone();
debug!("PT download URL: {}", &dl_url);
let resumable_upload_url = create_resumable_upload(&config.youtube, &latest_vid)
.await
.unwrap_or_else(|e| panic!("Cannot retrieve the uploads resumable id: {e}"));
debug!("YT upload URL: {}", &resumable_upload_url);
upload_video(&local_path, &resumable_upload_url, &config.youtube)
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
let yt_video_id = now_kiss(
&dl_url,
&resumable_upload_url,
&config.youtube,
&config.tootube,
)
.await
.unwrap_or_else(|e| panic!("Cannot resume upload!: {e}"));
debug!("YT video ID: {}", &yt_video_id);
remove_file(&local_path).unwrap_or_else(|e| panic!("Cannot delete file {}: {}", local_path, e));
if !pl.is_empty() {
add_video_to_playlists(&config.youtube, &yt_video_id, &pl)
.await
.unwrap_or_else(|e| panic!("Cannot add video to playlist(s): {e}"));
}
}

View File

@@ -17,11 +17,61 @@ fn main() {
.default_value(DEFAULT_CONFIG_PATH)
.display_order(1),
)
.arg(
Arg::new("playlists")
.short('p')
.long("playlist")
.value_name("PLAYLIST")
.help("List of playlists to add the video to")
.num_args(0..)
.display_order(2),
)
.arg(
Arg::new("vice")
.long("vice")
.alias("chybrare")
.alias("coquinou")
.action(clap::ArgAction::SetTrue)
.display_order(3),
)
.subcommand(
Command::new("register")
.version(env!("CARGO_PKG_VERSION"))
.about("Command to register to YouTube OAuth2.0")
.arg(
Arg::new("config")
.short('c')
.long("config")
.value_name("CONFIG_FILE")
.help("TOML config file for tootube")
.num_args(1)
.default_value(DEFAULT_CONFIG_PATH)
.display_order(1),
),
)
.get_matches();
let config = parse_toml(matches.get_one::<String>("config").unwrap());
if let Some(("register", sub_m)) = matches.subcommand() {
let config = parse_toml(sub_m.get_one::<String>("config").unwrap());
register(&config.youtube)
.unwrap_or_else(|e| panic!("Cannot register to YouTube API: {}", e));
return;
}
let mut config = parse_toml(matches.get_one::<String>("config").unwrap());
if matches.get_flag("vice") {
config.tootube.progress_bar = "{msg}\n[{elapsed_precise}] 8{wide_bar:.magenta}ᗺ {bytes}/{total_bytes} ({bytes_per_sec}, {eta})".to_string();
config.tootube.progress_chars = "=D ".to_string();
}
let playlists: Vec<String> = matches
.get_many::<String>("playlists")
.unwrap_or_default()
.map(|v| v.to_string())
.collect();
env_logger::init();
run(config);
run(config, playlists);
}

View File

@@ -1,5 +1,5 @@
use serde::Deserialize;
use std::{boxed::Box, error::Error};
use std::{boxed::Box, cmp::Ordering, error::Error};
#[derive(Debug, Deserialize)]
pub struct PeerTubeVideos {
@@ -22,7 +22,7 @@ pub struct PeerTubeVideoStreamingPlaylists {
pub files: Vec<PeerTubeVideoStreamingPlaylistsFiles>,
}
#[derive(Debug, Deserialize)]
#[derive(Eq, Debug, Deserialize)]
pub struct PeerTubeVideoStreamingPlaylistsFiles {
pub id: u64,
pub resolution: PeerTubeVideoStreamingPlaylistsFilesResolution,
@@ -30,71 +30,47 @@ pub struct PeerTubeVideoStreamingPlaylistsFiles {
pub file_download_url: String,
}
#[derive(Debug, Deserialize)]
impl Ord for PeerTubeVideoStreamingPlaylistsFiles {
fn cmp(&self, other: &Self) -> Ordering {
self.resolution.id.cmp(&other.resolution.id)
}
}
impl PartialOrd for PeerTubeVideoStreamingPlaylistsFiles {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for PeerTubeVideoStreamingPlaylistsFiles {
fn eq(&self, other: &Self) -> bool {
self.resolution.id == other.resolution.id
}
}
#[derive(Eq, Debug, Deserialize, PartialEq)]
pub struct PeerTubeVideoStreamingPlaylistsFilesResolution {
pub id: u16,
}
/// This gets the last video uploaded to the PeerTube server
pub fn get_latest_video(u: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
let body = reqwest::blocking::get(format!("{}/api/v1/videos?count=1&sort=-publishedAt", u))?
.json::<PeerTubeVideos>()?;
pub async fn get_latest_video(u: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
let body = reqwest::get(format!("{}/api/v1/videos?count=1&sort=-publishedAt", u))
.await?
.json::<PeerTubeVideos>()
.await?;
let vid = get_video_detail(u, &body.data[0].uuid)?;
let vid = get_video_detail(u, &body.data[0].uuid).await?;
Ok(vid)
}
/// This returns the direct download URL for with the maximum resolution
pub fn get_max_resolution_dl(p: &[PeerTubeVideoStreamingPlaylists]) -> String {
let mut res = 0;
let mut dl_url = String::new();
for i in p[0].files.iter() {
if i.resolution.id > res {
res = i.resolution.id;
dl_url = i.file_download_url.clone();
}
}
dl_url
}
/// This gets all the crispy details about one particular video
fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
let body =
reqwest::blocking::get(format!("{}/api/v1/videos/{}", u, v))?.json::<PeerTubeVideo>()?;
async fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
let body = reqwest::get(format!("{}/api/v1/videos/{}", u, v))
.await?
.json::<PeerTubeVideo>()
.await?;
Ok(body)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_max_resolution_dl() {
let str_plist: Vec<PeerTubeVideoStreamingPlaylists> =
vec![PeerTubeVideoStreamingPlaylists {
files: vec![
PeerTubeVideoStreamingPlaylistsFiles {
id: 1025,
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 990 },
file_download_url: "meh!".to_string(),
},
PeerTubeVideoStreamingPlaylistsFiles {
id: 1027,
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 1720 },
file_download_url: "blah".to_string(),
},
PeerTubeVideoStreamingPlaylistsFiles {
id: 1026,
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 360 },
file_download_url: "nope".to_string(),
},
],
}];
assert_eq!("blah".to_string(), get_max_resolution_dl(&str_plist));
}
}

View File

@@ -1,8 +1,18 @@
use crate::{config::YoutubeConfig, error::TootubeError, peertube::PeerTubeVideo};
use crate::{
config::{TootubeConfig, YoutubeConfig},
error::TootubeError,
peertube::PeerTubeVideo,
};
use async_stream::stream;
use futures_util::StreamExt;
use indicatif::{ProgressBar, ProgressStyle};
use log::debug;
use reqwest::{multipart::Form, Body, Client};
use serde::{Deserialize, Serialize};
use std::{error::Error, fs::File, sync::Mutex};
use std::{cmp::min, error::Error, io::stdin};
use tokio::sync::OnceCell;
static ACCESS_TOKEN: Mutex<String> = Mutex::new(String::new());
static ACCESS_TOKEN: OnceCell<String> = OnceCell::const_new();
#[derive(Serialize, Debug)]
struct RefreshTokenRequest {
@@ -30,6 +40,11 @@ struct AccessTokenResponse {
access_token: String,
}
#[derive(Deserialize, Debug)]
struct RegistrationAccessTokenResponse {
refresh_token: String,
}
#[derive(Serialize, Debug)]
struct YoutubeUploadParams {
snippet: YoutubeUploadParamsSnippet,
@@ -78,10 +93,110 @@ impl Default for YoutubeUploadParamsStatus {
}
}
#[derive(Serialize, Debug)]
struct YoutubePlaylistItemsParams {
snippet: YoutubePlaylistItemsParamsSnippet,
}
#[derive(Serialize, Debug)]
struct YoutubePlaylistItemsParamsSnippet {
#[serde(rename = "playlistId")]
playlist_id: String,
position: u16,
#[serde(rename = "resourceId")]
resource_id: YoutubePlaylistItemsParamsSnippetResourceId,
}
impl Default for YoutubePlaylistItemsParamsSnippet {
fn default() -> Self {
YoutubePlaylistItemsParamsSnippet {
playlist_id: "".to_string(),
position: 0,
resource_id: YoutubePlaylistItemsParamsSnippetResourceId {
..Default::default()
},
}
}
}
#[derive(Serialize, Debug)]
struct YoutubePlaylistItemsParamsSnippetResourceId {
kind: String,
#[serde(rename = "videoId")]
video_id: String,
}
impl Default for YoutubePlaylistItemsParamsSnippetResourceId {
fn default() -> Self {
YoutubePlaylistItemsParamsSnippetResourceId {
kind: "youtube#video".to_string(),
video_id: "".to_string(),
}
}
}
#[derive(Deserialize, Debug)]
struct YoutubeVideos {
id: String,
}
#[derive(Deserialize, Debug)]
struct YoutubePlaylistListResponse {
#[serde(rename = "nextPageToken")]
next_page_token: Option<String>,
items: Vec<YoutubePlaylistListResponseItem>,
}
#[derive(Deserialize, Debug)]
struct YoutubePlaylistListResponseItem {
id: String,
snippet: YoutubePlaylistListResponseItemSnippet,
}
#[derive(Deserialize, Debug)]
struct YoutubePlaylistListResponseItemSnippet {
title: String,
}
/// This function makes the registration process a little bit easier
#[tokio::main]
pub async fn register(config: &YoutubeConfig) -> Result<(), Box<dyn Error>> {
println!("Click on the link below to authorize {} to upload to YouTube and deal with your playlists:", env!("CARGO_PKG_NAME"));
println!("https://accounts.google.com/o/oauth2/v2/auth?client_id={}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/youtube%20https://www.googleapis.com/auth/youtube.upload&response_type=code", config.client_id);
println!("Paste the returned authorization code:");
let mut input = String::new();
stdin()
.read_line(&mut input)
.expect("Unable to read back the authorization code!");
let form = Form::new()
.text("code", input)
.text("client_id", config.client_id.clone())
.text("client_secret", config.client_secret.clone())
.text("redirect_uri", "urn:ietf:wg:oauth:2.0:oob")
.text("grant_type", "authorization_code");
let client = Client::new();
let res = client
.post("https://accounts.google.com/o/oauth2/token")
.multipart(form)
.send()
.await?;
let refresh_token: RegistrationAccessTokenResponse = res.json().await?;
println!("You can now paste the following line inside the `youtube` section of your tootube.toml file:");
println!("refresh_token=\"{}\"", refresh_token.refresh_token);
Ok(())
}
/// Ensures that Token has been refreshed and that it is unique
fn refresh_token(config: &YoutubeConfig) -> Result<String, Box<dyn Error>> {
if let Ok(mut unlocked_access_token) = ACCESS_TOKEN.lock() {
if unlocked_access_token.is_empty() {
async fn refresh_token(config: &YoutubeConfig) -> Result<String, reqwest::Error> {
ACCESS_TOKEN
.get_or_try_init(|| async {
let refresh_token = RefreshTokenRequest {
refresh_token: config.refresh_token.clone(),
client_id: config.client_id.clone(),
@@ -89,26 +204,110 @@ fn refresh_token(config: &YoutubeConfig) -> Result<String, Box<dyn Error>> {
..Default::default()
};
let client = reqwest::blocking::Client::new();
let client = Client::new();
let res = client
.post("https://accounts.google.com/o/oauth2/token")
.json(&refresh_token)
.send()?;
.send()
.await?;
let access_token: AccessTokenResponse = res.json()?;
let access_token: AccessTokenResponse = res.json().await?;
*unlocked_access_token = access_token.access_token.clone();
debug!("YT Access Token: {}", &access_token.access_token);
Ok(access_token.access_token)
})
.await
.cloned()
}
/// This function takes a list of playlists keyword and returns a list of playlist ID
async fn get_playlist_ids(
config: &YoutubeConfig,
pl: &[String],
) -> Result<Vec<String>, Box<dyn Error>> {
let mut page_token = String::new();
let mut playlists: Vec<String> = vec![];
let access_token = refresh_token(config).await?;
let client = Client::new();
while let Ok(local_pl) = client
.get(&format!(
"https://www.googleapis.com/youtube/v3/playlists?part=snippet&mine=true&pageToken={}",
page_token
))
.header("Authorization", format!("Bearer {}", access_token))
.send()
.await?
.json::<YoutubePlaylistListResponse>()
.await
{
playlists.append(
&mut local_pl
.items
.iter()
.filter_map(|s| pl.contains(&s.snippet.title).then_some(s.id.clone()))
.collect(),
);
// if nextPageToken is present, continue the loop
match local_pl.next_page_token {
None => break,
Some(a) => page_token = a.clone(),
}
}
Ok(ACCESS_TOKEN.lock().unwrap().to_string())
debug!("Playlists IDs: {:?}", &playlists);
Ok(playlists)
}
pub fn create_resumable_upload(
/// This function adds the video id to the corresponding named playlist(s)
pub async fn add_video_to_playlists(
config: &YoutubeConfig,
v: &str,
pl: &[String],
) -> Result<(), Box<dyn Error>> {
let access_token = refresh_token(config).await?;
let playlists_ids = get_playlist_ids(config, pl).await?;
for pl_id in playlists_ids {
let yt_pl_upload_params = YoutubePlaylistItemsParams {
snippet: YoutubePlaylistItemsParamsSnippet {
playlist_id: pl_id.clone(),
resource_id: YoutubePlaylistItemsParamsSnippetResourceId {
video_id: v.to_string(),
..Default::default()
},
..Default::default()
},
};
let client = Client::new();
let res = client
.post("https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet")
.header("Authorization", format!("Bearer {}", access_token))
.json(&yt_pl_upload_params)
.send()
.await?;
if !res.status().is_success() {
return Err(TootubeError::new(&format!(
"Something went wrong when trying to add the video to a playlist: {}",
res.text().await?
))
.into());
}
}
Ok(())
}
/// This function creates a resumable YT upload, putting all the parameters in
pub async fn create_resumable_upload(
config: &YoutubeConfig,
vid: &PeerTubeVideo,
) -> Result<String, Box<dyn Error>> {
let access_token = refresh_token(config)?;
let access_token = refresh_token(config).await?;
let upload_params = YoutubeUploadParams {
snippet: {
@@ -125,13 +324,13 @@ pub fn create_resumable_upload(
}
},
};
debug!("YT upload params: {:?}", &upload_params);
let client = reqwest::blocking::Client::new();
let client = Client::new();
let res = client.post("https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus")
.header("Authorization", format!("Bearer {}", access_token))
.json(&upload_params)
.send()?;
.send().await?;
if res.status().is_success() {
Ok(res
@@ -145,28 +344,61 @@ pub fn create_resumable_upload(
}
}
pub fn upload_video(
f_path: &str,
/// This takes the PT stream for download, connects it to YT stream for upload
pub async fn now_kiss(
dl_url: &str,
r_url: &str,
config: &YoutubeConfig,
) -> Result<(), Box<dyn Error>> {
pg_conf: &TootubeConfig,
) -> Result<String, Box<dyn Error>> {
// Get access token
let access_token = refresh_token(config)?;
let access_token = refresh_token(config).await?;
// Get the upstream bytes stream
let res = reqwest::get(dl_url).await?;
let content_lengh = res
.content_length()
.ok_or(format!("Cannot get content length from {}", dl_url))?;
let mut stream = res.bytes_stream();
// Create the progress bar
let pb = ProgressBar::new(content_lengh);
pb.set_style(
ProgressStyle::default_bar()
.template(&pg_conf.progress_bar)?
.progress_chars(&pg_conf.progress_chars),
);
pb.set_message("Transferring…");
let mut transferring: u64 = 0;
// yields the stream chunk by chunk, updating the progress bar at the same time
let async_stream = stream! {
while let Some(chunk) = stream.next().await {
if let Ok(chunk) = &chunk {
let new = min(transferring + (chunk.len() as u64), content_lengh);
transferring = new;
pb.set_position(new);
if transferring >= content_lengh {
pb.finish();
}
}
yield chunk;
}
};
// Create client
let client = reqwest::blocking::Client::new();
let file = File::open(f_path)?;
let client = Client::new();
let res = client
.put(r_url)
.header("Authorization", format!("Bearer {}", access_token))
.body(file)
.send()?;
.body(Body::wrap_stream(async_stream))
.send()
.await?;
if res.status().is_success() {
Ok(())
let yt_videos: YoutubeVideos = res.json().await?;
Ok(yt_videos.id)
} else {
Err(TootubeError::new(&format!("Cannot upload video: {:?}", res.text()?)).into())
Err(TootubeError::new(&format!("Cannot upload video: {:?}", res.text().await?)).into())
}
}