Files
Christian Krakau-Louis 2f55f898ed Add Spotify integration with improved token management and user interface
- Implemented Spotify OAuth handling in spotify_client_manager.py to ensure valid access tokens for users.
- Created helper functions in spotify_helper.py for refreshing tokens and retrieving user information.
- Developed manage_spotify.html template for connecting and managing Spotify accounts, displaying connection status and token information.
- Added logging for token management processes to enhance debugging and monitoring.
- Introduced a debug client for Spotify interactions to facilitate easier testing and development.
2025-05-27 21:40:37 +02:00

29 KiB
Raw Permalink Blame History

Thanks, thats perfect context. Ill now identify high-quality, scrape-friendly sources for historical and current music charts focused on US, UK, Ireland, Germany, and broader Europe. Ill also dig into the types of metadata these sources provide—like chart placements, debut dates, and impact metrics—and explore how to enrich your existing Song model with this info. Ill get back to you shortly with detailed findings and scraper strategy recommendations.

High-Quality Sources for Music Chart Data (US, UK, Ireland, Germany, Europe)

Official Sources for Chart Data

Billboard (US Billboard Charts)

  • Description & Scope: Billboard is the standard for U.S. music charts, including the weekly Hot 100 (singles) and Billboard 200 (albums), among many others. It covers all genres and is widely regarded as an authoritative source. Historical data spans from the Hot 100s start in 1958 to the present.
  • Available Metadata: Weekly charts list each songs current rank, song title, artist, as well as meta-data like last weeks position, peak position, and weeks on chart. For example, each Hot 100 entry includes Last Week, Peak Position, and Weeks on Chart in addition to the title and artist. (Commentary or editorial notes are sometimes provided in articles but not as structured data in the chart listing.)
  • Access Method: Data can be scraped from Billboards website via HTML pages. Each chart has a structured URL (e.g. billboard.com/charts/hot-100/<DATE> where <DATE> is a Monday chart date in YYYY-MM-DD format) to access a specific weeks Hot 100. The site displays 100 entries per page with the relevant fields. There is no free official API (Billboards old API was shut down in 2013), but the HTML is parseable. Third-party solutions exist (e.g. the billboard.py Python module or RapidAPI endpoints) which essentially scrape these pages in a controlled way.
  • Frequency & Archive Depth: Billboard charts are updated weekly (typically once a week, with charts dated to the week-ending Saturday). Archives are extensive the Hot 100 archive goes back to 1958. Older charts can be accessed by specifying historical dates; Billboards site allows navigating by week, or using third-party scrapers to iterate dates. For example, one can fetch the Hot 100 for a given past date by using the URL format or a library. Peak positions and weeks-on-chart are cumulatively tracked (so even an older entry will show its historical peak and total weeks up to that point).
  • Legal/Technical Considerations: Scraping Billboards site must be done respectfully to avoid IP blocks e.g. rate-limit requests since its a dynamic content site. Billboard content is copyrighted, so reuse of large datasets commercially may violate terms; its best to use the data for internal analysis or ensure you have rights for any public use. Technically, the sites HTML includes the needed info in a consistent format (making it amenable to scraping), but be aware that Billboard may change its layout periodically. An alternative is to use unofficial JSON data compiled by others (for example, a GitHub project that scraped every Hot 100 entry includes fields like last_week, peak_position, weeks_on_chart) but if freshness and official sourcing are priorities, direct scraping or licensed API access is preferable.

