Spotify Denmark chart history from kworb: every song that charted, weekly history since it charted, daily from now on

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 01:19:40 +00:00
co-authored by Claude Opus 5.5
parent ccae36e11a
commit ff5c8e939c
2 changed files with 150 additions and 2 deletions
+16 -2
View File
@@ -1,6 +1,6 @@
//! airplay: collects what Danish radio stations play, for modelling when artists get played again.
//!
//! airplay collect [--db data/airplay.db] [--days 7] [--all-bauer] [--only dr|bauer|hitlisten|deezer|musicbrainz] [--backfill]
//! airplay collect [--db data/airplay.db] [--days 7] [--all-bauer] [--only dr|bauer|hitlisten|deezer|musicbrainz|spotify] [--backfill]
//! airplay stats [--db data/airplay.db]
//! airplay check [--db data/airplay.db] gaps, duplicates, DR cross-check, chart completeness
//!
@@ -15,6 +15,7 @@ mod dr;
mod hitlisten;
mod http;
mod musicbrainz;
mod spotify;
use anyhow::Result;
use chrono::Utc;
@@ -36,7 +37,7 @@ fn main() -> Result<()> {
Some("stats") => stats(&db),
Some("check") => check::run(&db),
_ => {
eprintln!("usage: airplay collect [--db FILE] [--days 7] [--all-bauer] [--only dr|bauer|hitlisten|deezer|musicbrainz] [--backfill]\n airplay stats [--db FILE]\n airplay check [--db FILE]");
eprintln!("usage: airplay collect [--db FILE] [--days 7] [--all-bauer] [--only dr|bauer|hitlisten|deezer|musicbrainz|spotify] [--backfill]\n airplay stats [--db FILE]\n airplay check [--db FILE]");
std::process::exit(2);
}
}
@@ -92,6 +93,12 @@ fn collect(db: &db::Db, args: &[String], db_path: &str) -> Result<()> {
let r = musicbrainz::collect(db, &mb_http, arg(args, "--limit").and_then(|l| l.parse().ok()).unwrap_or(if backfill { usize::MAX } else { 2000 }), &mut log);
step("musicbrainz release dates", r.map(|n| format!("{n} ISRCs looked up")), &mut log);
}
if wants("spotify") {
// kworb.net is a one-person site: one request a second.
let kworb_http = http::Http::new(1000)?;
let r = spotify::collect(db, &kworb_http, arg(args, "--limit").and_then(|l| l.parse().ok()).unwrap_or(if backfill { usize::MAX } else { 400 }), &mut log);
step("spotify chart history (kworb)", r.map(|(l, p)| format!("{l} songs listed, {p} histories read")), &mut log);
}
if wants("hitlisten") {
let r = hitlisten::collect(db, &http, if backfill { usize::MAX } else { 60 }, &mut log);
step("hitlisten airplay chart", r.map(|n| format!("{n} weeks fetched")), &mut log);
@@ -131,6 +138,13 @@ fn stats(db: &db::Db) -> Result<()> {
(SELECT count(*) FROM deezer_tracks), (SELECT count(*) FROM deezer_albums),
(SELECT count(*) FROM deezer_albums WHERE coalesce(label, '') != '')", [],
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?, r.get(4)?)))?;
spotify::create_tables(db)?;
let (sp_tracks, sp_read, sp_rows, sp_from): (i64, i64, i64, Option<String>) = db.conn.query_row(
"SELECT (SELECT count(*) FROM spotify_dk_tracks), (SELECT count(*) FROM spotify_dk_tracks WHERE history_fetched_at IS NOT NULL),
(SELECT count(*) FROM spotify_chart_history WHERE country = 'DK'),
(SELECT min(date) FROM spotify_chart_history WHERE country = 'DK' AND chart = 'daily')", [],
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?)))?;
println!("Spotify Denmark: {sp_tracks} songs that charted, {sp_read} histories read, {sp_rows} DK chart rows (daily from {})", sp_from.unwrap_or_default());
musicbrainz::create_tables(db)?;
let (mb, mb_known): (i64, i64) = db.conn.query_row(
"SELECT count(*), count(*) FILTER (WHERE recordings > 0) FROM mb_isrc", [], |r| Ok((r.get(0)?, r.get(1)?)))?;