sort by links when in offline mode

This commit is contained in:
Love 2023-03-08 19:12:26 +01:00
parent 692d6d08c7
commit 1d0e709784
2 changed files with 7 additions and 10 deletions

View File

@ -44,11 +44,6 @@ async fn main() {
.iter()
.for_each(|s| println!("{}", &s));
// let gm = GrandMother::new(Configuration::new().expect("Failed to write to configfile"))
// .await
// .unwrap();
// let parser = Parser::new(config.clone()).await;
let mut mpv_fs = false;
let mut search_result: Option<Rc<Vec<&M3u8>>> = None;
let mut readline = Readline::new();

View File

@ -6,12 +6,12 @@ use crate::{m3u8::M3u8, Configuration, GetM3u8, GetPlayPath, OfflineEntry};
#[derive(Serialize)]
pub struct OfflineParser {
m3u8_items: Rc<Vec<OfflineEntry>>,
offline_entries: Rc<Vec<OfflineEntry>>,
}
impl OfflineParser {
pub fn new(config: &Configuration) -> Self {
Self {
m3u8_items: config.offlinefile_content.clone(),
offline_entries: config.offlinefile_content.clone(),
}
}
}
@ -20,13 +20,13 @@ impl Deref for OfflineParser {
type Target = Vec<OfflineEntry>;
fn deref(&self) -> &Self::Target {
&*self.m3u8_items
&*self.offline_entries
}
}
impl GetPlayPath for OfflineParser {
fn get_path_to_play(&self, link: Rc<String>) -> Result<Rc<String>, String> {
for offline_entry in &*self.m3u8_items {
for offline_entry in &*self.offline_entries {
if *offline_entry.link == *link {
return Ok(offline_entry.path.clone());
}
@ -37,6 +37,8 @@ impl GetPlayPath for OfflineParser {
impl GetM3u8 for OfflineParser {
fn get_m3u8(&self) -> Vec<&M3u8> {
self.m3u8_items.iter().map(|x| &**x).collect()
let mut items: Vec<&M3u8> = self.offline_entries.iter().map(|x| &**x).collect();
items.sort_by_key(|x| &x.link);
items
}
}