Official Charts Company (UK & Ireland Official Charts)

  • Description & Scope: The Official Charts Company (OCC) provides the official weekly charts for the UK and, in partnership with IRMA, the Republic of Ireland. This includes the Official UK Singles Chart Top 100 and Albums Chart, and the Official Irish Singles Top 50 and Albums, among others. The OCC site is a comprehensive repository for British chart history (with data back to the 1950s) and also hosts Irish charts (the Irish Singles Chart is compiled by OCC for IRMA).
  • Available Metadata: Chart listings on officialcharts.com show each songs position, title, artist, and key metadata: Last week (LW) position, Peak to-date, and Weeks on Chart. New entries or re-entries are indicated by a blank or special notation for last week. The site also provides richer detail on dedicated pages for each track: clicking a song leads to a page with chart facts such as Peak position, First charted date (debut date), total weeks on chart, label, and even a week-by-week chart run history. For example, a songs page might show “Peak position: 1, First Chart Date: 27/02/2025” along with a list of its position on each week of its chart run. This means the data source can yield not only the current weeks stats but also historical context (debut date and trajectory).
  • Access Method: The OCC website is accessible via HTML. Charts can be accessed through structured URLs: for instance, the UK Singles Top 100 usually at officialcharts.com/charts/uk-top-40/<DATE>, and the Irish Singles at .../irish-singles-chart/<DATE>/. The <DATE> is typically the chart week ending date or an identifier; the site has an archive navigation that can generate the URL (e.g., an Irish chart URL looks like .../irish-singles-chart/20250221/ie7501/ for the week of Feb 21, 2025). In many cases, if no date is given, the URL shows the latest chart, and older charts are retrieved by inserting the week ID. No public API is provided, but HTML scraping is feasible. Each chart page lists 100 entries (for UK) or 50 (for Ireland) in a consistent format, which can be parsed. The site is mostly static content (one page per chart week), making it straightforward to script through archive pages.
  • Frequency & Archive Depth: Charts are updated weekly. The UK charts are typically refreshed every Friday (reflecting sales/streams through Thursday night), and Irish charts weekly as well. Archive depth is very deep: the OCCs database includes every UK weekly chart back to November 1952 for singles and to 1956 for albums. (They merged older charts like NME into the official archive.) The website allows browsing these historical charts (the “Archive” feature). Many specialty UK charts (like genre-specific or sales-only charts) are available from 1994 onward. The Irish chart archive on OCCs site covers the period since the OCC took over compilation (in recent years); earlier Irish data (from 1960s onward) might not be fully on the OCC site, but IRMAs own site provides all-time records in a less accessible format.
  • Legal/Technical Considerations: The OCC sites content is subject to database rights they famously protect their data. Automated scraping may violate their terms if done extensively, so it should be done carefully (and only for legitimate use). In practical terms, the HTML is easily parseable (entries are in a predictable structure with position and meta fields). Be mindful of not overwhelming the server throttle requests or cache results, especially if pulling decades of weekly data. Also note that some data (like full chart runs or certain archives) might require login or might be rate-limited if done via the front-end interface. Generally, however, basic weekly charts are publicly viewable. Make sure to preserve attribution (for internal use, keep track of OCC as the source in your metadata_sources field).

