mirror of
https://codeberg.org/librarian/stream-proxy
synced 2024-12-06 19:26:34 +01:00
First commit
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
use actix_web::{error, web, Error, HttpResponse};
|
||||
use awc::Client;
|
||||
|
||||
pub async fn forward_live(
|
||||
payload: web::Payload,
|
||||
path: web::Path<String>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let cdn_url = "https://cdn.odysee.live/";
|
||||
let url = cdn_url.to_owned() + &path;
|
||||
|
||||
let client = Client::default();
|
||||
|
||||
println!("{}", url);
|
||||
|
||||
let forwarded_req = client
|
||||
.get(url)
|
||||
.insert_header((
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0",
|
||||
))
|
||||
.insert_header(("Origin", "https://odysee.com"))
|
||||
.insert_header(("Referer", "https://odysee.com/"))
|
||||
.no_decompress();
|
||||
|
||||
let res = forwarded_req
|
||||
.send_stream(payload)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
let mut client_resp = HttpResponse::build(res.status());
|
||||
|
||||
match res.headers().get("Content-Type") {
|
||||
None => client_resp.insert_header(("Content-Type", "application/octet-stream")),
|
||||
Some(header) => client_resp.insert_header(("Content-Type", header)),
|
||||
};
|
||||
client_resp.insert_header(("Access-Control-Allow-Origin", "*"));
|
||||
|
||||
Ok(client_resp.streaming(res))
|
||||
}
|
||||
+16
-40
@@ -1,50 +1,26 @@
|
||||
use actix_web::{error, web, App, Error, HttpResponse, HttpServer};
|
||||
use awc::Client;
|
||||
mod live;
|
||||
mod stream;
|
||||
|
||||
async fn forward(payload: web::Payload, path: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||
let cdn_url = "https://cdn.odysee.live/";
|
||||
let url = cdn_url.to_owned() + &path;
|
||||
|
||||
let client = Client::default();
|
||||
|
||||
println!("{}", url);
|
||||
|
||||
let forwarded_req = client
|
||||
.get(url)
|
||||
.insert_header((
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0",
|
||||
))
|
||||
.insert_header(("Origin", "https://odysee.com"))
|
||||
.insert_header(("Referer", "https://odysee.com/"))
|
||||
.no_decompress();
|
||||
|
||||
let res = forwarded_req
|
||||
.send_stream(payload)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
let mut client_resp = HttpResponse::build(res.status());
|
||||
// Remove `Connection` as per
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection#Directives
|
||||
for (header_name, header_value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
|
||||
client_resp.insert_header((header_name.clone(), header_value.clone()));
|
||||
}
|
||||
client_resp.insert_header(("Access-Control-Allow-Origin", "*"));
|
||||
|
||||
Ok(client_resp.streaming(res))
|
||||
}
|
||||
use std::env;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let address = match env::var("ADDRESS") {
|
||||
Ok(val) => val,
|
||||
Err(_e) => "0.0.0.0".to_string(),
|
||||
};
|
||||
let port = match env::var("PORT") {
|
||||
Ok(val) => val,
|
||||
Err(_e) => "3001".to_string(),
|
||||
};
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
//.app_data(web::Data::new(Client::default()))
|
||||
//.app_data(web::Data::new(forward_url.clone()))
|
||||
.route("/live/{path:.*}", web::get().to(forward))
|
||||
.route("/live/{path:.*}", web::get().to(live::forward_live))
|
||||
.route("/stream/{path:.*}", web::get().to(stream::forward_stream))
|
||||
})
|
||||
.bind("0.0.0.0:3001")?
|
||||
.workers(4)
|
||||
.bind(address + &":".to_string() + &port)?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
use actix_web::{error, web, Error, HttpResponse};
|
||||
use awc::Client;
|
||||
|
||||
pub async fn forward_stream(payload: web::Payload, path: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||
let cdn_url = "https://player.odycdn.com/";
|
||||
let url = cdn_url.to_owned() + &path;
|
||||
|
||||
let client = Client::default();
|
||||
|
||||
println!("{}", url);
|
||||
|
||||
let forwarded_req = client
|
||||
.get(url)
|
||||
.insert_header((
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0",
|
||||
))
|
||||
.insert_header(("Origin", "https://odysee.com"))
|
||||
.insert_header(("Referer", "https://odysee.com/"))
|
||||
.no_decompress();
|
||||
|
||||
let res = forwarded_req
|
||||
.send_stream(payload)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
let mut client_resp = HttpResponse::build(res.status());
|
||||
|
||||
match res.headers().get("Content-Type") {
|
||||
None => client_resp.insert_header(("Content-Type", "application/octet-stream")),
|
||||
Some(header) => client_resp.insert_header(("Content-Type", header)),
|
||||
};
|
||||
client_resp.insert_header(("Access-Control-Allow-Origin", "*"));
|
||||
|
||||
Ok(client_resp.streaming(res))
|
||||
}
|
||||
Reference in New Issue
Block a user