Compare commits
5 Commits
f57fc8d22b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 479d2623e6 | |||
| a3caa0ebfa | |||
| 381560eef8 | |||
| 001b6f660c | |||
| 6f243e3485 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
/.direnv/
|
||||||
|
|||||||
10
shell.nix
Normal file
10
shell.nix
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
|
||||||
|
with pkgs;
|
||||||
|
|
||||||
|
mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
protobuf
|
||||||
|
rustup
|
||||||
|
];
|
||||||
|
}
|
||||||
21
src/grpc.rs
21
src/grpc.rs
@@ -1,12 +1,13 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use tonic::{metadata::MetadataValue, Request, Status};
|
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 {
|
pub mod stream_list {
|
||||||
tonic::include_proto!("youtube.api.v3");
|
tonic::include_proto!("youtube.api.v3");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_live_id(channel: String) -> String {
|
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()
|
||||||
@@ -16,15 +17,27 @@ pub fn get_live_id(channel: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn auth_header(mut req: Request<()>) -> Result<Request<()>, Status> {
|
pub fn auth_header(mut req: Request<()>) -> Result<Request<()>, Status> {
|
||||||
let token: MetadataValue<_> = "Bearer my-secret-token"
|
let oauth_token = "Yeah!".to_string();
|
||||||
|
let token: MetadataValue<_> = format!("Bearer {}", oauth_token)
|
||||||
.parse()
|
.parse()
|
||||||
.expect("failed to parse token");
|
.expect("failed to parse token");
|
||||||
|
|
||||||
req.metadata_mut()
|
req.metadata_mut()
|
||||||
.insert("x-goog-api-key", token)
|
.insert("authorization", token)
|
||||||
.expect("WHAT");
|
.expect("WHAT");
|
||||||
Ok(req)
|
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]
|
#[test]
|
||||||
fn test_get_live_id() {
|
fn test_get_live_id() {
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -1,8 +1,8 @@
|
|||||||
use tonic::{Request, transport::Channel};
|
use tonic::{transport::Channel};
|
||||||
use grpc::stream_list::{
|
use grpc::stream_list::{
|
||||||
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient, LiveChatMessageListRequest
|
v3_data_live_chat_message_service_client::V3DataLiveChatMessageServiceClient
|
||||||
};
|
};
|
||||||
use grpc::{auth_header, get_live_id};
|
use grpc::{auth_header, construct_request};
|
||||||
mod grpc;
|
mod grpc;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -12,14 +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 = Request::new(LiveChatMessageListRequest {
|
let request = construct_request(String::from("linlyboi"));
|
||||||
part: vec!["snippet".to_string()],
|
|
||||||
live_chat_id: Some(get_live_id(String::from("linlyboi"))),
|
|
||||||
max_results: Some(20),
|
|
||||||
page_token: None,
|
|
||||||
hl: None,
|
|
||||||
profile_image_size: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
let response = client.stream_list(request).await?;
|
let response = client.stream_list(request).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user