Compare commits

..
2 Commits
Author SHA1 Message Date
Sweetbread 96321573ee Rename confusing var 2026-01-14 17:21:57 +03:00
Sweetbread 1790750e0a Replace Playing status with Listening 2026-01-14 17:18:58 +03:00
2 changed files with 20 additions and 64 deletions

No files matched your search

Generated
+6 -6
View File
@@ -5,11 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1731533236, "lastModified": 1705309234,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1768395095, "lastModified": 1707711327,
"narHash": "sha256-ZhuYJbwbZT32QA95tSkXd9zXHcdZj90EzHpEXBMabaw=", "narHash": "sha256-JaiR0Er0Bx80CT5POOYR1I1tLM7VvC2/ny6mOmkoRQw=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "13868c071cc73a5e9f610c47d7bb08e5da64fdd5", "rev": "01737456dfe4907fb5bdc8af39ac8c6d6b1fb551",
"type": "github" "type": "github"
}, },
"original": { "original": {
+14 -58
View File
@@ -4,7 +4,7 @@ use core::time;
use std::{collections::{HashMap, HashSet}, env, error::Error, thread}; use std::{collections::{HashMap, HashSet}, env, error::Error, thread};
use discord_presence::{ use discord_presence::{
models::{ActivityType, DisplayType}, models::ActivityType,
Client, Event, Client, Event,
}; };
use dotenv::dotenv; use dotenv::dotenv;
@@ -57,35 +57,18 @@ fn main() -> Result<(), Box<dyn Error>> {
debug!("Cached cover failure"); debug!("Cached cover failure");
None None
} else { } else {
let youtube_cover_url = metadata.additional_info.as_ref() let url = lb.cover_art(&track, &artist, release_name.as_deref(), 0);
.and_then(|info| info.music_service_name.as_ref())
.filter(
|service|
["YouTube", "YouTube Music"].contains(&service.as_str())
)
.and_then(|_| metadata.additional_info.as_ref())
.and_then(|info| info.origin_url.as_ref())
.and_then(|url| extract_youtube_video_id(url))
.map(|video_id| format!(
"https://img.youtube.com/vi/{}/sddefault.jpg",
video_id
));
if let Some(url) = youtube_cover_url { match url {
cover_cache.insert(hash_key.clone(), url.clone()); Ok(a) => {
Some(url) cover_cache.insert(hash_key, a.clone());
} else { Some(a)
match lb.cover_art(&track, &artist, release_name.as_deref(), 0) { },
Ok(url) => { Err(e) => {
cover_cache.insert(hash_key.clone(), url.clone()); error!("Error fetching cover_art: {}", e);
Some(url) cover_failure_cache.insert(hash_key);
}, None
Err(e) => { },
error!("Error fetching cover_art: {}", e);
cover_failure_cache.insert(hash_key);
None
},
}
} }
}; };
@@ -93,14 +76,13 @@ fn main() -> Result<(), Box<dyn Error>> {
// TODO: Add buttons // TODO: Add buttons
let mut t = act let mut t = act
.activity_type(ActivityType::Listening) .activity_type(ActivityType::Listening)
.status_display(DisplayType::State)
.state(artist.clone()) .state(artist.clone())
.details(track.clone()); .details(track.clone());
if let Some(cover_url) = cover_art { if let Some(url) = cover_art {
t = t.assets(|ass| { t = t.assets(|ass| {
ass ass
.large_image(cover_url) .large_image(url)
.large_text(format!("{} - {}", &track, &artist)) .large_text(format!("{} - {}", &track, &artist))
}) })
} }
@@ -113,29 +95,3 @@ fn main() -> Result<(), Box<dyn Error>> {
thread::sleep(time::Duration::from_secs(15)); thread::sleep(time::Duration::from_secs(15));
} }
} }
fn extract_youtube_video_id(url: &str) -> Option<&str> {
let patterns = [
"youtube.com/watch?v=",
"youtu.be/",
"youtube.com/v/",
"youtube.com/embed/",
];
for pattern in patterns.iter() {
if let Some(pos) = url.find(pattern) {
let start = pos + pattern.len();
let end = url[start..]
.find(|c: char| !c.is_alphanumeric() && c != '_' && c != '-')
.map(|end_pos| start + end_pos)
.unwrap_or(url.len());
let video_id = &url[start..end];
if !video_id.is_empty() {
return Some(video_id);
}
}
}
None
}