Ok, I found a cool resource that gets me a little closer. Someone has a CSV of all Billboard top 100 songs since its inception through the current week. It’s about 343k rows (100 rows per week * 52 weeks * ~65 years), so I decided to script the heavy lifting. With a little help from an LLM, I was able to write a Python script that parsed the CSV and then looped over it (see below). Fortunately, my music is fairly well organized, so I was able to use the directory structure to check to see if I had a copy of the song for each of the hits.
With the output of the Python script, I was able to create an m3u playlist, which I can at least open in any decent music player on the same computer as my music. Fortunately, the format of the playlist is dead simple. I just started the file with
#EXTM3U
#EXTINF:-1 tvg-id="US_Billboard" tvg-name="Billboard Top 40 Hits" group-title="US Billboard",Billboard Top 40 Hits
and then added each file as a newline. I’m not sure the second line is even necessary, but it opened in VLC without an issue.
Unfortunately, I’ve heard that converting/importing an m3u playlist into Plex is not a simple process. You have to query the API and get an ID or manually go to each file and “Get Info”. The latter is definitely not practical for the couple thousand matches in my m3u file. I can try to look into querying the API from within the script, but I still don’t know the format for the request to add a song to a playlist. If only Python already had everything written for you.
Anyway… I might update if I get further along, but it’s not a major priority at the moment. Maybe this will help someone else in the future. I’m just trying to move the sticks.
import os
import csv
import re
def find_files(csv_file, base_directory):
with open(csv_file, mode='r', newline='', encoding='utf-8') as file:
reader = csv.reader(file)
hit_count=0;
cache = {}
# Skip header if present
next(reader, None) # Uncomment if your CSV has a header
for row in reader:
if len(row) < 7:
print(f"Row is incomplete: {row}")
continue
billboard_week = row[0] # Date column
billboard_rank = int(row[1]) # First integer column
song_name = row[2] # String to search in filenames
artist_name = row[3] # Directory to search in
#NOTE: row[4] might not be an integer, and that causes problems
# I'm not using these values, anyway.
# last_week = int(row[4]) # Second integer column
# peak_position = int(row[5]) # Third integer column
# weeks_on_chart = int(row[6]) # Fourth integer column
if re.search("hristmas",song_name): #Skip "[C|c]hristmas" songs
continue
# Construct the full path to the directory
search_directory = os.path.join(base_directory, artist_name)
if os.path.isdir(search_directory):
for root, dirs, files in os.walk(search_directory):
for dir in dirs:
album_directory = os.path.join(search_directory, dir)
if re.search("^[\\.|_]",dir):
continue
for album_root, album_dirs, album_files in os.walk(album_directory):
for file in album_files:
if song_name in file:
unique_key = os.path.join(search_directory,song_name);
if re.search("__MACOSX",unique_key): #Skip weird OSX directory
continue
if unique_key not in cache:
full_path = os.path.join(album_root, file)
print(full_path) #TODO: Print to playlist.m3u file
hit_count=hit_count+1
cache[unique_key]=1
# else:
# #print(f"Could not find artist directory: {search_directory}")
print(hit_count)
# Example usage
if __name__ == "__main__":
csv_file_path = 'hot-100-current.csv' # Update this path
base_directory = '~/Music/' # Update this path (e.g. 'C:\\Music\')
find_files(csv_file_path, base_directory)
os.system("pause")
#How to Use the Script
#
# Prepare Your CSV File: Ensure it has the correct format: date, Current Rank, Song Title, Artist/Directory name, Previous Rank (1-100, or NA), Peak Rank (1-100), Weeks on Chart (integer).
# Set the File Paths: Update csv_file_path and base_directory variables with the correct paths.
# Run the Script: Execute the script in your Python environment. It will print the full paths of matching files to the console.
#
#Notes
#
# This script assumes that the directory name in the CSV corresponds to a subdirectory of the specified base_directory.
# It handles the case where the directory does not exist and will skip any rows that do not have the correct number of columns.
# Adjust the path separators as necessary based on your operating system. In this case, it uses double backslashes (\\) for Windows paths.
#TODO:
# Better artist handling (Look for "Featuring" or "&" to better find artists. Make artist search case-insensitive)
# Automatically generate playlist file by writing directly to playlist.m3u instead of printing to console.
# Incorporate Python libraries to query Plex API for song information and create/update a playlist.
# Accept filter parameters to only include songs from a given date range.
deleted by creator