From 668bb0a30726ef4a928cb28290aa6ef95b1630f0 Mon Sep 17 00:00:00 2001 From: mbrucedogs Date: Sat, 26 Jul 2025 14:44:36 -0500 Subject: [PATCH] Signed-off-by: mbrucedogs --- README.md | 97 +++- docs/PRD.md | 199 +++++--- frontend/src/App.jsx | 27 +- frontend/src/components/ChartTable.jsx | 14 +- frontend/src/components/DownloadButton.jsx | 20 +- frontend/src/components/ItemCountSelector.jsx | 30 ++ frontend/src/components/JsonViewer.jsx | 61 ++- .../src/components/YearlyDownloadButton.jsx | 18 +- frontend/src/components/YearlyTopSongs.jsx | 5 +- frontend/src/styles.css | 479 ++++++++++++------ 10 files changed, 707 insertions(+), 243 deletions(-) create mode 100644 frontend/src/components/ItemCountSelector.jsx diff --git a/README.md b/README.md index 2a8063e..eafa92e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Music Charts Archive Scraper +# Multi-Source Music Charts Analytics Platform -A full-stack React application for scraping and visualizing music chart data from the Music Charts Archive website. +A full-stack React application for scraping and visualizing music chart data from multiple sources including Music Charts Archive, Kworb, and Shazam. ## Project Structure @@ -22,6 +22,9 @@ MusicCharts/ │ ├── routes/ # API routes │ ├── controllers/ # Route controllers │ ├── models/ # Data models & scraping logic + │ │ ├── chartService.js # Music Charts Archive + │ │ ├── kworbService.js # Kworb integration + │ │ └── shazamService.js # Shazam integration │ ├── middleware/ # Express middleware │ └── server.js # Main server file └── package.json @@ -29,7 +32,15 @@ MusicCharts/ ## Features -- **Year Selection**: Choose different years to view available chart dates +### **Multi-Source Data Integration** +- **Music Charts Archive**: Historical Billboard charts with weekly and yearly data +- **Kworb**: Real-time chart data with current trending information +- **Shazam**: Current trending songs with multiple chart types (no historical data) +- **Source Switching**: Seamless switching between data sources via tab interface +- **Chart Type Selection**: Multiple chart types for Shazam integration + +### **Core Functionality** +- **Year Selection**: Choose different years to view available chart dates (Music Charts Archive & Kworb) - **Date Selection**: Browse and select specific chart dates for detailed song data - **Music Chart Display**: View ranked songs with title and artist information - **Yearly Analytics**: Calculate and display top songs of the year using multi-factor ranking algorithm @@ -38,12 +49,13 @@ MusicCharts/ - **Property Selection**: Choose which data properties to include in exports - **Responsive Design**: Mobile-friendly interface - **Error Handling**: Comprehensive error states and loading indicators -- **Web Scraping**: Real-time data scraping from Music Charts Archive +- **Web Scraping**: Real-time data scraping from multiple sources ## Frontend Components -- `YearSelector`: Dropdown for year selection -- `DateList`: Grid of available chart dates for selected year +- `SourceSelector`: Tab-based interface for switching between data sources +- `YearSelector`: Dropdown for year selection (conditional based on source) +- `DateList`: Grid of available chart dates for selected year (conditional) - `ChartTable`: Music chart data table with rankings - `YearlyTopSongs`: Enhanced yearly analytics display with calculation metrics - `JsonViewer`: Interactive JSON data viewer with property selection @@ -54,9 +66,10 @@ MusicCharts/ ## Backend API Endpoints - `GET /api/health` - Health check endpoint -- `GET /api/chart/dates/:year` - Get available chart dates for a year -- `GET /api/chart/data/:date` - Get chart data for a specific date -- `GET /api/chart/yearly-top/:year` - Get yearly top songs ranking with calculation metrics +- `GET /api/chart/dates/:year` - Get available chart dates for a year (with source query param) +- `GET /api/chart/data/:date` - Get chart data for a specific date (with source and chartType query params) +- `GET /api/chart/yearly-top/:year` - Get yearly top songs ranking with calculation metrics (with source and chartType query params) +- `GET /api/chart/shazam/chart-types` - Get available Shazam chart types ## Setup Instructions @@ -82,6 +95,7 @@ MusicCharts/ PORT=3001 NODE_ENV=development CORS_ORIGIN=http://localhost:3000 + SHAZAM_API_KEY=your_shazam_api_key_here ``` 4. Start the development server: @@ -114,11 +128,12 @@ The frontend will be available at `http://localhost:3000` ### Get Available Chart Dates ``` -GET /api/chart/dates/:year +GET /api/chart/dates/:year?source=musicchartsarchive ``` **Parameters:** - `year` (number): The year to get chart dates for (1970-present) +- `source` (query): Data source - 'musicchartsarchive', 'kworb', or 'shazam' **Response:** ```json @@ -136,11 +151,13 @@ GET /api/chart/dates/:year ### Get Chart Data ``` -GET /api/chart/data/:date +GET /api/chart/data/:date?source=musicchartsarchive&chartType=top-200 ``` **Parameters:** -- `date` (string): Date in YYYY-MM-DD format +- `date` (string): Date in YYYY-MM-DD format (or 'today' for Shazam) +- `source` (query): Data source - 'musicchartsarchive', 'kworb', or 'shazam' +- `chartType` (query): Chart type for Shazam (e.g., 'top-200', 'top-100') **Response:** ```json @@ -160,11 +177,13 @@ GET /api/chart/data/:date ### Get Yearly Top Songs ``` -GET /api/chart/yearly-top/:year +GET /api/chart/yearly-top/:year?source=musicchartsarchive&chartType=top-200 ``` **Parameters:** - `year` (number): The year to get yearly top songs for +- `source` (query): Data source - 'musicchartsarchive', 'kworb', or 'shazam' +- `chartType` (query): Chart type for Shazam **Response:** ```json @@ -188,11 +207,52 @@ GET /api/chart/yearly-top/:year ] ``` -## Data Source +### Get Shazam Chart Types +``` +GET /api/chart/shazam/chart-types +``` -This application scrapes data from [Music Charts Archive](https://musicchartsarchive.com), a comprehensive database of historical music charts. The scraper extracts: +**Response:** +```json +[ + { + "id": "top-200", + "name": "Top 200" + }, + { + "id": "top-100", + "name": "Top 100" + } +] +``` -1. **Chart Dates**: Available chart dates for each year +## Data Sources + +This application integrates with multiple music chart data sources: + +### **Music Charts Archive** +- **URL**: https://musicchartsarchive.com +- **Data**: Historical Billboard charts +- **Features**: Weekly and yearly data, comprehensive historical records +- **Scraping**: HTML parsing with Cheerio + +### **Kworb** +- **URL**: https://kworb.net +- **Data**: Real-time chart data +- **Features**: Current trending information, historical support +- **Scraping**: HTML parsing with Cheerio + +### **Shazam** +- **URL**: https://www.shazam.com +- **Data**: Current trending songs +- **Features**: Multiple chart types, real-time data only (no historical) +- **Integration**: Official API with authentication + +## Data Processing + +The application extracts and processes: + +1. **Chart Dates**: Available chart dates for each year (Music Charts Archive & Kworb) 2. **Song Rankings**: Top songs with their chart positions, titles, and artists 3. **Yearly Analytics**: Multi-factor ranking algorithm calculating: - **Total Points**: Reverse scoring (1st = 50 points, 50th = 1 point) @@ -205,7 +265,7 @@ This application scrapes data from [Music Charts Archive](https://musicchartsarc 1. **Frontend**: Add new components in `frontend/src/components/` 2. **Backend**: Add new routes in `backend/src/routes/` and controllers in `backend/src/controllers/` -3. **Scraping**: Modify `backend/src/models/chartService.js` for new data extraction +3. **Scraping**: Modify service files in `backend/src/models/` for new data extraction 4. **Styling**: Modify `frontend/src/styles.css` for global styles 5. **API Integration**: Update `frontend/src/services/chartApi.js` for new endpoints 6. **JSON Formatting**: Modify `frontend/src/components/JsonViewer.jsx` for custom data formats @@ -243,10 +303,11 @@ This application scrapes data from [Music Charts Archive](https://musicchartsarc - **Progress Logging**: Real-time progress updates during yearly calculations - **Error Recovery**: Graceful handling of failed requests with continuation - **Memory Optimization**: Efficient data structures for large datasets +- **Multi-Source Routing**: Efficient routing to appropriate service based on source ## Legal Notice -This application is for educational and research purposes. Please respect the terms of service of the Music Charts Archive website and implement appropriate rate limiting and caching strategies for production use. +This application is for educational and research purposes. Please respect the terms of service of all data sources (Music Charts Archive, Kworb, and Shazam) and implement appropriate rate limiting and caching strategies for production use. ## License diff --git a/docs/PRD.md b/docs/PRD.md index c0e73e4..054dbaf 100644 --- a/docs/PRD.md +++ b/docs/PRD.md @@ -1,46 +1,56 @@ # Product Requirements Document (PRD) -## Music Charts Archive Scraper & Analytics Platform +## Multi-Source Music Charts Analytics Platform --- ## 📋 **Executive Summary** -A full-stack web application that scrapes, analyzes, and visualizes music chart data from the Music Charts Archive website. The platform provides both weekly chart views and comprehensive yearly rankings, enabling users to explore historical music trends and download data for further analysis. +A full-stack web application that scrapes, analyzes, and visualizes music chart data from multiple sources including Music Charts Archive, Kworb, and Shazam. The platform provides both weekly chart views and comprehensive yearly rankings, enabling users to explore historical music trends and download data for further analysis across different data sources. --- ## 🎯 **Product Vision** -Create a comprehensive music analytics platform that transforms raw chart data into actionable insights, making historical music trends accessible and analyzable for researchers, music enthusiasts, and data analysts. +Create a comprehensive music analytics platform that transforms raw chart data from multiple sources into actionable insights, making historical music trends accessible and analyzable for researchers, music enthusiasts, and data analysts. --- ## 🎵 **Core Features** -### **1. Data Scraping Engine** +### **1. Multi-Source Data Integration** +- **Music Charts Archive**: Historical Billboard charts with weekly and yearly data +- **Kworb**: Real-time chart data with current trending information +- **Shazam**: Current trending songs with multiple chart types (no historical data) +- **Source Switching**: Seamless switching between data sources +- **Chart Type Selection**: Multiple chart types for Shazam integration + +### **2. Data Scraping Engine** - **Weekly Chart Scraping**: Extract song rankings from individual chart dates - **Yearly Data Aggregation**: Collect and analyze data across all available dates for a year -- **Real-time Data Fetching**: Live scraping from Music Charts Archive website +- **Real-time Data Fetching**: Live scraping from multiple sources - **Error Handling**: Graceful handling of missing data and network issues -### **2. Weekly Chart View** -- **Date Selection**: Browse available chart dates by year -- **Chart Display**: View top 50 songs with rankings, titles, and artists +### **3. Weekly Chart View** +- **Source Selection**: Choose between Music Charts Archive, Kworb, or Shazam +- **Date Selection**: Browse available chart dates by year (Music Charts Archive & Kworb) +- **Chart Display**: View top songs with rankings, titles, and artists - **Data Export**: Download weekly chart data in JSON format - **Responsive Design**: Mobile and desktop optimized interface -### **3. Yearly Analytics** +### **4. Yearly Analytics** - **Yearly Rankings**: Calculate top songs of the year based on: - Total points (position-based scoring) - Highest achieved position - Number of appearances - **Smart Algorithm**: Multi-factor ranking system - **Yearly Export**: Download comprehensive yearly data +- **Source-Specific Logic**: Different algorithms for different data sources -### **4. Data Export System** +### **5. Data Export System** - **JSON Format**: Structured data export with metadata - **File Naming**: Date/year-based file naming convention - **Metadata Inclusion**: Chart date, total songs, formatted titles +- **Source Attribution**: Data source information in exports --- @@ -62,18 +72,22 @@ GET /api/health GET /api/chart/dates/:year - Purpose: Get available chart dates for a year -- Parameters: year (number) +- Parameters: year (number), source (query param) - Response: Array of date objects with date and formattedDate GET /api/chart/data/:date - Purpose: Get chart data for specific date -- Parameters: date (YYYY-MM-DD format) +- Parameters: date (YYYY-MM-DD format), source (query param), chartType (query param for Shazam) - Response: Array of song objects with order, title, artist GET /api/chart/yearly-top/:year - Purpose: Get yearly top songs ranking with calculation metrics -- Parameters: year (number) -- Response: Array of top 50 songs with order, title, artist, totalPoints, highestPosition, appearances +- Parameters: year (number), source (query param), chartType (query param for Shazam) +- Response: Array of top songs with order, title, artist, totalPoints, highestPosition, appearances + +GET /api/chart/shazam/chart-types +- Purpose: Get available Shazam chart types +- Response: Array of chart type objects with id and name ``` #### **Data Models** @@ -115,17 +129,32 @@ GET /api/chart/yearly-top/:year highestPosition: 1, appearances: 8 } + +// Chart Type Object (Shazam) +{ + id: "top-200", + name: "Top 200" +} +``` + +#### **Service Architecture** +```javascript +// Service Layer Structure +ChartService - Music Charts Archive integration +KworbService - Kworb real-time data integration +ShazamService - Shazam API integration with chart types ``` #### **Scraping Logic** -1. **Date Extraction**: Parse HTML for chart date links -2. **Song Data Extraction**: Parse table rows for song information -3. **Data Validation**: Ensure data integrity and completeness -4. **Error Recovery**: Skip problematic dates and continue processing +1. **Source Detection**: Route requests to appropriate service based on source parameter +2. **Date Extraction**: Parse HTML for chart date links (Music Charts Archive & Kworb) +3. **Song Data Extraction**: Parse table rows for song information +4. **Data Validation**: Ensure data integrity and completeness +5. **Error Recovery**: Skip problematic dates and continue processing #### **Yearly Ranking Algorithm** ```javascript -// Scoring System +// Scoring System (Music Charts Archive & Kworb) - Position Points: 1st = 50 points, 50th = 1 point - Highest Position: Track best position achieved - Appearance Count: Number of weeks on charts @@ -134,6 +163,10 @@ GET /api/chart/yearly-top/:year 1. Total Points (descending) 2. Highest Position (ascending) 3. Appearance Count (descending) + +// Shazam Algorithm (Current data only) +- Position-based ranking for current trending songs +- No historical aggregation available ``` ### **Frontend Requirements** @@ -148,9 +181,10 @@ GET /api/chart/yearly-top/:year ``` App ├── Layout -├── YearSelector +├── SourceSelector +├── YearSelector (conditional) ├── ViewModeSelector (Weekly/Yearly) -├── DateList (Weekly mode) +├── DateList (Weekly mode, conditional) ├── ChartTable ├── YearlyTopSongs ├── JsonViewer @@ -162,12 +196,15 @@ App ```javascript // Core State { + selectedSource: 'musicchartsarchive' | 'kworb' | 'shazam', selectedYear: number, selectedDate: string | null, + selectedChartType: string, // For Shazam viewMode: 'weekly' | 'yearly', dates: DateObject[], chartData: SongObject[], yearlySongs: SongObject[], + shazamChartTypes: ChartTypeObject[], selectedProperties: { position: boolean, title: boolean, @@ -182,18 +219,22 @@ App { datesLoading: boolean, dataLoading: boolean, - yearlyLoading: boolean + yearlyLoading: boolean, + chartTypesLoading: boolean } // Error States { datesError: string | null, dataError: string | null, - yearlyError: string | null + yearlyError: string | null, + chartTypesError: string | null } ``` #### **User Interface Requirements** +- **Source Selection**: Tab-based interface for switching between data sources +- **Conditional UI**: Show/hide components based on selected source - **Responsive Design**: Mobile-first approach - **Loading States**: Visual feedback during data fetching with progress indicators - **Error Handling**: User-friendly error messages with retry options @@ -220,14 +261,21 @@ struct Song: Codable { let artist: String } +struct ChartType: Codable { + let id: String + let name: String +} + // Network Layer class ChartAPIService { - func fetchChartDates(year: Int) async throws -> [ChartDate] - func fetchChartData(date: String) async throws -> [Song] - func fetchYearlyTopSongs(year: Int) async throws -> [Song] + func fetchChartDates(year: Int, source: String) async throws -> [ChartDate] + func fetchChartData(date: String, source: String, chartType: String?) async throws -> [Song] + func fetchYearlyTopSongs(year: Int, source: String, chartType: String?) async throws -> [Song] + func fetchShazamChartTypes() async throws -> [ChartType] } // UI Components +struct SourceSelector: View struct YearSelector: View struct ChartTableView: View struct YearlyTopSongsView: View @@ -248,14 +296,21 @@ data class Song( val artist: String ) +data class ChartType( + val id: String, + val name: String +) + // Network Layer class ChartAPIService { - suspend fun fetchChartDates(year: Int): List - suspend fun fetchChartData(date: String): List - suspend fun fetchYearlyTopSongs(year: Int): List + suspend fun fetchChartDates(year: Int, source: String): List + suspend fun fetchChartData(date: String, source: String, chartType: String?): List + suspend fun fetchYearlyTopSongs(year: Int, source: String, chartType: String?): List + suspend fun fetchShazamChartTypes(): List } // UI Components +@Composable fun SourceSelector() @Composable fun YearSelector() @Composable fun ChartTable() @Composable fun YearlyTopSongs() @@ -266,14 +321,19 @@ class ChartAPIService { ## 🎵 **Data Flow** +### **Source Selection Flow** +1. User selects data source → Load source-specific UI components +2. For Shazam → Fetch available chart types +3. For Music Charts Archive/Kworb → Show year selector and date list + ### **Weekly Chart Flow** -1. User selects year → Fetch available dates +1. User selects source and year → Fetch available dates (if applicable) 2. User selects date → Fetch chart data 3. Display chart table → Enable download 4. User downloads → Generate JSON file ### **Yearly Chart Flow** -1. User selects year → Fetch all dates for year +1. User selects source and year → Fetch all dates for year (if applicable) 2. System scrapes all dates → Calculate rankings 3. Display yearly top songs → Enable download 4. User downloads → Generate yearly JSON file @@ -283,11 +343,12 @@ class ChartAPIService { ## 🛠 **Development Guidelines** ### **Backend Development** -1. **Error Handling**: Implement comprehensive error handling -2. **Rate Limiting**: Respect website terms of service -3. **Caching**: Implement caching for frequently accessed data -4. **Logging**: Comprehensive logging for debugging -5. **Testing**: Unit tests for core algorithms +1. **Service Architecture**: Modular service layer for each data source +2. **Error Handling**: Implement comprehensive error handling +3. **Rate Limiting**: Respect website terms of service +4. **Caching**: Implement caching for frequently accessed data +5. **Logging**: Comprehensive logging for debugging +6. **Testing**: Unit tests for core algorithms ### **Frontend Development** 1. **Component Reusability**: Create reusable UI components @@ -295,6 +356,7 @@ class ChartAPIService { 3. **Performance**: Optimize for large datasets 4. **User Experience**: Smooth loading and error states 5. **Accessibility**: Screen reader and keyboard navigation support +6. **Conditional Rendering**: Handle different UI states based on source ### **Mobile Development** 1. **Offline Support**: Cache data for offline viewing @@ -312,12 +374,14 @@ class ChartAPIService { - **Error Rate**: < 5% failed requests - **Uptime**: > 99% availability - **Timeout Handling**: Graceful handling of long-running operations +- **Multi-Source Reliability**: Consistent performance across all data sources ### **User Experience Metrics** - **Page Load Time**: < 3 seconds - **User Engagement**: Time spent on platform - **Download Rate**: Percentage of users downloading data - **Error Recovery**: Successful error resolution rate +- **Source Switching**: Seamless transitions between data sources --- @@ -328,11 +392,12 @@ class ChartAPIService { - **User Agent**: Proper identification in requests - **Error Handling**: No sensitive data in error messages - **CORS**: Proper cross-origin resource sharing +- **API Key Management**: Secure handling of Shazam API keys ### **Legal Considerations** -- **Terms of Service**: Respect Music Charts Archive terms +- **Terms of Service**: Respect all data source terms - **Data Usage**: Educational and research purposes -- **Attribution**: Proper credit to data source +- **Attribution**: Proper credit to data sources - **Rate Limiting**: Responsible scraping practices --- @@ -346,12 +411,14 @@ class ChartAPIService { - **Advanced Filtering**: Date range, artist, song title filters - **Enhanced JSON Export**: Customizable data formats and property selection - **Real-time Progress Tracking**: Visual progress indicators for long operations +- **Data Source Comparison**: Side-by-side comparison of different sources ### **Phase 3 Features** - **User Accounts**: Save favorite charts and analyses - **Social Features**: Share charts and insights - **API Access**: Public API for developers - **Data Visualization**: Interactive charts and graphs +- **Additional Sources**: Integration with more music data providers --- @@ -360,9 +427,10 @@ class ChartAPIService { ### **Backend Setup** - [ ] Choose server framework and language - [ ] Set up web scraping library -- [ ] Implement API endpoints -- [ ] Create data models -- [ ] Implement yearly ranking algorithm +- [ ] Implement multi-source service architecture +- [ ] Create API endpoints with source routing +- [ ] Implement data models for all sources +- [ ] Create yearly ranking algorithms - [ ] Add error handling and logging - [ ] Set up testing framework @@ -370,6 +438,8 @@ class ChartAPIService { - [ ] Choose UI framework - [ ] Set up state management - [ ] Create reusable components +- [ ] Implement source selector component +- [ ] Create conditional UI logic - [ ] Implement API integration - [ ] Add download functionality - [ ] Implement responsive design @@ -377,9 +447,9 @@ class ChartAPIService { ### **Mobile Setup (if applicable)** - [ ] Set up mobile development environment -- [ ] Create data models -- [ ] Implement network layer -- [ ] Create UI components +- [ ] Create data models for all sources +- [ ] Implement network layer with source routing +- [ ] Create UI components with conditional rendering - [ ] Add native features (download, share) - [ ] Test on devices @@ -395,7 +465,7 @@ class ChartAPIService { ### **Project Structure** ``` -m/ +MusicCharts/ ├── frontend/ # React frontend application │ ├── src/ │ │ ├── components/ # React components @@ -411,6 +481,9 @@ m/ │ ├── routes/ # API routes │ ├── controllers/ # Route controllers │ ├── models/ # Data models & scraping logic + │ │ ├── chartService.js # Music Charts Archive + │ │ ├── kworbService.js # Kworb integration + │ │ └── shazamService.js # Shazam integration │ ├── middleware/ # Express middleware │ └── server.js # Main server file └── package.json @@ -427,29 +500,35 @@ m/ ## 🚀 **Recent Enhancements (Latest Update)** -### **Enhanced Data Export System** -- **JsonViewer Component**: Interactive JSON data inspection with property selection -- **Customizable Exports**: Choose which properties to include in JSON output -- **Copy/Download Functionality**: One-click copy to clipboard and direct download -- **Format Consistency**: Matches reference format from `docs/songList.json` +### **Multi-Source Architecture** +- **SourceSelector Component**: Tab-based interface for switching between data sources +- **Service Layer**: Modular architecture with separate services for each data source +- **Conditional UI**: Dynamic component rendering based on selected source +- **Enhanced API**: Source-aware endpoints with query parameters -### **Performance Optimizations** -- **Extended Timeouts**: 5-minute frontend timeout for yearly calculations -- **Request Delays**: 100ms delays between scraping requests -- **Progress Logging**: Real-time progress updates during long operations -- **Error Recovery**: Graceful handling of failed requests with continuation +### **Shazam Integration** +- **Chart Types**: Multiple chart type selection (Top 200, Top 100, etc.) +- **Current Data**: Real-time trending songs (no historical data) +- **API Integration**: Complete Shazam API integration +- **Chart Type Endpoint**: New endpoint for fetching available chart types + +### **Kworb Integration** +- **Real-time Data**: Current chart data from Kworb +- **Historical Support**: Yearly data aggregation capabilities +- **Service Implementation**: Dedicated KworbService for data extraction ### **Enhanced User Experience** -- **Property Selection**: Checkboxes to customize JSON output properties -- **Loading Indicators**: Informative loading messages for long-running operations -- **Enhanced Error Handling**: Better error messages and recovery options +- **Source-Specific UI**: Different interfaces for different data sources +- **Loading States**: Source-aware loading indicators +- **Error Handling**: Source-specific error messages - **Responsive Design**: Improved mobile and desktop experience ### **Data Format Standards** -- **Consistent JSON Structure**: Standardized format matching industry standards +- **Consistent JSON Structure**: Standardized format across all sources +- **Source Attribution**: Data source information in exports - **Calculation Properties**: Full visibility into ranking algorithm metrics - **Flexible Export Options**: Multiple export formats for different use cases --- -This PRD provides a comprehensive blueprint for recreating the Music Charts Archive Scraper in any technology stack, from web frameworks to mobile platforms. The modular architecture and clear data flow make it adaptable to different implementation approaches while maintaining the core functionality and user experience. \ No newline at end of file +This PRD provides a comprehensive blueprint for the multi-source Music Charts Analytics Platform, supporting Music Charts Archive, Kworb, and Shazam integrations. The modular architecture and clear data flow make it adaptable to different implementation approaches while maintaining the core functionality and user experience across multiple data sources. \ No newline at end of file diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 1827bb7..79246cd 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -18,6 +18,7 @@ function App() { const [viewMode, setViewMode] = useState('weekly'); // 'weekly' or 'yearly' const [selectedSource, setSelectedSource] = useState('musicchartsarchive'); const [selectedChartType, setSelectedChartType] = useState('top-200'); + const [itemCount, setItemCount] = useState(50); // Default to 50 items const { chartTypes: shazamChartTypes, loading: chartTypesLoading } = useShazamChartTypes(); const { dates, loading: datesLoading, error: datesError } = useChartDates(selectedSource === 'shazam' ? null : selectedYear, selectedSource); @@ -53,6 +54,10 @@ function App() { setSelectedDate(null); // Reset selected date when chart type changes }; + const handleItemCountChange = (count) => { + setItemCount(count); + }; + return (
@@ -125,10 +130,19 @@ function App() { loading={dataLoading} error={dataError} selectedDate={selectedSource === 'shazam' ? 'Current' : selectedDate} + selectedSource={selectedSource} + itemCount={itemCount} + onItemCountChange={handleItemCountChange} /> {chartData && chartData.length > 0 && ( - + )} ) : ( @@ -138,10 +152,19 @@ function App() { loading={yearlyLoading} error={yearlyError} year={selectedSource === 'shazam' ? 'Current' : selectedYear} + selectedSource={selectedSource} + itemCount={itemCount} + onItemCountChange={handleItemCountChange} /> {yearlySongs && yearlySongs.length > 0 && ( - + )} )} diff --git a/frontend/src/components/ChartTable.jsx b/frontend/src/components/ChartTable.jsx index b65818f..733c0fe 100644 --- a/frontend/src/components/ChartTable.jsx +++ b/frontend/src/components/ChartTable.jsx @@ -1,6 +1,7 @@ import React from 'react'; +import JsonViewer from './JsonViewer'; -const ChartTable = ({ data, loading, error, selectedDate }) => { +const ChartTable = ({ data, loading, error, selectedDate, selectedSource, itemCount, onItemCountChange }) => { if (loading) { return (
@@ -56,6 +57,17 @@ const ChartTable = ({ data, loading, error, selectedDate }) => {
+ + {/* JSON Viewer for debugging and data inspection */} +
); }; diff --git a/frontend/src/components/DownloadButton.jsx b/frontend/src/components/DownloadButton.jsx index 80398e9..66f9d4c 100644 --- a/frontend/src/components/DownloadButton.jsx +++ b/frontend/src/components/DownloadButton.jsx @@ -1,9 +1,23 @@ import React from 'react'; -const DownloadButton = ({ data, selectedDate }) => { +const DownloadButton = ({ data, selectedDate, selectedSource, itemCount, onItemCountChange }) => { const downloadJSON = () => { if (!data || data.length === 0) return; + // Limit data based on item count for Kworb source + let dataToDownload = data; + if (selectedSource === 'kworb' && itemCount) { + dataToDownload = data.slice(0, itemCount); + } + + // For Kworb source, renumber positions sequentially to handle missing numbers + if (selectedSource === 'kworb') { + dataToDownload = dataToDownload.map((item, index) => ({ + ...item, + order: index + 1 // Sequential numbering starting from 1 + })); + } + // Format the date for the title const formatDate = (dateString) => { const date = new Date(dateString); @@ -18,8 +32,8 @@ const DownloadButton = ({ data, selectedDate }) => { const jsonData = { title: `${formatDate(selectedDate)} - Top Songs`, date: selectedDate, - totalSongs: data.length, - songs: data + totalSongs: dataToDownload.length, + songs: dataToDownload }; const jsonContent = JSON.stringify(jsonData, null, 2); diff --git a/frontend/src/components/ItemCountSelector.jsx b/frontend/src/components/ItemCountSelector.jsx new file mode 100644 index 0000000..2188aad --- /dev/null +++ b/frontend/src/components/ItemCountSelector.jsx @@ -0,0 +1,30 @@ +import React from 'react'; + +const ItemCountSelector = ({ itemCount, onItemCountChange, selectedSource }) => { + // Only show for Kworb source since it has random numbers + if (selectedSource !== 'kworb') { + return null; + } + + const itemCountOptions = [40, 50, 60, 70, 80, 90, 100]; + + return ( +
+ + +
+ ); +}; + +export default ItemCountSelector; \ No newline at end of file diff --git a/frontend/src/components/JsonViewer.jsx b/frontend/src/components/JsonViewer.jsx index 067935b..954ba9b 100644 --- a/frontend/src/components/JsonViewer.jsx +++ b/frontend/src/components/JsonViewer.jsx @@ -1,7 +1,9 @@ import React, { useState } from 'react'; +import ItemCountSelector from './ItemCountSelector'; -const JsonViewer = ({ data, title, filename, year }) => { +const JsonViewer = ({ data, title, filename, year, selectedSource, itemCount, onItemCountChange }) => { const [isVisible, setIsVisible] = useState(false); + const [customTitle, setCustomTitle] = useState(title || `${year} - Top 50 Songs`); const [selectedProperties, setSelectedProperties] = useState({ position: true, title: true, @@ -15,12 +17,23 @@ const JsonViewer = ({ data, title, filename, year }) => { const formatData = () => { if (!data || data.length === 0) return null; - const filteredSongs = data.map(item => { + // Limit data based on item count for Kworb source + let dataToProcess = data; + if (selectedSource === 'kworb' && itemCount) { + dataToProcess = data.slice(0, itemCount); + } + + const filteredSongs = dataToProcess.map((item, index) => { const filteredSong = {}; // Map order to position to match the expected format if (selectedProperties.position && item.hasOwnProperty('order')) { - filteredSong.position = item.order; + // For Kworb source, renumber positions sequentially to handle missing numbers + if (selectedSource === 'kworb') { + filteredSong.position = index + 1; // Sequential numbering starting from 1 + } else { + filteredSong.position = item.order; // Keep original order for other sources + } } // Add other selected properties @@ -34,7 +47,7 @@ const JsonViewer = ({ data, title, filename, year }) => { }); return { - title: `${year} - Top 50 Songs`, + title: customTitle, songs: filteredSongs }; }; @@ -73,8 +86,46 @@ const JsonViewer = ({ data, title, filename, year }) => { document.body.removeChild(link); }; + const updateTitle = () => { + // This function can be used to update the title if needed + // For now, the title updates automatically as the user types + }; + return (
+ {/* Form Section with Title Input and Item Count Selector */} +
+
+
+ + setCustomTitle(e.target.value)} + className="title-input" + placeholder="Enter custom title for JSON" + /> +
+ + {/* Item Count Selector - only for Kworb */} + +
+ +
+ +
+
+