GfK Offizielle Deutsche Charts (Germany)

  • Description & Scope: The Offizielle Deutsche Charts (managed by GfK Entertainment for the Bundesverband Musikindustrie) are the official German music charts. The main charts include the Top 100 Singles and Top 100 Albums (weekly), and the site also features a variety of genre and format charts (e.g., Top 20 for genres like Dance, Rock/Metal, etc., plus Midweek and Year-end charts). This source covers Germanys chart data comprehensively, with an archive of almost 40 years of history available online.
  • Available Metadata: The German chart portal provides structured data for each entry: current rank, previous weeks rank, title, artist (including featured artists, separated by slashes or ampersands), and the record label. It also lists the songs weeks on chart and peak position to date as inline metadata. For example, an entry might read: “1 1 DNA feat. Suzanne Vega Toms Diner (A&M/Polydor) In Charts: 6 W Peak: 1”, indicating the song is at #1, was #1 last week, has spent 6 weeks in the charts, and peaked at #1. New entries are shown with no previous rank (or a dash) and typically “In Charts: 1 W” as weeks. Re-entries can be detected when a song has weeks >1 but no prior week position listed. (The site does not explicitly give the debut date on the listing page, but the first chart date can be inferred by looking at the archive and the site includes artist pages/discographies with “Erstchartdatum” if logged in).
  • Access Method: The official German charts site offiziellecharts.de is interactive, but can be scraped via its internal endpoints. The charts are displayed by selecting a date range; under the hood, the site uses a call like .../charts/single/for-date-<timestamp> to fetch the HTML snippet for that week. For scraping, one approach is to simulate weekly date selections. Each weekly chart corresponds to a Friday-to-Thursday period; for example, the week 01.10.1990 07.10.1990 has an internal identifier (timestamp) used in the URL. By incrementing by 7-day intervals (604800000 ms in timestamp), one can retrieve consecutive weeks. Alternatively, the site provides dropdowns to navigate; you could scrape by programmatically selecting dates (the HTML of the “for-date” response contains the full Top 100 list). No public API is provided by GfK for chart data the official route is paid reports so HTML scraping is the viable approach. The data is well-structured in the HTML, but note its in German (e.g., “In Charts: X W”).
  • Frequency & Archive Depth: The German charts are updated weekly, with the new Top 100 released every Friday afternoon (reflecting sales/streams from FridayThursday, following a 2015 change to align release day and chart day). The site also posts midweek updates on Wednesdays (Top 20/100 midweeks) and daily trends (these might be behind login or press releases). Archive depth: The online archive covers all weekly charts since the start of the modern German charts data collection by Media Control/GfK (the portal boasts a complete archive “seit Beginn der Datenermittlung,” i.e., since official electronic chart data began). In practice, this means you can find weekly charts from the early 1980s (and even late 1970s) onward. For example, charts from 1990 are readily accessible, and one can retrieve even earlier 1980s charts. (Earlier historical German charts from the 1950s60s are not part of this electronic archive because those were published in magazines, but from about 1977 forward, its complete).
  • Legal/Technical Considerations: The Offiziellecharts site is intended for user exploration and is free to browse, but scraping should be done gently. The site may use JavaScript to load content, so a scraper might need to either replicate the XHR calls (as mentioned) or use a headless browser approach. Since this is an official industry site, its robots.txt may disallow scraping (worth checking). As with other official data, it is protected by copyright/database rights; using it for commercial purposes would require permission. GfK offers the data via subscription, implying that heavy automated use could be frowned upon. However, for internal use and research, pulling the data with moderation (and attributing it) is typically acceptable. Also note that the site requires character encoding handling (umlauts in titles, etc.) and that labels and artist names are exactly as listed (might need normalization when matching with your database).

