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
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use tonic::{metadata::MetadataValue, Request, Status};
|
||||||
|
|
||||||
pub mod stream_list {
|
pub mod stream_list {
|
||||||
tonic::include_proto!("youtube.api.v3");
|
tonic::include_proto!("youtube.api.v3");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_live_id(channel: String) -> String {
|
pub fn get_live_id(channel: String) -> String {
|
||||||
let video_id = Command::new("./get_url.sh")
|
let video_id = Command::new("./get_url.sh")
|
||||||
.arg(channel)
|
.arg(channel)
|
||||||
.output()
|
.output()
|
||||||
@@ -13,6 +15,17 @@ fn get_live_id(channel: String) -> String {
|
|||||||
String::from_utf8_lossy(&stdout).trim().to_string()
|
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]
|
#[test]
|
||||||
fn test_get_live_id() {
|
fn test_get_live_id() {
|
||||||
get_live_id("linlyboi".to_string());
|
get_live_id("linlyboi".to_string());
|
||||||
22
src/main.rs
22
src/main.rs
@@ -1,7 +1,9 @@
|
|||||||
use tonic::{Request, Status, metadata::MetadataValue, transport::Channel};
|
use tonic::{Request, transport::Channel};
|
||||||
use youtube_chat_rs::{get_live_id, stream_list::{
|
use grpc::stream_list::{
|
||||||
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient, LiveChatMessageListRequest
|
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient, LiveChatMessageListRequest
|
||||||
}};
|
};
|
||||||
|
use grpc::{auth_header, get_live_id};
|
||||||
|
mod grpc;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -10,7 +12,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.await?;
|
.await?;
|
||||||
let mut client = V3DataLiveChatMessageServiceClient::with_interceptor(channel, auth_header);
|
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()],
|
part: vec!["snippet".to_string()],
|
||||||
live_chat_id: Some(get_live_id(String::from("linlyboi"))),
|
live_chat_id: Some(get_live_id(String::from("linlyboi"))),
|
||||||
max_results: Some(20),
|
max_results: Some(20),
|
||||||
@@ -21,18 +23,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let response = client.stream_list(request).await?;
|
let response = client.stream_list(request).await?;
|
||||||
|
|
||||||
println!("RESPONSE={:?}", response);
|
println!("RESPONSE={response:?}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user