Compare commits

..

10 Commits

Author SHA1 Message Date
f57fc8d22b refactor: lib.rs to grpc.rss
I may be stupid

lib.rs is a whole other crate can't have pub(crate) in two crates STUPID
renamed lib.rs to grpc.rs
2026-04-13 10:27:33 +02:00
96ba273dc5 chore: remove todo comment lol 2026-04-13 10:05:31 +02:00
f504155d77 feat: no longer hard coded video_id 2026-04-13 10:04:52 +02:00
1d298794ce feat: video_id script, move proto include to lib 2026-04-13 10:01:58 +02:00
5a661c826d same shit different elevator 2026-04-13 09:57:08 +02:00
db181b83e3 fmt: I ran cargo fmt 2026-04-13 09:56:57 +02:00
a49de349ab refactor: rename client module to grpc
also removed a useless import
2026-04-13 09:56:23 +02:00
eca45650ca open sourceeeeeee 2026-04-13 09:51:29 +02:00
6009679e9e this doesn't need to be async 2026-04-13 08:48:24 +02:00
378044a41c replace closure with auth_header function
I AM SO COOL
2026-04-13 08:46:13 +02:00
5 changed files with 56 additions and 37 deletions

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2026 LinlyBoi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

5
get_url.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
CHANNEL=$1
LIVE_ID=$(curl -sL "https://www.youtube.com/@$CHANNEL/live" | grep -oE '"videoId":"([^"]+)"' | head -n 1 | cut -d'"' -f4)
echo "$LIVE_ID"

View File

@@ -1,11 +0,0 @@
use tonic::{Request, Response, Status, transport::Server};
// use stream_list::greeter_server::{Greeter, GreeterServer};
// use stream_list::{HelloReply, HelloRequest};
use stream_list::{
LiveChatMessageListRequest,
v3_data_live_chat_message_service_server::V3DataLiveChatMessageService,
};
pub mod stream_list {
tonic::include_proto!("youtube.api.v3");
}

32
src/grpc.rs Normal file
View File

@@ -0,0 +1,32 @@
use std::process::Command;
use tonic::{metadata::MetadataValue, Request, Status};
pub mod stream_list {
tonic::include_proto!("youtube.api.v3");
}
pub fn get_live_id(channel: String) -> String {
let video_id = Command::new("./get_url.sh")
.arg(channel)
.output()
.expect("couldn't execute fetch script");
let stdout = video_id.stdout.as_slice().to_vec();
String::from_utf8_lossy(&stdout).trim().to_string()
}
pub fn auth_header(mut req: Request<()>) -> Result<Request<()>, Status> {
let token: MetadataValue<_> = "Bearer my-secret-token"
.parse()
.expect("failed to parse token");
req.metadata_mut()
.insert("x-goog-api-key", token)
.expect("WHAT");
Ok(req)
}
#[test]
fn test_get_live_id() {
get_live_id("linlyboi".to_string());
}

View File

@@ -1,26 +1,20 @@
use client::stream_list::{
LiveChatMessageListRequest,
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient,
use tonic::{Request, transport::Channel};
use grpc::stream_list::{
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient, LiveChatMessageListRequest
};
use tonic::{metadata::{errors::InvalidMetadataValue, MetadataValue}, transport::Channel, Request};
mod client;
use grpc::{auth_header, get_live_id};
mod grpc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = Channel::from_static("dns:///youtube.googleapis.com:443").connect().await?;
let token: MetadataValue<_> = "Bearer my-secret-token".parse()?;
let mut client = V3DataLiveChatMessageServiceClient::with_interceptor(
channel,
move |mut req: Request<()>| {
req.metadata_mut().insert("authorization", token.clone());
Ok(req)
},
);
let channel = Channel::from_static("dns:///youtube.googleapis.com:443")
.connect()
.await?;
let mut client = V3DataLiveChatMessageServiceClient::with_interceptor(channel, auth_header);
let request = tonic::Request::new(LiveChatMessageListRequest {
let request = Request::new(LiveChatMessageListRequest {
part: vec!["snippet".to_string()],
live_chat_id: Some("A0VHDvkheIg".to_string()), // TODO Fetch Latest Stream ID
live_chat_id: Some(get_live_id(String::from("linlyboi"))),
max_results: Some(20),
page_token: None,
hl: None,
@@ -29,16 +23,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let response = client.stream_list(request).await?;
println!("RESPONSE={:?}", response);
println!("RESPONSE={response:?}");
Ok(())
}
async fn auth_header(mut req: Request<()>) -> Result<Request<()>, InvalidMetadataValue> {
let token: MetadataValue<_> = "Bearer my-secret-token".parse()?;
req.metadata_mut().insert("x-goog-api-key", token).expect("WHAT");
Ok(req)
}