Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yaml
from modules.listenbrainz_functions import get_weeklyjams_playlist
from modules.listenbrainz_functions import get_weeklyjams_playlist,get_weeklyexploration_playlist
from modules.plex_functions import set_section

with open("config.yml", 'r') as ymlfile:
Expand All @@ -8,3 +8,4 @@
if __name__ == "__main__":
set_section()
get_weeklyjams_playlist(cfg['user_token'])
get_weeklyexploration_playlist(cfg['user_token'])
39 changes: 34 additions & 5 deletions modules/listenbrainz_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

track_list = []

search_title = get_playlist_title(cfg['playlist_username'])


def get_weeklyjams_playlist(user_token):
"""
Goes through all the 'Created For' playlists and returns the 'Weekly Jams' playlist for the current week
Expand All @@ -24,6 +21,39 @@ def get_weeklyjams_playlist(user_token):
"""
username = cfg['playlist_username']

search_title = get_playlist_title(username)

try:
get_playlist(username,user_token,search_title)
except Exception as e:
logger.error(f"Unable to create Weekly Exploration playlist")


def get_weeklyexploration_playlist(user_token):
"""
Goes through all the 'Created For' playlists and returns the 'Weekly Exploration' playlist for the current week
:param user_token: The ListenBrainz token for the user
:return: The 'Weekly Exploration' playlist info
"""
username = cfg['playlist_username']

search_title = get_playlist_exploration_title(username)

try:
get_playlist(username,user_token,search_title)
except Exception as e:
logger.error(f"Unable to create Weekly Exploration playlist")



def get_playlist(username, user_token, search_title):
"""
Goes through all the 'Created For' playlists and returns the 'Weekly Exploration' playlist for the current week
:param username: The ListenBrainz username for the user
:param user_token: The ListenBrainz token for the user
:param search_title: Search string for the playlist title
:return: The 'Weekly Exploration' playlist info
"""
try:
logger.info("Getting playlists...")

Expand All @@ -49,7 +79,7 @@ def get_weeklyjams_playlist(user_token):

# Find the playlist that is titled search_title
for playlist in playlists:
if playlist['playlist']['title'] == search_title:
if search_title in playlist['playlist']['title']:
playlist_mbid = playlist['playlist']['identifier'].split('/')[-1]

# Get the name of the second playlist
Expand All @@ -75,7 +105,6 @@ def get_weeklyjams_playlist(user_token):
logger.error(f"An error occurred: {e}")
exit()


def get_tracks_from_playlist(user_token, playlist_mbid):
"""
Retrieves all tracks and their related info for a specific playlist
Expand Down
23 changes: 22 additions & 1 deletion modules/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@ def get_playlist_title(username: str):
# Format the date as 'YYYY-MM-DD'
formatted_date = most_recent_monday.strftime('%Y-%m-%d')

title = f"Weekly Jams for {username}, week of {formatted_date} Mon"
title = f"Weekly Jams for {username}"

return title

def get_playlist_exploration_title(username: str):
"""
Gets the date of the most recent Monday and formats it for the title to search for
:param username: The username for the playlist
:return: The formatted title to search for
"""
# Get the current date
current_date = datetime.now()

# Calculate the difference in days between the current day and Monday (weekday 0)
days_to_monday = (current_date.weekday() - 0) % 7

# Subtract the difference to get the date of the most recent Monday
most_recent_monday = current_date - timedelta(days=days_to_monday)

# Format the date as 'YYYY-MM-DD'
formatted_date = most_recent_monday.strftime('%Y-%m-%d')

title = f"Weekly Exploration for {username}"

return title

def normalize_characters(title: str):
"""
Expand Down