Skip to content

Commit

Permalink
Add support for rich presence song pictures.
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlie committed Aug 26, 2024
1 parent 44660d6 commit 03d9242
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
16 changes: 13 additions & 3 deletions core/musicPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,17 @@ def update_song_info(self):

# Update Discord presence
if self.config['connect_to_discord']: # Check if Discord connection is enabled
image_text = f"{self.current_playlist}"
if self.current_song["picture_link"]: # Check if there is a picture link
big_image = self.current_song["picture_link"]
else:
big_image = self.current_playlist_image if self.current_playlist else None

if self.current_song["album"]: # Check if there is an album
image_text = f"Album: {self.current_song['album']}"
else:
image_text = f"Playlist: {self.current_playlist}"


if self.is_playing: # Check if something is playing
if self.is_paused: # Check if it is paused
self.discord_integration.update_presence(
Expand All @@ -727,7 +737,7 @@ def update_song_info(self):
"pause", # Small image key
"Paused", # Small image text
0, # Youtube ID for button
self.current_playlist_image if self.current_playlist else None, # Playlist image
big_image, # Playlist image
None, # Duration
)
else: # Playing and not paused
Expand All @@ -741,7 +751,7 @@ def update_song_info(self):
small_image_key, # Small image key
small_image_text, # Small image text
self.current_song.get('youtube_id') if self.current_song else None, # Youtube ID for button
self.current_playlist_image if self.current_playlist else None, # Playlist image
big_image, # Playlist image
song_duration, # Duration
)
else: # No song is playing
Expand Down
22 changes: 15 additions & 7 deletions core/playlistMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, icon_path):
self.setWindowTitle("Iota Player • Playlist Maker")
if os.path.exists(icon_path):
self.setWindowIcon(QIcon(icon_path))
self.setGeometry(100, 100, 1700, 800)
self.setGeometry(100, 100, 1700, 900)

with open('config.json', 'r') as f:
self.config = json.load(f)
Expand Down Expand Up @@ -185,16 +185,17 @@ def initUI(self):

# Table view for song list
self.song_table = QTableWidget()
self.song_table.setColumnCount(7)
self.song_table.setHorizontalHeaderLabels(["Artist", "Title", "Album", "Genre", "Picture Path", "YouTube ID", "Song Path"])
self.song_table.setColumnCount(8)
self.song_table.setHorizontalHeaderLabels(["Artist", "Title", "Album", "Genre", "Picture Path", "Picture Link", "YouTube ID", "Song Path"])
self.right_layout.addWidget(self.song_table)
self.song_table.setColumnWidth(0, 150)
self.song_table.setColumnWidth(1, 150)
self.song_table.setColumnWidth(2, 150)
self.song_table.setColumnWidth(3, 150)
self.song_table.setColumnWidth(4, 150)
self.song_table.setColumnWidth(5, 150)
self.song_table.setColumnWidth(6, 450)
self.song_table.setColumnWidth(6, 150)
self.song_table.setColumnWidth(7, 450)
self.song_table.itemChanged.connect(self.update_song_data)
self.songs = []

Expand Down Expand Up @@ -230,6 +231,7 @@ def process_folder(self, folder):
"genre": "", # Default empty genre
"album": "", # Default empty album
"picture_path": "", # Default empty picture path
"picture_link": "", # Default empty picture link
"youtube_id": youtube_id,
"path": song_path.replace("\\", "/")
})
Expand All @@ -244,6 +246,7 @@ def add_song_to_table(self):
album = song.get('album', 'Unknown Album')
genre = song.get('genre', 'Unknown Genre')
picture_path = song.get('picture_path', '')
picture_link = song.get('picture_link', '')
youtube_id = song.get('youtube_id', '')
path = song.get('path', '')

Expand All @@ -252,8 +255,9 @@ def add_song_to_table(self):
self.song_table.setItem(row, 2, QTableWidgetItem(album))
self.song_table.setItem(row, 3, QTableWidgetItem(genre))
self.song_table.setItem(row, 4, QTableWidgetItem(picture_path))
self.song_table.setItem(row, 5, QTableWidgetItem(youtube_id))
self.song_table.setItem(row, 6, QTableWidgetItem(path))
self.song_table.setItem(row, 5, QTableWidgetItem(picture_link))
self.song_table.setItem(row, 6, QTableWidgetItem(youtube_id))
self.song_table.setItem(row, 7, QTableWidgetItem(path))

def update_song_data(self, item):
row = item.row()
Expand All @@ -272,8 +276,10 @@ def update_song_data(self, item):
elif column == 4:
self.songs[row]['picture_path'] = value
elif column == 5:
self.songs[row]['youtube_id'] = value
self.songs[row]['picture_link'] = value
elif column == 6:
self.songs[row]['youtube_id'] = value
elif column == 7:
self.songs[row]['path'] = value

def add_song(self):
Expand All @@ -282,6 +288,7 @@ def add_song(self):
album = self.album_input.text().strip()
genre = self.genre_input.text().strip() # Get genre input
picture_path = self.picture_path_input.text().strip() # Get picture path input
picture_link = self.picture_link_input.text().strip()
youtube_id = self.youtube_id_input.text().strip()
path = self.path_input.text().strip()

Expand All @@ -292,6 +299,7 @@ def add_song(self):
"album": album,
"genre": genre,
"picture_path": picture_path,
"picture_link": picture_link,
"youtube_id": youtube_id,
"path": path.replace("\\", "/")
}
Expand Down
6 changes: 4 additions & 2 deletions playlists/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"playlist": "default",
"album": "Album 1",
"genre": "Genre 2",
"picture_path": "C:\\Users\\USER\\Music\\FOLDER\\picture.jpg"
"picture_path": "C:\\Users\\USER\\Music\\FOLDER\\picture.jpg",
"picture_link":""
},
{
"artist": "Artist 2",
Expand All @@ -21,7 +22,8 @@
"playlist": "default",
"album": "Album 2",
"genre": "Genre 2",
"picture_path": "C:\\Users\\USER\\Music\\FOLDER\\picture.jpg"
"picture_path": "C:\\Users\\USER\\Music\\FOLDER\\picture.jpg",
"picture_link":""
}
]
}

0 comments on commit 03d9242

Please sign in to comment.