mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 12:50:32 +00:00
added Chrome cast
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use crate::open_video;
|
||||
use crate::{anime_link, anime_names};
|
||||
use crate::{
|
||||
get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress,
|
||||
write_an_progress,
|
||||
};
|
||||
use crate::{open_cast, open_video};
|
||||
|
||||
use crossterm::{
|
||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
||||
@@ -93,6 +93,7 @@ struct App {
|
||||
anime_id: i32,
|
||||
token: String,
|
||||
provider: String,
|
||||
cast: (bool, String),
|
||||
}
|
||||
|
||||
impl<'a> App {
|
||||
@@ -107,11 +108,16 @@ impl<'a> App {
|
||||
anime_id: 0,
|
||||
token: String::new(),
|
||||
provider: String::new(),
|
||||
cast: (false, "0".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn anime_ui(token: String, provider: String) -> Result<(), Box<dyn Error>> {
|
||||
pub fn anime_ui(
|
||||
token: String,
|
||||
provider: String,
|
||||
cast: (bool, String),
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// setup terminal
|
||||
enable_raw_mode()?;
|
||||
let mut stdout = io::stdout();
|
||||
@@ -123,6 +129,7 @@ pub fn anime_ui(token: String, provider: String) -> Result<(), Box<dyn Error>> {
|
||||
let mut app = App::default();
|
||||
app.token = token;
|
||||
app.provider = provider;
|
||||
app.cast = cast;
|
||||
let res = run_app(&mut terminal, app);
|
||||
|
||||
// restore terminal
|
||||
@@ -180,7 +187,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
||||
}
|
||||
if anime_info.1 == 1 {
|
||||
let link = anime_link(&app.title, 1, &app.provider);
|
||||
open_video((link.0, link.1));
|
||||
if !app.cast.0 {
|
||||
open_video((link.0, link.1));
|
||||
} else {
|
||||
open_cast((link.0, link.1), &app.cast.1)
|
||||
}
|
||||
if app.token == "local" || app.anime_id == 0 {
|
||||
write_an_progress(&app.title, &1);
|
||||
} else {
|
||||
@@ -203,7 +214,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
||||
.parse::<u64>()
|
||||
.unwrap();
|
||||
let link = anime_link(&app.title, app.ep, &app.provider);
|
||||
open_video((link.0, link.1));
|
||||
if !app.cast.0 {
|
||||
open_video((link.0, link.1));
|
||||
} else {
|
||||
open_cast((link.0, link.1), &app.cast.1)
|
||||
}
|
||||
if app.ep > app.progress as u64 {
|
||||
if app.token == "local" || app.anime_id == 0 {
|
||||
write_an_progress(&app.title, &app.ep);
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
extern crate rust_cast;
|
||||
use rust_cast::{
|
||||
channels::{
|
||||
media::{Media, StreamType},
|
||||
receiver::CastDeviceApp,
|
||||
},
|
||||
CastDevice,
|
||||
};
|
||||
use std::str::FromStr;
|
||||
|
||||
pub fn open_video(link: (String, String)) {
|
||||
let title = link.1;
|
||||
let title = title.replace("-", " ");
|
||||
@@ -10,3 +20,63 @@ pub fn open_video(link: (String, String)) {
|
||||
|
||||
// clear terminal
|
||||
}
|
||||
|
||||
const DEFAULT_DESTINATION_ID: &str = "receiver-0";
|
||||
fn play_media(
|
||||
device: &CastDevice,
|
||||
app_to_run: &CastDeviceApp,
|
||||
media: String,
|
||||
media_type: String,
|
||||
media_stream_type: StreamType,
|
||||
) {
|
||||
let app = device.receiver.launch_app(app_to_run).unwrap();
|
||||
|
||||
device
|
||||
.connection
|
||||
.connect(app.transport_id.as_str())
|
||||
.unwrap();
|
||||
|
||||
let _status = device
|
||||
.media
|
||||
.load(
|
||||
app.transport_id.as_str(),
|
||||
app.session_id.as_str(),
|
||||
&Media {
|
||||
content_id: media,
|
||||
content_type: media_type,
|
||||
stream_type: media_stream_type,
|
||||
duration: None,
|
||||
metadata: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn open_cast(link: (String, String), ip: &str) {
|
||||
let cast_device = match CastDevice::connect_without_host_verification(ip, 8009) {
|
||||
Ok(cast_device) => cast_device,
|
||||
Err(err) => panic!("Could not establish connection with Cast Device: {:?}", err),
|
||||
};
|
||||
|
||||
cast_device
|
||||
.connection
|
||||
.connect(DEFAULT_DESTINATION_ID.to_string())
|
||||
.unwrap();
|
||||
cast_device.heartbeat.ping().unwrap();
|
||||
|
||||
// Play media and keep connection.
|
||||
|
||||
let media_stream_type = match "none" {
|
||||
value @ "buffered" | value @ "live" | value @ "none" => {
|
||||
StreamType::from_str(value).unwrap()
|
||||
}
|
||||
_ => panic!("Unsupported stream type!"),
|
||||
};
|
||||
play_media(
|
||||
&cast_device,
|
||||
&CastDeviceApp::from_str("default").unwrap(),
|
||||
link.0.to_string(),
|
||||
"".to_string(),
|
||||
media_stream_type,
|
||||
);
|
||||
}
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@@ -8,7 +8,7 @@ use colored::Colorize;
|
||||
use ln::ln::ln_ui;
|
||||
|
||||
use crate::anime::{
|
||||
player::open_video,
|
||||
player::{open_cast, open_video},
|
||||
scraper::{anime_link, anime_names},
|
||||
trackers::*,
|
||||
};
|
||||
@@ -22,6 +22,7 @@ fn main() {
|
||||
//let search = option string
|
||||
let mut count = 0;
|
||||
let mut provider: String = "gogo".to_string();
|
||||
let mut cast = (false, "0".to_string());
|
||||
for arg in std::env::args() {
|
||||
if arg == "--help" || arg == "-h" {
|
||||
help = true;
|
||||
@@ -45,6 +46,13 @@ fn main() {
|
||||
provider = "vrv".to_string();
|
||||
}
|
||||
}
|
||||
if arg == "--cast" || arg == "-C" {
|
||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||
cast = (true, String::from(arg))
|
||||
} else {
|
||||
println!("{}", "please provide a ip address".red())
|
||||
}
|
||||
}
|
||||
|
||||
if arg == "--ln" || arg == "-l" {
|
||||
ln = true;
|
||||
@@ -85,7 +93,7 @@ fn main() {
|
||||
//anime_stream(search, episode, resume);
|
||||
|
||||
let token = get_token();
|
||||
_ = anime_ui(token, provider);
|
||||
_ = anime_ui(token, provider, cast);
|
||||
} else {
|
||||
println!("Invalid argument");
|
||||
}
|
||||
@@ -95,6 +103,11 @@ fn print_help() {
|
||||
println!("anime:\t\t{}", format_args!("{}", "-a --anime".red()));
|
||||
//print blank line
|
||||
println!("");
|
||||
println!(
|
||||
"cast:\t\t{}",
|
||||
format_args!("{} {}", "-C --cast".red(), "<IP Adress>".green())
|
||||
);
|
||||
println!("");
|
||||
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
||||
//print blank line
|
||||
println!("");
|
||||
|
||||
Reference in New Issue
Block a user