Compare commits
No commits in common. "4d16d2530b390f81f8fa7ad5d05782376b0eafe3" and "973af875ad71998a74d69a20795d23f780bd1d61" have entirely different histories.
4d16d2530b
...
973af875ad
6 changed files with 37 additions and 100 deletions
|
@ -130,18 +130,7 @@ impl Extractor {
|
|||
if let Some(sp) = &self.sp {
|
||||
if requirements.check_req(SyncKind::Genres) {
|
||||
// Get a few tracks to try and find on Spotify
|
||||
if let Err(e) = sp.update_artist_genres(res.c).await {
|
||||
if let Some(sync_data) = util::error_to_sync_data(&e) {
|
||||
Artist::set_last_sync(
|
||||
res.c,
|
||||
SyncKind::Genres,
|
||||
sync_data,
|
||||
&self.core.db,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
warn!("error fetching Spotify artist for #{}: {}", res.c, e);
|
||||
}
|
||||
sp.update_artist_genres(res.c).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -500,75 +500,47 @@ impl YouTubeExtractor {
|
|||
return Ok(Err(None));
|
||||
};
|
||||
let t1 = self.core.matchmaker.parse_title(name);
|
||||
let a1 = self.core.matchmaker.parse_artist(artist);
|
||||
|
||||
// Attempt to find the track by searching YouTube for its ISRC id
|
||||
// If the title of the first search result matches, return this track.
|
||||
if let Some(isrc) = isrc {
|
||||
match CONFIG.extractor.youtube.isrc_search {
|
||||
tiraya_utils::config::IsrcSearchMode::Ytm => {
|
||||
let res = self.rp.query().music_search_tracks(isrc).await?;
|
||||
if let Some(t) = res.items.items.into_iter().next() {
|
||||
let t2 = self.core.matchmaker.parse_title(&t.name);
|
||||
let a2 = self.core.matchmaker.parse_artist(
|
||||
&t.artists
|
||||
.first()
|
||||
.map(|a| a.name.to_owned())
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let score = self.core.matchmaker.match_track(&t1, &a1, &t2, &a2, false);
|
||||
if self.core.matchmaker.is_match(score) {
|
||||
tracing::info!(
|
||||
"matched track `{name}` [{src_id}] => `{0}` [yt:{1}] (ISRC, {score:.2})",
|
||||
t.name,
|
||||
t.id
|
||||
);
|
||||
return Ok(Ok((
|
||||
self.import_track_item(t, None, &[], None, false).await?,
|
||||
score,
|
||||
)));
|
||||
}
|
||||
let filter = SearchFilter::new()
|
||||
.item_type(rustypipe::param::search_filter::ItemType::Video)
|
||||
.verbatim();
|
||||
let res = self.rp.query().search_filter(isrc, &filter).await?;
|
||||
if let Some(rpmodel::YouTubeItem::Video(video)) = res.items.items.first() {
|
||||
let t2 = self.core.matchmaker.parse_title(&video.name);
|
||||
let score = self.core.matchmaker.match_name(&t1, &t2);
|
||||
if self.core.matchmaker.is_match(score) {
|
||||
tracing::info!(
|
||||
"matched track `{name}` [{src_id}] => `{0}` [yt:{1}] (ISRC, {score:.2})",
|
||||
video.name,
|
||||
video.id
|
||||
);
|
||||
|
||||
// Get the found track either from YT or the database
|
||||
let track = if let Some(track) =
|
||||
Track::get(Id::Src(&video.id, MusicService::YouTube), &self.core.db)
|
||||
.await
|
||||
.to_optional()?
|
||||
{
|
||||
track
|
||||
} else {
|
||||
let track_id = self._fetch_track(&video.id, false).await?;
|
||||
Track::get(track_id, &self.core.db).await?
|
||||
};
|
||||
|
||||
let album = AlbumSlim::get(track.album_id, &self.core.db).await?;
|
||||
if album.album_type != Some(AlbumType::Mv) {
|
||||
self.store_matching_artists(artists, &track.artists).await?;
|
||||
return Ok(Ok((track.id, score)));
|
||||
}
|
||||
}
|
||||
tiraya_utils::config::IsrcSearchMode::Yt => {
|
||||
let filter = SearchFilter::new()
|
||||
.item_type(rustypipe::param::search_filter::ItemType::Video)
|
||||
.verbatim();
|
||||
let res = self.rp.query().search_filter(isrc, &filter).await?;
|
||||
if let Some(rpmodel::YouTubeItem::Video(video)) = res.items.items.first() {
|
||||
let t2 = self.core.matchmaker.parse_title(&video.name);
|
||||
let score = self.core.matchmaker.match_name(&t1, &t2);
|
||||
if self.core.matchmaker.is_match(score) {
|
||||
tracing::info!(
|
||||
"matched track `{name}` [{src_id}] => `{0}` [yt:{1}] (ISRC, {score:.2})",
|
||||
video.name,
|
||||
video.id
|
||||
);
|
||||
|
||||
// Get the found track either from YT or the database
|
||||
let track = if let Some(track) =
|
||||
Track::get(Id::Src(&video.id, MusicService::YouTube), &self.core.db)
|
||||
.await
|
||||
.to_optional()?
|
||||
{
|
||||
track
|
||||
} else {
|
||||
let track_id = self._fetch_track(&video.id, false).await?;
|
||||
Track::get(track_id, &self.core.db).await?
|
||||
};
|
||||
|
||||
let album = AlbumSlim::get(track.album_id, &self.core.db).await?;
|
||||
if album.album_type != Some(AlbumType::Mv) {
|
||||
self.store_matching_artists(artists, &track.artists).await?;
|
||||
return Ok(Ok((track.id, score)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tiraya_utils::config::IsrcSearchMode::Off => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let a1 = self.core.matchmaker.parse_artist(artist);
|
||||
|
||||
// Find the track by searching for YT Music tracks/videos
|
||||
let search = self
|
||||
.rp
|
||||
|
|
|
@ -54,7 +54,9 @@ pub fn get_database_uri() -> String {
|
|||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use crate::{derive_db_name, derive_db_prefix};
|
||||
use std::env;
|
||||
|
||||
use crate::{connect_options, derive_db_name, derive_db_prefix, get_database_uri};
|
||||
|
||||
#[test]
|
||||
fn test_db_prefix() {
|
||||
|
@ -95,7 +97,6 @@ mod tests {
|
|||
assert_eq!(derive_db_name("postgresql:///").unwrap().len(), 32);
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn test_connect_options() {
|
||||
env::set_var("DATABASE_URL", "postgresql:///");
|
||||
|
@ -140,5 +141,4 @@ mod tests {
|
|||
env::remove_var("DATABASE_URL");
|
||||
let _ = get_database_uri();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -112,24 +112,6 @@ pub struct ConfigExtractorYouTube {
|
|||
/// Maximum number of concurrent requests per operation
|
||||
#[default(4)]
|
||||
pub concurrency: usize,
|
||||
/// Track ISRC search mode
|
||||
///
|
||||
/// Searching on `ytm` directly is the fastest, but is not available a lot of times.
|
||||
/// The alternative is searching on `yt` (the regular YouTube size) or disabling
|
||||
/// ISRC search (`off`).
|
||||
pub isrc_search: IsrcSearchMode,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum IsrcSearchMode {
|
||||
/// Search for ISRCs using YouTube Music
|
||||
Ytm,
|
||||
/// Search for ISRCs using regular YouTube
|
||||
#[default]
|
||||
Yt,
|
||||
/// Disable search for ISRCs
|
||||
Off,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, SmartDefault)]
|
||||
|
|
|
@ -30,7 +30,6 @@ Config(
|
|||
country: "US",
|
||||
n_retries: 2,
|
||||
concurrency: 4,
|
||||
isrc_search: yt,
|
||||
),
|
||||
spotify: ConfigExtractorSpotify(
|
||||
enable: true,
|
||||
|
|
|
@ -68,11 +68,6 @@ country = "US"
|
|||
n_retries = 2
|
||||
# Maximum number of concurrent requests per operation
|
||||
concurrency = 4
|
||||
# Track ISRC search mode
|
||||
# Searching on `ytm` directly is the fastest, but is not available a lot of times.
|
||||
# The alternative is searching on `yt` (the regular YouTube size) or disabling
|
||||
# ISRC search (`off`).
|
||||
isrc_search = "yt"
|
||||
|
||||
[extractor.spotify]
|
||||
enable = true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue