Skip to content

Commit

Permalink
resolve hanging thread issuse, add radio metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ljufa committed Oct 11, 2024
1 parent 93b1c26 commit fa472f6
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 178 deletions.
33 changes: 1 addition & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ anyhow = "1.0.88"
serde = {version = "1.0.210", features = ["derive"]}
serde_json = "1.0.128"
sled = "0.34.7"
symphonia = { version = "0.5.4", features = ["all"] }
symphonia = { path = "/home/dlj/github/Symphonia/symphonia", features = ["all"] }
cfg-if = "1.0.0"
tokio = { version = "1.40.0", features = ["full", "tracing"] }
futures = { version = "0.3.30", default-features = false }
tokio-stream = "0.1.16"
chrono = { version = "0.4.38", features = ["serde"]}
uuid = { version = "1.8.0", features = ["serde", "v4"] }
ureq = "2.10.1"

[profile.release]
opt-level = 3
Expand Down
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ script = "sudo pkill -9 rsplayer || true"

[tasks.run_local]
dependencies = ["kill_local"]
env = { "RUST_LOG" = "rsplayer=info,rsplayer_playback=info,warp=info", "RUST_BACKTRACE" = "full", "PORT" = "8000", "TLS_PORT" = "8443", "TLS_CERT_PATH" = "self.crt", "TLS_CERT_KEY_PATH" = "self.key" }
env = { "RUST_LOG" = "rsplayer=info,rsplayer_playback=debug,warp=info", "RUST_BACKTRACE" = "full", "PORT" = "8000", "TLS_PORT" = "8443", "TLS_CERT_PATH" = "self.crt", "TLS_CERT_KEY_PATH" = "self.key" }
cwd = ".run"
command = "cargo"
args = ["run"]
Expand Down
1 change: 1 addition & 0 deletions rsplayer_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sled.workspace = true
symphonia.workspace = true
chrono.workspace = true
uuid.workspace = true
ureq.workspace = true

api_models = {path = "../rsplayer_api_models"}
walkdir = "2.5.0"
Expand Down
39 changes: 36 additions & 3 deletions rsplayer_metadata/src/queue_service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::sync::{
atomic::{AtomicBool, AtomicU16, Ordering},
Arc,
use std::{
sync::{
atomic::{AtomicBool, AtomicU16, Ordering},
Arc,
},
time::Duration,
};

use log::info;
use rand::Rng;
use sled::{Db, IVec, Tree};

Expand Down Expand Up @@ -72,6 +76,35 @@ impl QueueService {
if let Ok(Some(value)) = self.queue_db.get(current_key) {
let mut song = Song::bytes_to_song(&value).expect("Failed to parse song");
song.statistics = self.statistics_repository.find_by_id(song.file.as_str());
if song.file.starts_with("http") {
let agent = ureq::AgentBuilder::new()
.timeout_connect(Duration::from_secs(5))
.timeout_read(Duration::from_secs(5))
.timeout_write(Duration::from_secs(5))
.build();
let Ok(resp) = agent.get(&song.file).set("accept", "*/*").call() else {
return None;
};

let status = resp.status();
info!("response status code:{status} / status text:{}", resp.status_text());
if status == 200 {

resp.headers_names()
.iter()
.filter(|h| h.starts_with("icy-"))
.for_each(|header_key| {
match header_key.as_str() {
"icy-name" => song.title = resp.header(header_key).map(|s|s.to_owned()),
"icy-description" => song.artist = resp.header(header_key).map(|s|s.to_owned()),
"icy-genre" => song.genre = resp.header(header_key).map(|s|s.to_owned()),
_ => ()
}
});
} else {
return None
}
}
return Some(song);
}
}
Expand Down
11 changes: 11 additions & 0 deletions rsplayer_metadata/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(test)]
mod queue {
use std::sync::Arc;

Expand Down Expand Up @@ -390,6 +391,15 @@ mod metadata {
assert_eq!(stat.liked_count, -2);
}

#[test]
fn test_favorite_radio_station(){
let ctx = TestContext::new();
ctx.metadata_service.like_media_item("radio_uuid_http://radioaparat.com");
let favs = ctx.metadata_service.get_favorite_radio_stations();
assert_eq!(favs.len(), 1);
assert_eq!(favs.get(0).unwrap(), "http://radioaparat.com");
}

#[test]
fn test_increase_play_count() {
let ctx = TestContext::new();
Expand All @@ -401,6 +411,7 @@ mod metadata {
}
}

#[cfg(test)]
mod playlist {
use std::vec;

Expand Down
4 changes: 2 additions & 2 deletions rsplayer_playback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ tokio.workspace = true
thread-priority = "1.1.0"
core_affinity = "0.8.1"
sled.workspace = true

ureq.workspace = true
# symphonia
cpal = "0.15.3"
# cpal = { path = "/home/dlj/github/cpal" }
rb = "0.4.1"
# rubato = "0.12.0"
ureq = "2.10.1"



mockall_double = "0.3.1"
Expand Down
Loading

0 comments on commit fa472f6

Please sign in to comment.