From ccc4958080717979914ff92c07e9ad1c355650f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Lachapelle?= Date: Wed, 23 Oct 2024 12:18:57 -0700 Subject: [PATCH] fix a few bugs --- src-tauri/src/m3u.rs | 12 ++++++++---- src-tauri/src/mpv.rs | 3 ++- src-tauri/src/sql.rs | 29 ++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/m3u.rs b/src-tauri/src/m3u.rs index 1089616..945bd63 100644 --- a/src-tauri/src/m3u.rs +++ b/src-tauri/src/m3u.rs @@ -60,9 +60,13 @@ pub fn read_m3u8(mut source: Source) -> Result<()> { continue; } }; - let (fail, headers) = extract_headers(&mut l2, &mut lines)?; - if fail { - continue; + let mut headers: Option = None; + if l2.starts_with("#EXTVLCOPT") { + let (fail, _headers) = extract_headers(&mut l2, &mut lines)?; + if fail { + continue; + } + headers = _headers; } let mut channel = match get_channel_from_lines(l1, l2, source.id.unwrap()) .with_context(|| format!("Failed to process lines #{c1} #{c2}, skipping")) @@ -155,7 +159,7 @@ fn extract_headers(l2: &mut String, lines: &mut Skip = LazyLock::new(|| find_macos_bin(YTDLP_BIN_ pub async fn play(channel: Channel, record: bool) -> Result<()> { println!("{} playing", channel.url.as_ref().unwrap()); let args = get_play_args(channel, record)?; + println!("with args: {:?}", args); let mut cmd = Command::new(MPV_PATH.clone()) .args(args) .stdout(Stdio::piped()) @@ -169,7 +170,7 @@ fn set_headers(headers: Option, args: &mut Vec) { fn get_path(path_str: String) -> String { let path = Path::new(&path_str); let path = path.join(get_file_name()); - return path.to_string_lossy().to_string(); // Check if it causes problems for some OS languages? + return path.to_string_lossy().to_string(); } fn get_file_name() -> String { diff --git a/src-tauri/src/sql.rs b/src-tauri/src/sql.rs index a9363cb..a82fae3 100644 --- a/src-tauri/src/sql.rs +++ b/src-tauri/src/sql.rs @@ -35,7 +35,6 @@ fn get_and_create_sqlite_db_path() -> String { return path.to_string_lossy().to_string(); } -//@TODO: Nullable types fn create_structure() -> Result<()> { let sql = get_conn()?; sql.execute_batch( @@ -189,7 +188,7 @@ pub fn insert_channel_headers(tx: &Transaction, headers: ChannelHttpHeaders) -> tx.execute( r#" INSERT OR IGNORE INTO channel_http_headers (channel_id, referrer, user_agent, http_origin) -VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, false); +VALUES (?, ?, ?, ?); "#, params![ headers.channel_id, @@ -248,11 +247,13 @@ pub fn set_channel_group_id( pub fn get_channel_headers_by_id(id: i64) -> Result> { let sql = get_conn()?; - let headers = sql.query_row( - "SELECT * FROM channel_http_headers WHERE channel_id = ?", - params![id], - row_to_channel_headers, - ).optional()?; + let headers = sql + .query_row( + "SELECT * FROM channel_http_headers WHERE channel_id = ?", + params![id], + row_to_channel_headers, + ) + .optional()?; Ok(headers) } @@ -263,7 +264,7 @@ fn row_to_channel_headers(row: &Row) -> Result std::result::Result { pub fn delete_channels_by_source(source_id: i64) -> Result<()> { let sql = get_conn()?; + sql.execute( + r#" + DELETE + FROM channel_http_headers ch + JOIN channels c ON ch.channel_id = c.id + WHERE c.source_id = ? + AND c.favorite = 0; + "#, + params![source_id.to_string()], + )?; sql.execute( r#" DELETE FROM channels - WHERE source_id = ?1 + WHERE source_id = ? AND favorite = 0; "#, params![source_id.to_string()],