Compare commits
15 Commits
4a73819d67
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 479d2623e6 | |||
| a3caa0ebfa | |||
| 381560eef8 | |||
| 001b6f660c | |||
| 6f243e3485 | |||
| f57fc8d22b | |||
| 96ba273dc5 | |||
| f504155d77 | |||
| 1d298794ce | |||
| 5a661c826d | |||
| db181b83e3 | |||
| a49de349ab | |||
| eca45650ca | |||
| 6009679e9e | |||
| 378044a41c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/.direnv/
|
||||
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal 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
5
get_url.sh
Executable 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
10
shell.nix
Normal file
@@ -0,0 +1,10 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
mkShell {
|
||||
buildInputs = [
|
||||
protobuf
|
||||
rustup
|
||||
];
|
||||
}
|
||||
@@ -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
45
src/grpc.rs
Normal 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());
|
||||
}
|
||||
43
src/main.rs
43
src/main.rs
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user