Pan-European Chart Sources (Europe-wide)

  • Description & Scope: A pan-European chart aggregates music popularity across Europe. The primary historic source was the Eurochart Hot 100 Singles (also known as the European Hot 100) which was compiled by Music & Media magazine and later by Billboard from 1984 until it was discontinued in December 2010. This chart combined national singles charts from across European countries into a single top 100 ranking. After 2010, there has been no official unified European singles chart. (Billboard did maintain a Euro Digital Songs chart (top 10 digital sales in Europe) until Feb 2022, but that is a limited subset.) For albums, a European Top 100 Albums chart also existed during that period via Music & Media.
  • Available Metadata: During its run, the Eurochart Hot 100 provided weekly ranks for songs. In Music & Media magazine issues, each entry was listed with its current position, song and artist, and often last weeks position or a country-by-country breakout in some cases. However, as a scraped dataset today, you wont find a readily queryable official site with structured fields (since the service ended). What is available are archives and scanned data: for example, the World Radio History library hosts PDF scans of Music & Media (and the Eurotipsheet) which contain the weekly Eurochart listings. These scans include all the info (positions 1100 each week, and sometimes peak or weeks if mentioned in year-end summaries). If one processes these, one can obtain fields like rank, song, artist, and sometimes flags for new entries or notable movements. Additionally, fan-maintained databases or wiki pages have captured parts of this data. For instance, the Billboard fandom wiki and other chart archives might list the number-ones or top 20 of each week.
  • Access Method: Since there is no official live website for historical Eurocharts, accessing this data means relying on archives or third-party compilations. Two main approaches: (1) Archive scraping using sources like the PDFs on worldradiohistory.com which has Music & Media issues (1980s2000s). One could scrape text from these PDFs (OCR or text extraction) to build a dataset of the Eurochart. This requires substantial effort and parsing of semi-structured text. (2) Third-party websites e.g., top40-charts.com provides a “Europe Official Top 100” which appears to be an aggregated chart updated weekly, and sites like acharts.co or ChartsAroundTheWorld track multiple countries (though a specific Eurochart might not be explicitly given, some provide a “Europe” section). The top40-charts.com version might not be an official industry-sanctioned chart, but it could be scraped via HTML as it presents a ranked list of songs for Europe. If a more current pan-European perspective is needed, one might also use the Billboard Global Excl. US chart as a proxy (since European songs would dominate there, though its global minus US, not Europe-only).
  • Frequency & Archive Depth: The historical Eurochart was weekly (matching the Billboard publication cycle). Archives exist for 19842010 weekly. If using WorldRadioHistory, one can get nearly every weeks chart in that range. The Euro Digital Songs chart (2000s2022) was also weekly; Billboards site had those top 10 lists (which could be scraped for those years if needed, via billboard.com, similar method as Hot 100 but chart name “Euro Digital Song Sales”). The top40-charts.com “Europe Top 100” is updated weekly in current time. There is no single official archive for pan-Europe after 2010, so any post-2010 “Euro chart” is either unofficial or derived from combining national charts.
  • Legal/Technical Considerations: The Music & Media Eurochart data is © Billboard/BPI etc. Since its historical and out-of-print, using it for research is usually fine, but any republishing of a compiled Eurochart database might violate copyrights (the OCC, for instance, objected to unlicensed archive postings of UK charts, and similar could apply to Eurocharts). Scraping the PDFs is technically challenging (OCR needed for uniformity). If using a site like top40-charts.com, note that its not an official source and the methodology might not be transparent but it is a convenient HTML source. Ensure your scraping code handles variations in song naming and that you verify if the sites “Europe Official Top 100” indeed corresponds to an aggregate of official data. Also, as always, be mindful of load; if pulling large historical data from a fan site, do so politely. In summary, for pan-European data, high-quality officially means historical reconstruction (and perhaps supplementing with the now-ended Euro Digital Songs). This data can then be mapped into your system similar to national charts.

Comparison of Identified Sources

Source (Region) Metadata Provided Access Method Archive Depth & Update Scraping Considerations
Billboard (US) Rank, Title, Artist; Last Week, Peak, Weeks on Chart for each song. Some charts include icons for “Greatest Gainer” etc. HTML pages on Billboard.com (structured URLs per chart and date); unofficial API wrappers available. Weekly updates; archives back to 1958 (Hot 100). All weekly charts accessible via date queries (manual or scripted). No free official API; site can throttle heavy use use rate limiting. Data copyrighted (for internal use unless licensed).
Official Charts (UK & IRL) Rank, Title, Artist; Last Week, Peak, Weeks on chart. Song pages give debut date and full run. HTML pages on officialcharts.com (with endpoints for each chart and date). No public API. Weekly; UK data back to 1952 (complete archive), Ireland back to at least 1990s (OCC era). Current charts on site, historical via archive picker. Strong copyright enforcement by OCC. Scrape gently. Structured HTML easy to parse. Some details (full runs) may need clicking into song pages.
Offizielle Charts (Germany) Rank, Title, Artist(s), Label; Prev Week rank, Weeks on chart, Peak to-date. (German titles/labels as listed.) Interactive HTML site (offiziellecharts.de). Scrape via XHR endpoint (e.g. /charts/<category>/for-date-<timestamp>). Weekly; archive from ~1977/1980s onward (almost 40 years). Full Top100 available for each week. Updates every Friday (midweeks on Wed). Dynamic content (JS) may need to simulate calls. Data is official and comprehensive. Throttle requests. Content in German (take care with encoding).
Pan-European (Eurochart) Rank, Title, Artist as published. Historical last week or country breakdowns in magazines. (No live peak/weeks metadata after the fact without computing yourself.) Archive PDFs (Music & Media magazine scans) or third-party chart sites. No official website post-2010. Weekly (historical 19842010 for Euro Hot 100). No current official chart; some sites provide unofficial weekly Euro Top 100. Data must be reconstructed. Scraping PDFs requires OCR. Third-party “Euro charts” may not be official. Ensure legality if using historical data; likely okay for research.

