mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
she be working again
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
use crate::{anime_link, anime_names};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress,
|
get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress,
|
||||||
write_an_progress,
|
write_an_progress,
|
||||||
};
|
};
|
||||||
|
use crate::{get_anime_link, get_animes};
|
||||||
use crate::{open_cast, open_video};
|
use crate::{open_cast, open_video};
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
@@ -83,11 +83,13 @@ impl<T> StatefulList<T> {
|
|||||||
struct App {
|
struct App {
|
||||||
/// Current value of the input box
|
/// Current value of the input box
|
||||||
input: String,
|
input: String,
|
||||||
|
animes: (Vec<String>, Vec<String>),
|
||||||
/// Current input mode
|
/// Current input mode
|
||||||
input_mode: InputMode,
|
input_mode: InputMode,
|
||||||
/// History of recorded messages
|
/// History of recorded messages
|
||||||
messages: StatefulList<String>,
|
messages: StatefulList<String>,
|
||||||
title: String,
|
title: String,
|
||||||
|
link: String,
|
||||||
ep: u64,
|
ep: u64,
|
||||||
progress: i32,
|
progress: i32,
|
||||||
anime_id: i32,
|
anime_id: i32,
|
||||||
@@ -100,9 +102,11 @@ impl<'a> App {
|
|||||||
fn default() -> App {
|
fn default() -> App {
|
||||||
App {
|
App {
|
||||||
input: String::new(),
|
input: String::new(),
|
||||||
|
animes: (Vec::new(), Vec::new()),
|
||||||
input_mode: InputMode::Normal,
|
input_mode: InputMode::Normal,
|
||||||
messages: StatefulList::with_items(Vec::new()),
|
messages: StatefulList::with_items(Vec::new()),
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
|
link: String::new(),
|
||||||
ep: 0,
|
ep: 0,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
anime_id: 0,
|
anime_id: 0,
|
||||||
@@ -174,7 +178,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
app.progress = 0;
|
app.progress = 0;
|
||||||
let selected = app.messages.state.selected();
|
let selected = app.messages.state.selected();
|
||||||
app.title = app.messages.items[selected.unwrap()].clone();
|
app.title = app.messages.items[selected.unwrap()].clone();
|
||||||
let anime_info = get_anime_info(&app.title);
|
app.link = app.animes.0[selected.unwrap()].clone();
|
||||||
|
let anime_info = get_anime_info(&app.animes.0[selected.unwrap()]);
|
||||||
app.anime_id = get_anime_id(anime_info.0);
|
app.anime_id = get_anime_id(anime_info.0);
|
||||||
app.messages.items.clear();
|
app.messages.items.clear();
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
@@ -186,11 +191,14 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
app.messages.state.select(Some(app.progress as usize));
|
app.messages.state.select(Some(app.progress as usize));
|
||||||
}
|
}
|
||||||
if anime_info.1 == 1 {
|
if anime_info.1 == 1 {
|
||||||
let link = anime_link(&app.title, 1, &app.provider);
|
let link = get_anime_link(&app.link, 1);
|
||||||
if !app.cast.0 {
|
if !app.cast.0 {
|
||||||
open_video((link.0, link.1));
|
open_video((link, format!("{} Episode 1", &app.title)));
|
||||||
} else {
|
} else {
|
||||||
open_cast((link.0, link.1), &app.cast.1)
|
open_cast(
|
||||||
|
(link, format!("{} Episode 1", &app.title)),
|
||||||
|
&app.cast.1,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
write_an_progress(&app.title, &1);
|
write_an_progress(&app.title, &1);
|
||||||
@@ -213,11 +221,14 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
.replace("Episode ", "")
|
.replace("Episode ", "")
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let link = anime_link(&app.title, app.ep, &app.provider);
|
let link = get_anime_link(&app.link, app.ep);
|
||||||
if !app.cast.0 {
|
if !app.cast.0 {
|
||||||
open_video((link.0, link.1));
|
open_video((link, format!("{} Episode {}", &app.title, app.ep)));
|
||||||
} else {
|
} else {
|
||||||
open_cast((link.0, link.1), &app.cast.1)
|
open_cast(
|
||||||
|
(link, format!("{} Episode {}", &app.title, app.ep)),
|
||||||
|
&app.cast.1,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if app.ep > app.progress as u64 {
|
if app.ep > app.progress as u64 {
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
@@ -237,13 +248,12 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
},
|
},
|
||||||
InputMode::Editing => match key.code {
|
InputMode::Editing => match key.code {
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
//push app.input into app.messages with '1
|
//push app.input into app.messages with '
|
||||||
let anime_list = anime_names(app.input.drain(..).collect());
|
app.animes = get_animes(app.input.drain(..).collect());
|
||||||
app.messages.items.clear();
|
app.messages.items.clear();
|
||||||
for anime in anime_list {
|
for anime in &app.animes.1 {
|
||||||
app.messages.push(anime.to_string());
|
app.messages.push(anime.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
ep_select = false;
|
ep_select = false;
|
||||||
app.input_mode = InputMode::Normal;
|
app.input_mode = InputMode::Normal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use base64::{decode, encode};
|
|
||||||
use isahc::config::Configurable;
|
use isahc::config::Configurable;
|
||||||
use isahc::{ReadResponseExt, Request, RequestExt};
|
use isahc::{ReadResponseExt, Request, RequestExt};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
//use serde_json::json;
|
||||||
|
|
||||||
pub fn get_anime_html(url: &str) -> String {
|
pub fn get_anime_html(url: &str) -> String {
|
||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
@@ -16,126 +16,64 @@ pub fn get_anime_html(url: &str) -> String {
|
|||||||
req.send().unwrap().text().unwrap()
|
req.send().unwrap().text().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ep_location(url: &str) -> String {
|
pub fn get_post(id: &str) -> String {
|
||||||
let request = Request::builder()
|
let resp = Request::builder()
|
||||||
.method("HEAD")
|
.method("POST")
|
||||||
.uri(url)
|
.uri("https://yugen.to/api/embed/")
|
||||||
.header(
|
.header("x-requested-with", "XMLHttpRequest")
|
||||||
"user-agent",
|
.body(id)
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
.unwrap()
|
||||||
)
|
.send()
|
||||||
.body(())
|
.unwrap()
|
||||||
.unwrap();
|
.text();
|
||||||
let response = request.send().unwrap();
|
let resp: String = resp.as_ref().unwrap().to_string();
|
||||||
let headers = response.headers();
|
resp
|
||||||
let location = headers.get("location").unwrap();
|
|
||||||
location.to_str().unwrap().to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn anime_names(query: String) -> Vec<String> {
|
pub fn get_animes(query: String) -> (Vec<String>, Vec<String>) {
|
||||||
let url = format!("https://gogoanime.dk//search.html?keyword={}", query);
|
let query = query.replace(" ", "+");
|
||||||
//relpace all spaces with %20
|
let html = get_anime_html(&format!("https://yugen.to/search/?q={}", query));
|
||||||
let url = url.replace(' ', "%20");
|
let re = Regex::new(r#"href="(/anime[^"]*)""#).unwrap();
|
||||||
let html = get_anime_html(&url);
|
let mut animes_links = Vec::new();
|
||||||
let re = Regex::new(r#"(?m)/category/([^"]*)"#).unwrap();
|
|
||||||
let mut anime_list: Vec<String> = Vec::new();
|
|
||||||
for cap in re.captures_iter(&html) {
|
for cap in re.captures_iter(&html) {
|
||||||
anime_list.push(cap.get(1).unwrap().as_str().trim().to_string());
|
animes_links.push(cap[1].to_string());
|
||||||
}
|
}
|
||||||
anime_list.dedup();
|
let re = Regex::new(r#"/" title="([^"]*)""#).unwrap();
|
||||||
|
let mut animes_names = Vec::new();
|
||||||
anime_list
|
for cap in re.captures_iter(&html) {
|
||||||
}
|
animes_names.push(cap[1].to_string());
|
||||||
|
|
||||||
pub fn get_anime_info(title: &str) -> (i32, u16) {
|
|
||||||
let url = format!("https://animixplay.to/v1/{}", title);
|
|
||||||
let html = get_anime_html(&url);
|
|
||||||
let re = Regex::new(r#"(?m)var malid = '([0-9]*)'"#).unwrap();
|
|
||||||
let mal_id = re
|
|
||||||
.captures_iter(&html)
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.get(1)
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.trim()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let re = Regex::new(r#"(?m)"eptotal":([\d]+)"#).unwrap();
|
|
||||||
let episodes = re
|
|
||||||
.captures_iter(&html)
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.get(1)
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.trim()
|
|
||||||
.to_string();
|
|
||||||
(
|
|
||||||
mal_id.parse::<i32>().unwrap_or(0),
|
|
||||||
episodes.parse::<u16>().unwrap_or(0),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn anime_link(title: &str, ep: u64, provider: &str) -> (String, String) {
|
|
||||||
let url = format!("https://animixplay.to/v1/{}", title);
|
|
||||||
let html = get_anime_html(&url);
|
|
||||||
let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap();
|
|
||||||
let id1 = match re.captures_iter(&html).nth(ep as usize - 1) {
|
|
||||||
Some(cap) => cap.get(1).unwrap().as_str().trim().to_string(),
|
|
||||||
None => "".to_string(),
|
|
||||||
};
|
|
||||||
if id1 != "" {
|
|
||||||
if provider == "vrv" {
|
|
||||||
let title = format!("{} Episode {}", title.replace('-', " "), ep);
|
|
||||||
let encoded_id1 = encode(&id1);
|
|
||||||
let encoded_id2 = encode(&encoded_id1);
|
|
||||||
let mut last_byte = encoded_id1.as_bytes()[encoded_id1.len() - 2];
|
|
||||||
last_byte += 1;
|
|
||||||
let mut new_encoded_id1 = encoded_id1.as_bytes().to_vec();
|
|
||||||
new_encoded_id1.pop();
|
|
||||||
new_encoded_id1.pop();
|
|
||||||
new_encoded_id1.push(last_byte);
|
|
||||||
let new_encoded_id1 = String::from_utf8(new_encoded_id1).unwrap();
|
|
||||||
let ani_id = format!("cW9{}MVFhzM0dyVTh3ZTlP{}", new_encoded_id1, encoded_id2);
|
|
||||||
let result = get_ep_location(format!("https://animixplay.to/api/{}", ani_id).as_str());
|
|
||||||
//split the result into at # and return the second part
|
|
||||||
let result: String = std::str::from_utf8(
|
|
||||||
decode(result.split('#').nth(1).unwrap())
|
|
||||||
.unwrap()
|
|
||||||
.as_slice(),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
return (result, title);
|
|
||||||
} else if provider == "gogo" {
|
|
||||||
let title = format!("{} Episode {}", title.replace('-', " "), ep);
|
|
||||||
let encoded_id1 = encode(&id1);
|
|
||||||
let anime_id = encode(format!("{}LTXs3GrU8we9O{}", id1, encoded_id1));
|
|
||||||
let html = format!("https://animixplay.to/api/cW9{}", anime_id);
|
|
||||||
let url = get_ep_location(&html);
|
|
||||||
let url = url.split('#').nth(1).unwrap();
|
|
||||||
let url = std::str::from_utf8(&decode(url).unwrap())
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
return (url, title);
|
|
||||||
} else {
|
|
||||||
panic!("Invalid provider");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let re = Regex::new(r#"(?m)r\.html#(.*)""#).unwrap();
|
|
||||||
let id2 = re
|
|
||||||
.captures_iter(&html)
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.get(1)
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.trim()
|
|
||||||
.to_string();
|
|
||||||
let url = decode(id2).unwrap();
|
|
||||||
let url = std::str::from_utf8(&url).unwrap().to_string();
|
|
||||||
let title = format!("{} Episode {}", title.replace('-', " "), ep);
|
|
||||||
return (url, title);
|
|
||||||
}
|
}
|
||||||
|
(animes_links, animes_names)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_anime_info(url: &str) -> (i32, u16) {
|
||||||
|
let url = format!("https://yugen.to{}watch", url);
|
||||||
|
let html = get_anime_html(&url);
|
||||||
|
//print html and exit
|
||||||
|
let re = Regex::new(r#""mal_id":(\d*)"#).unwrap();
|
||||||
|
let mal_id = re.captures(&html).unwrap()[1].parse().unwrap();
|
||||||
|
let re =
|
||||||
|
Regex::new(r#"Episodes</div><span class="description" style="font-size: \d*px;">(\d*)"#)
|
||||||
|
.unwrap();
|
||||||
|
let episodes = re.captures(&html).unwrap()[1].parse().unwrap();
|
||||||
|
(mal_id, episodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_anime_link(url: &str, episode: u64) -> String {
|
||||||
|
let url = &format!(
|
||||||
|
"https://yugen.to/watch{}{}/",
|
||||||
|
url.replace("/anime", ""),
|
||||||
|
episode
|
||||||
|
);
|
||||||
|
let html = get_anime_html(url);
|
||||||
|
let re = Regex::new(r#"iframe id="main-embed" src="https://yugen.to/e/(.*)=="#).unwrap();
|
||||||
|
let capture = re.captures(&html).unwrap();
|
||||||
|
let id = &capture[1];
|
||||||
|
let id = format!("id={}%3D%3D&ac=0", id);
|
||||||
|
let json = get_post(&id);
|
||||||
|
let re = Regex::new(r#"hls": \["(.*)","#).unwrap();
|
||||||
|
let capture = re.captures(&json).unwrap();
|
||||||
|
let link = &capture[1];
|
||||||
|
//return the link
|
||||||
|
link.to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,7 @@ use colored::Colorize;
|
|||||||
//use ln::ui::ln_ui;
|
//use ln::ui::ln_ui;
|
||||||
use ln::ln::ln_ui;
|
use ln::ln::ln_ui;
|
||||||
|
|
||||||
use crate::anime::{
|
use crate::anime::{player::*, scraper::*, trackers::*};
|
||||||
player::{open_cast, open_video},
|
|
||||||
scraper::{anime_link, anime_names},
|
|
||||||
trackers::*,
|
|
||||||
};
|
|
||||||
use crate::get_token;
|
use crate::get_token;
|
||||||
use crate::helpers::take_input::{int_input, string_input};
|
use crate::helpers::take_input::{int_input, string_input};
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user