mirror of
https://github.com/tsirysndr/music-player.git
synced 2026-01-08 20:58:07 -05:00
fix(searcher): skip track if already indexed
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -4534,7 +4534,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "music-player-storage"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools",
|
||||
@@ -8405,9 +8405,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||
|
||||
[[package]]
|
||||
name = "upnp-client"
|
||||
version = "0.1.7"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "707a259c0ef8bde8be3519694e2c5be39d1e1e70be716960546015446efce52e"
|
||||
checksum = "4dbb5216f79dee3f90aaeb07d1f6da5f5f52ebc1abc5cc269a3677387b1c75cc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-stream 0.3.4",
|
||||
@@ -8420,7 +8420,6 @@ dependencies = [
|
||||
"owo-colors",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"socket2",
|
||||
"surf",
|
||||
"tokio",
|
||||
"url",
|
||||
|
||||
@@ -29,7 +29,7 @@ jsonrpsee = { version = "0.16.2", features = ["jsonrpsee-ws-client", "jsonrpsee-
|
||||
url = "2.3.1"
|
||||
md5 = "0.7.0"
|
||||
local-ip-addr = "0.1.1"
|
||||
upnp-client = "0.1.7"
|
||||
upnp-client = "0.1.9"
|
||||
futures = "0.3.26"
|
||||
tokio = { version = "1.25.0", features = ["time"] }
|
||||
hyper = { version = "0.14.23", features = ["runtime", "client", "stream", "tcp", "http1", "http2"] }
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Dlna {
|
||||
) -> Result<Option<Box<dyn Player + Send>>, Error> {
|
||||
let mut player: Self = device.clone().into();
|
||||
let location = player.location.clone().unwrap();
|
||||
let device_client = futures::executor::block_on(DeviceClient::new(&location).connect())?;
|
||||
let device_client = futures::executor::block_on(DeviceClient::new(&location)?.connect())?;
|
||||
player.client = Some(MediaRendererClient::new(device_client));
|
||||
|
||||
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel::<DlnaPlayerCommand>();
|
||||
@@ -80,7 +80,7 @@ impl Dlna {
|
||||
) -> Result<Option<Box<dyn Browseable + Send>>, Error> {
|
||||
let mut player: Self = device.clone().into();
|
||||
let location = player.location.clone().unwrap();
|
||||
let device_client = futures::executor::block_on(DeviceClient::new(&location).connect())?;
|
||||
let device_client = futures::executor::block_on(DeviceClient::new(&location)?.connect())?;
|
||||
player.media_server_client = Some(MediaServerClient::new(device_client));
|
||||
Ok(Some(Box::new(player)))
|
||||
}
|
||||
@@ -425,7 +425,8 @@ impl DlnaPlayer {
|
||||
mut cmd_rx: mpsc::UnboundedReceiver<DlnaPlayerCommand>,
|
||||
) -> Self {
|
||||
let device_client =
|
||||
futures::executor::block_on(DeviceClient::new(location.as_str()).connect()).unwrap();
|
||||
futures::executor::block_on(DeviceClient::new(location.as_str()).unwrap().connect())
|
||||
.unwrap();
|
||||
let player_internal = Arc::new(Mutex::new(DlnaPlayerInternal {
|
||||
client: MediaRendererClient::new(device_client),
|
||||
tracklist,
|
||||
|
||||
@@ -18,4 +18,4 @@ md5 = "0.7.0"
|
||||
sea-orm = { version = "0.9.2", features = ["runtime-tokio-rustls", "sqlx-sqlite"] }
|
||||
serde = "1.0.145"
|
||||
chrono = "0.4.23"
|
||||
upnp-client = "0.1.6"
|
||||
upnp-client = "0.1.9"
|
||||
|
||||
@@ -72,4 +72,4 @@ serde = { version = "1.0.148", features = ["serde_derive"] }
|
||||
mdns-sd = "0.5.9"
|
||||
anyhow = "1.0.67"
|
||||
url = "2.3.1"
|
||||
upnp-client = "0.1.6"
|
||||
upnp-client = "0.1.9"
|
||||
|
||||
@@ -83,17 +83,18 @@ fn scan_chromecast_devices(devices: Arc<Mutex<Vec<Device>>>) {
|
||||
fn scan_upnp_dlna_devices(devices: Arc<Mutex<Vec<Device>>>) {
|
||||
thread::spawn(move || {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
let upnp_devices = discover_pnp_locations();
|
||||
tokio::pin!(upnp_devices);
|
||||
if let Ok(upnp_devices) = discover_pnp_locations().await {
|
||||
tokio::pin!(upnp_devices);
|
||||
|
||||
while let Some(device) = upnp_devices.next().await {
|
||||
if device.device_type.contains(MEDIA_RENDERER)
|
||||
|| device.device_type.contains(MEDIA_SERVER)
|
||||
{
|
||||
let mut devices = devices.lock().unwrap();
|
||||
if devices.iter().find(|d| d.id == device.udn).is_none() {
|
||||
devices.push(Device::from(device.clone()));
|
||||
SimpleBroker::<Device>::publish(Device::from(device.clone()));
|
||||
while let Some(device) = upnp_devices.next().await {
|
||||
if device.device_type.contains(MEDIA_RENDERER)
|
||||
|| device.device_type.contains(MEDIA_SERVER)
|
||||
{
|
||||
let mut devices = devices.lock().unwrap();
|
||||
if devices.iter().find(|d| d.id == device.udn).is_none() {
|
||||
devices.push(Device::from(device.clone()));
|
||||
SimpleBroker::<Device>::publish(Device::from(device.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "music-player-storage"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
edition = "2021"
|
||||
repository = "https://github.com/tsirysndr/music-player"
|
||||
license = "MIT"
|
||||
|
||||
@@ -5,8 +5,8 @@ use tantivy::{
|
||||
collector::TopDocs,
|
||||
directory::MmapDirectory,
|
||||
doc,
|
||||
query::{FuzzyTermQuery, PhraseQuery},
|
||||
schema::{Schema, SchemaBuilder, STORED, STRING, TEXT},
|
||||
query::{FuzzyTermQuery, PhraseQuery, TermQuery},
|
||||
schema::{IndexRecordOption, Schema, SchemaBuilder, STORED, STRING, TEXT},
|
||||
Document, Index, IndexReader, ReloadPolicy, Term,
|
||||
};
|
||||
|
||||
@@ -59,6 +59,15 @@ impl AlbumSearcher {
|
||||
let year = self.schema.get_field("year").unwrap();
|
||||
let cover = self.schema.get_field("cover").unwrap();
|
||||
|
||||
// check if album already exists
|
||||
let searcher = self.reader.searcher();
|
||||
let term = Term::from_field_text(id, &album.id);
|
||||
let query = TermQuery::new(term, IndexRecordOption::Basic);
|
||||
let top_docs = searcher.search(&query, &TopDocs::with_limit(1))?;
|
||||
if top_docs.len() > 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let doc: Document = doc!(
|
||||
id => album.id.clone(),
|
||||
title => album.title.clone(),
|
||||
|
||||
@@ -5,8 +5,8 @@ use tantivy::{
|
||||
collector::TopDocs,
|
||||
directory::MmapDirectory,
|
||||
doc,
|
||||
query::{FuzzyTermQuery, PhraseQuery},
|
||||
schema::{Schema, SchemaBuilder, STORED, STRING, TEXT},
|
||||
query::{FuzzyTermQuery, PhraseQuery, TermQuery},
|
||||
schema::{IndexRecordOption, Schema, SchemaBuilder, STORED, STRING, TEXT},
|
||||
Document, Index, IndexReader, ReloadPolicy, Term,
|
||||
};
|
||||
#[derive(Clone)]
|
||||
@@ -52,6 +52,17 @@ impl ArtistSearcher {
|
||||
let id = self.schema.get_field("id").unwrap();
|
||||
let name = self.schema.get_field("name").unwrap();
|
||||
|
||||
// Check if the artist already exists
|
||||
let searcher = self.reader.searcher();
|
||||
let query = TermQuery::new(
|
||||
Term::from_field_text(name, artist.name.as_str()),
|
||||
IndexRecordOption::Basic,
|
||||
);
|
||||
let top_docs = searcher.search(&query, &TopDocs::with_limit(1))?;
|
||||
if top_docs.len() > 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let doc: Document = doc!(
|
||||
id => artist.id.clone(),
|
||||
name => artist.name.clone(),
|
||||
|
||||
@@ -5,8 +5,8 @@ use tantivy::{
|
||||
collector::TopDocs,
|
||||
directory::MmapDirectory,
|
||||
doc,
|
||||
query::{FuzzyTermQuery, PhraseQuery},
|
||||
schema::{Schema, SchemaBuilder, STORED, STRING, TEXT},
|
||||
query::{FuzzyTermQuery, PhraseQuery, TermQuery},
|
||||
schema::{IndexRecordOption, Schema, SchemaBuilder, STORED, STRING, TEXT},
|
||||
Document, Index, IndexReader, ReloadPolicy, Term,
|
||||
};
|
||||
#[derive(Clone)]
|
||||
@@ -67,6 +67,15 @@ impl TrackSearcher {
|
||||
let artist_id = self.schema.get_field("artistId").unwrap();
|
||||
let album_id = self.schema.get_field("albumId").unwrap();
|
||||
|
||||
// Check if the song is already in the index
|
||||
let searcher = self.reader.searcher();
|
||||
let term = Term::from_field_text(id, str_id);
|
||||
let query = TermQuery::new(term, IndexRecordOption::Basic);
|
||||
let top_docs = searcher.search(&query, &TopDocs::with_limit(1))?;
|
||||
if top_docs.len() > 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let time = song.duration.as_secs_f32() as i64;
|
||||
|
||||
let doc: Document = doc!(
|
||||
|
||||
@@ -23,6 +23,6 @@ md5 = "0.7.0"
|
||||
mdns-sd = "0.5.9"
|
||||
minreq = { version = "2.6.0" }
|
||||
local-ip-addr = "0.1.1"
|
||||
upnp-client = "0.1.6"
|
||||
upnp-client = "0.1.9"
|
||||
url = "2.3.1"
|
||||
tantivy = "0.19.2"
|
||||
|
||||
Reference in New Issue
Block a user