Compare commits

..

15 Commits

Author SHA1 Message Date
479d2623e6 change auth token header!
Google api docs LIED!
2026-04-20 08:06:12 +02:00
a3caa0ebfa I may be stupid 2026-04-20 08:06:05 +02:00
381560eef8 remove useless import 2026-04-13 10:49:52 +02:00
001b6f660c feat: construct request function
wow a helper function
changed get_live_id to private
2026-04-13 10:49:01 +02:00
6f243e3485 move request construction to grpc.rs 2026-04-13 10:46:57 +02:00
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
9 changed files with 84 additions and 43 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use nix

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target
/.direnv/

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"

10
shell.nix Normal file
View File

@@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
buildInputs = [
protobuf
rustup
];
}

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");
}

45
src/grpc.rs Normal file
View File

@@ -0,0 +1,45 @@
use std::process::Command;
use stream_list::{v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient, LiveChatMessageListRequest};
use tonic::{metadata::MetadataValue, service::interceptor::InterceptedService, transport::Channel, Request, Status};
pub mod stream_list {
tonic::include_proto!("youtube.api.v3");
}
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 oauth_token = "Yeah!".to_string();
let token: MetadataValue<_> = format!("Bearer {}", oauth_token)
.parse()
.expect("failed to parse token");
req.metadata_mut()
.insert("authorization", token)
.expect("WHAT");
Ok(req)
}
pub fn construct_request(channel: String) -> Request<LiveChatMessageListRequest>{
let request = Request::new(LiveChatMessageListRequest {
part: vec!["snippet".to_string()],
live_chat_id: Some(get_live_id(channel)),
max_results: Some(20),
page_token: None,
hl: None,
profile_image_size: None,
});
request
}
#[test]
fn test_get_live_id() {
get_live_id("linlyboi".to_string());
}

View File

@@ -1,44 +1,23 @@
use client::stream_list::{
LiveChatMessageListRequest,
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient,
use tonic::{transport::Channel};
use grpc::stream_list::{
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient
};
use tonic::{metadata::{errors::InvalidMetadataValue, MetadataValue}, transport::Channel, Request};
mod client;
use grpc::{auth_header, construct_request};
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 {
part: vec!["snippet".to_string()],
live_chat_id: Some("A0VHDvkheIg".to_string()), // TODO Fetch Latest Stream ID
max_results: Some(20),
page_token: None,
hl: None,
profile_image_size: None,
});
let request = construct_request(String::from("linlyboi"));
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)
}

4
todo.org Normal file
View File

@@ -0,0 +1,4 @@
* Inbox
** TODO use .env here LOL
[[file:~/Code/youtube-chat-rs/src/grpc.rs::let oauth_token = "Yeah!".to_string();]]