Mapping Scraped Data to the Song Model

Once chart data is scraped from the above sources, the next challenge is integrating it with your existing Song model. Below are recommendations for linking and enriching your song records with the new metadata:

  • Linking by Unique Identifier (ISRC): Whenever possible, use a stable identifier like the ISRC to match scraped songs to your database. Official chart sources sometimes provide identifiers for example, the Official Charts site lists a “Catalogue number” for each song, which often corresponds to an ISRC or label catalog code. If your Song model stores ISRCs (or you can obtain them via an external lookup by song title/artist), matching on ISRC is most reliable for linking the exact same recording. This helps avoid issues with songs that have common titles or multiple versions. Recommendation: parse any available code from sources (e.g., OCCs catalogue number, or use the song+artist to query an external service for ISRC) and store it in the Song record for future cross-referencing.

  • Linking by Title/Artist (Exact or Fuzzy): In many cases, chart data will have only the song title and artist name. You should prepare to do a robust string match against your Song records:

    • Start with normalized exact matching: Normalize the scraped title and artist strings (trim punctuation, convert to a standard case, remove common suffixes like “(feat. X)” or “feat. X” if your DB doesnt store them, etc.) and compare to your song entries. If your Song model has separate fields for title and artist(s), ensure both match.
    • Handle feat./collaboration variations: Chart listings might abbreviate or include featured artists differently than your database. For example, a song listed as “Artist A & Artist B” on a chart might be “Artist A feat. Artist B” in your database. Consider using a fuzzy matching library or custom logic to account for ampersands, “x”, “feat.”, etc., so that these count as a match.
    • Fuzzy matching: If exact match fails, employ a fuzzy string match (Levenshtein distance or token-based matching) on title + primary artist. This can catch minor spelling differences or punctuation mismatches. For instance, “Beyonce” vs “Beyoncé” or “Hips Dont Lie” vs “Hips Dont Lie” (missing apostrophe) would be caught by a fuzzy match.
    • Manual review for edge cases: Flag any ambiguous matches (like two songs with the same title in your database) for human verification or use additional data (like release year or genre) to pick the correct one.
  • Populating Song Fields with Chart Metadata: Once a song is identified, decide which fields in your Song model to update:

    • metadata_sources: Its good practice to record where information came from. For each song, add an entry noting the chart source and perhaps the specific chart name and date range. For example, for a song that charted, you might add "Billboard Hot 100 (peak #5, 20 weeks)" or a structured object detailing peak and weeks. At minimum, store that the song has data from “Billboard Hot 100” or “Official Charts UK” etc., so you know which sources confirmed its popularity.
    • year: If your Song model has a year (often release year or year of greatest popularity), you can use chart debut year as a proxy if the release year is missing. For instance, if a song first appears on a chart in 2021, its likely a 2020 or 2021 release. Chart data gives you the debut date or first chart year (OCC explicitly gives first chart date). You might update the songs year field if its empty or if you want to store “year first popular”. (Be cautious not to override an actual release year if you have it; perhaps store chart year separately or only fill if year was unknown.)
    • genre: Chart sources typically do not provide genre per track. However, chart context can imply something (e.g., if you scraped a genre-specific chart like “Rock/Metal Charts” from Germany, you know those songs are rock). For mainstream pop charts like Hot 100 or UK Top 100, the genre will be varied. Its usually better to get genre from another source. If your model has genre and its empty, you might consider using the presence on a genre chart as a clue (e.g., if a song appears on “US Hot Country Songs”, tag its genre as Country).
    • tags: This is where you can richly annotate the song with chart-related information. See next point on chart milestone tags.
  • Adding Tags for Chart Achievements: To enhance the dataset, create new tags based on the songs chart performance milestones:

    • For example, if a song reached #1 on the UK Official Singles Chart, add a tag like “UK #1 Hit” to that song. This highlights a major achievement.
    • If a song made the Top 10 on a chart, you can tag it “Billboard Top 10” or “UK Top 10”. Some songs might get multiple tags (e.g. a song that hit #1 in the US and Top 10 in UK gets both “US #1” and “UK Top 10”). Decide on a consistent tagging scheme (perhaps “Billboard Hot 100 #1”, “UK Official Chart Top10”, etc.).
    • You could also tag long chart runs or notable records: e.g. “20+ Weeks on Hot 100”, “Christmas #1 UK” (for the UKs holiday chart-toppers), “Eurochart Top 5”, depending on what insights you want to surface. These tags can later be used for generating playlists or highlighting songs in your app.
    • Consider automated rules: e.g., if peak_position == 1 on a given chart, generate a “ #1” tag; if peak_position <= 10, generate “ Top 10”, etc. This way, as you update chart data, tags are consistently applied.
  • Data Model Extensions (if needed): If your current Song model doesnt have a place for detailed chart info, you have options:

    • Use an auxiliary table or object for chart entries (SongChartPerformance with fields: song_id, chart_name, peak, weeks, debut_date, etc.). This is more structured but requires schema changes. It might be worthwhile if you plan extensive analytics.
    • If not, storing summary info in tags/metadata as described is fine for many use cases. Tags are flexible for queries (e.g., one can query all songs with tag “US #1 Hit”). The drawback is tags are untyped strings, but theyre quick to implement.
    • Another field you might utilize is a “chart history” blob in metadata_sources or a JSON field, where you keep the raw info (like an array of weekly positions or a highest achievement summary). For example, you could store: {"Billboard Hot 100": {"peak": 5, "weeks": 20, "debut_date": "2021-05-01"}} in a JSON field. This preserves more detail in a structured way.
  • Quality Assurance Matching Validation: After linking and populating, its good to run a sanity check. For instance, verify that the number of songs tagged as #1 matches the number of #1 entries scraped, etc. Also, for any songs where the scraper found a chart entry but no match in your database, log those for review you might have the song under a slightly different name or not have it at all (perhaps add it as a new Song entry if its missing and the project allows).

By following these steps, you will enrich your Song model with valuable chart metadata. Youll have tags highlighting hits (“UK #1”, “Germany Top 5”, etc.), year and source info to contextualize each song, and a robust linking using identifiers or fuzzy logic to ensure accuracy. This integration will allow you to query, for example, all songs that were hits in multiple countries, or display on a songs page something like “🏆 Chart Achievements: #1 in UK, Top 10 in US (20 weeks on chart)” drawn from the data youve mapped.

By leveraging the above high-quality sources and carefully mapping the data, you can significantly enhance the informational richness of your music database while maintaining data integrity and respecting the sources terms.

Sources:

  • Billboard Charts data fields (song, artist, current rank, last week, peak, weeks)
  • Official Charts Company UK and Irish chart listings and archive info
  • OCC song page example (peak, first chart date, etc.)
  • Offizielle Deutsche Charts data fields and archive confirmation
  • European Hot 100 (Billboards pan-European chart) history