Skip to content

Commit

Permalink
fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredolx committed Oct 23, 2024
1 parent 7bf87ab commit ccc4958
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src-tauri/src/m3u.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelHttpHeaders> = 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"))
Expand Down Expand Up @@ -155,7 +159,7 @@ fn extract_headers(l2: &mut String, lines: &mut Skip<Enumerate<Lines<BufReader<F
}
}
if at_least_one {
return Ok((true, Some(headers)));
return Ok((false, Some(headers)));
}
else {
return Ok((true, None));
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/mpv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static YTDLP_PATH: LazyLock<String> = 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())
Expand Down Expand Up @@ -169,7 +170,7 @@ fn set_headers(headers: Option<ChannelHttpHeaders>, args: &mut Vec<String>) {
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 {
Expand Down
29 changes: 20 additions & 9 deletions src-tauri/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -248,11 +247,13 @@ pub fn set_channel_group_id(

pub fn get_channel_headers_by_id(id: i64) -> Result<Option<ChannelHttpHeaders>> {
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)
}

Expand All @@ -263,7 +264,7 @@ fn row_to_channel_headers(row: &Row) -> Result<ChannelHttpHeaders, rusqlite::Err
http_origin: row.get("http_origin")?,
referrer: row.get("referrer")?,
user_agent: row.get("user_agent")?,
ignore_ssl: row.get("ignore_ssl")?
ignore_ssl: row.get("ignore_ssl")?,
})
}

Expand Down Expand Up @@ -448,10 +449,20 @@ fn row_to_channel(row: &Row) -> std::result::Result<Channel, rusqlite::Error> {

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()],
Expand Down

0 comments on commit ccc4958

Please sign in to comment.