Does anyone have any thoughts or suggestions on how to create a playlist of songs from my library that have been released as “singles” or “Top 40s” across a time period?

Let’s say I wanted to throw a 90s party, and I wanted to create a playlist from my library using only songs that people are likely to know. I recognize that’s totally subjective, so maybe that’s why I’m struggling to find what I want. I can create a playlist based on album release date, which gets me a bit of the way there, but the playlist is going to include a lot of “deep cut” tracks and whole albums that few people know. I’d rather not spend too long curating the list. I was hoping for a way to just find popular tracks, and it seems like basing it on “chart toppers” would be a good place to start. Ideally, it would be genre-independent, but limited to songs that got decent radio play, so Backstreet Boys to Korn to Shania Twain are fine. Yo Yo Ma maybe not so much.

It doesn’t seem like Plex has information available in the filters to achieve that. It does have “Popularity” as an additional column header if I list my music by “Tracks”, so I guess I could sort by that and limit the results to some value. It feels a little clunky, though, and I’m not sure where it’s getting that information.

I know that Library Radio is a thing, but I can’t seem to make it do what I want. I only have 4 stations on the web interface: “Library Radio”, “Deep Cuts Radio”, “Time Travel Radio”, and “Random Album Radio”. Clicking on them just starts playing music from a wide selection that I have no control over. I know that “Decade Radio” exists, but it doesn’t seem to be giving me what I want, either. It frequently pulls instrumental tracks from movie soundtracks. I have “Smart Shuffle” enabled on my server. I’m not sure if that’s helping or hurting my experience (I’ve seen some very mixed reviews on that feature). I also can’t find “Decade Radio” on the web interface; it seems like Decade Radio is only available on Plexamp.

I’d rather just create a playlist. That way it would be available everywhere, and I could tailor it a little bit, if needed.

So, yeah… any tips? It seems like the “filter by decade, sort by popularity, and limit by count” might be my best option right now.

  • spizzat2@lemm.eeOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 months ago

    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.