Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- source theme only once to prevent issues on subsequent activations in experimental mode
- saving metadata without album art
  • Loading branch information
elibroftw committed Apr 23, 2024
1 parent 65318d5 commit a08e535
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Music Caster by Elijah Lopez Changelog

5.19.6
- [Fix] Experimental theme setting
- [Fix] Saving metadata without album art

5.19.5
- [Fix] Handling unresponsive cast device

Expand Down
8 changes: 4 additions & 4 deletions build_files/mc_version_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# For more details about fixed file info 'ffi' see: http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
ffi=FixedFileInfo(
prodvers=(5, 19, 5, 0),
filevers=(5, 19, 5, 0),
prodvers=(5, 19, 6, 0),
filevers=(5, 19, 6, 0),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x17,
# Contains a bitmask that specifies the Boolean attributes of the file.
Expand All @@ -27,12 +27,12 @@ VSVersionInfo(
'000004b0',
[StringStruct('CompanyName', 'Elijah Lopez'),
StringStruct('FileDescription', 'Music Caster'),
StringStruct('FileVersion', '5.19.5.0'),
StringStruct('FileVersion', '5.19.6.0'),
StringStruct('InternalName', 'Music Caster'),
StringStruct('LegalCopyright', 'Copyright (c) 2019 - 2024, Elijah Lopez'),
StringStruct('OriginalFilename', 'Music Caster.exe'),
StringStruct('ProductName', 'Music Caster'),
StringStruct('ProductVersion', '5.19.5.0')])
StringStruct('ProductVersion', '5.19.6.0')])
]),
VarFileInfo([VarStruct('Translation', [0, 1200])])
]
Expand Down
2 changes: 1 addition & 1 deletion build_files/setup_script.iss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define MyAppName "Music Caster"
#define MyAppVersion "5.19.5"
#define MyAppVersion "5.19.6"
#define MyAppPublisher "Elijah Lopez"
#define MyAppURL "https://elijahlopez.ca/software#music-caster"
#define MyAppExeName "Music Caster.exe"
Expand Down
4 changes: 2 additions & 2 deletions src/meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = latest_version = '5.19.5'
VERSION = latest_version = '5.19.6'
UPDATE_MESSAGE = """
[NEW] Better Error Capturing
[MSG] Language translators wanted
Expand Down Expand Up @@ -70,7 +70,6 @@
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/591'
SUN_VALLEY_TCL = 'theme/sun-valley.tcl'
SPOTIFY_API = 'https://api.spotify.com/v1'
SORT_BY_POPULAR = 0


class State:
Expand All @@ -83,6 +82,7 @@ class State:
PORT = 2001
# experimental setting
using_tcl_theme = False
theme_sourced = False
settings = {}
update_available = False
installing_update = False
Expand Down
21 changes: 16 additions & 5 deletions src/music_caster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: noqa: E402
from meta import State
from meta import *
import time

Expand Down Expand Up @@ -2738,10 +2739,15 @@ def activate_gui(selected_tab=None, url_option='url_play'):
if State.using_tcl_theme:
Sg.PySimpleGUI.TOOLTIP_BACKGROUND_COLOR = settings['theme']['background']
try:
# as per State.using_tcl_theme, sun_valley_tcl_path exists
gui_window.TKroot.tk.call('source', sun_valley_tcl_path)
if not State.theme_sourced:
# as per State.using_tcl_theme, sun_valley_tcl_path exists
# source errors out if called more than once
gui_window.TKroot.tk.call('source', sun_valley_tcl_path)
State.theme_sourced = True
# this needs to be called every time the GUI is constructed
gui_window.TKroot.tk.call('set_theme', 'dark')
except TclError as e:
# _tkinter.TclError: Theme sun-valley-light already exists
if IS_FROZEN:
handle_exception(e)
else:
Expand Down Expand Up @@ -3649,10 +3655,14 @@ def read_main_window():
gui_window['metadata_art'].update(data=None)
elif main_event in {'metadata_save', 's:83'} and main_values.get('tab_group') == 'tab_metadata':
if gui_window['metadata_file'].get():
mime, art = gui_window['metadata_art'].metadata
new_metadata = {'title': main_values['metadata_title'], 'artist': main_values['metadata_artist'],
'album': main_values['metadata_album'], 'explicit': main_values['metadata_explicit'],
'track_number': main_values['metadata_track_num'], 'mime': mime, 'art': art}
'album': main_values['metadata_album'], 'explicit': main_values['metadata_explicit'],
'track_number': main_values['metadata_track_num']}
# album art optional
if gui_window['metadata_art'].metadata is not None:
mime, art = gui_window['metadata_art'].metadata
new_metadata['mime'] = mime
new_metadata['art'] = art
gui_window['metadata_msg'].update(value=t('Saving metadata'), text_color='yellow')
try:
set_metadata(gui_window['metadata_file'].get(), new_metadata)
Expand All @@ -3663,6 +3673,7 @@ def read_main_window():
gui_window['metadata_msg'].update(value=error, text_color='red')
gui_window.TKroot.after(2000, lambda: gui_window['metadata_msg'].update(value=''))
gui_window['title'].update(' ' + gui_window['title'].DisplayText + ' ') # try updating now playing

elif main_event == 'exit_program':
exit_program()
# other GUI updates
Expand Down
17 changes: 9 additions & 8 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
from PIL import Image, ImageFile, ImageDraw, ImageFont, UnidentifiedImageError
import requests
from wavinfo import WavInfoReader, WavInfoEOFError # until mutagen supports .wav
from youtube_comment_downloader import YoutubeCommentDownloader
from youtube_comment_downloader import YoutubeCommentDownloader, SORT_BY_POPULAR
from meta import *
from meta import AUDIO_HANDLER_EXTS


# CONSTANTS
IS_FROZEN = getattr(sys, 'frozen', False)
ImageFile.LOAD_TRUNCATED_IMAGES = True
YTCommentDLer = YoutubeCommentDownloader()
yt_comment_downloader = YoutubeCommentDownloader()
# for stealing focus when bring window to front

class SystemAudioRecorder:
Expand Down Expand Up @@ -448,7 +448,7 @@ def set_metadata(file_path: str, metadata: dict):
track_number = track_place.split('/')[0] # X
rating = '1' if metadata['explicit'] else '0'
# b64 album art data should be b64 as a string not as bytes
if 'art' in metadata and isinstance(metadata['art'], bytes):
if isinstance(metadata.get('art'), bytes):
metadata['art'] = metadata['art'].decode()
if '/' not in track_place:
tracks = max(1, int(track_place))
Expand All @@ -469,7 +469,7 @@ def set_metadata(file_path: str, metadata: dict):
# audio['TPUB'] = mutagen.id3.TPUB(text=metadata['publisher'])
audio['TXXX:RATING'] = mutagen.id3._frames.TXXX(text=rating, desc='RATING')
audio['TXXX:ITUNESADVISORY'] = mutagen.id3._frames.TXXX(text=rating, desc='ITUNESADVISORY')
if metadata['art'] is not None:
if metadata.get('art') is not None:
img_data = b64decode(metadata['art'])
audio['APIC:'] = mutagen.id3._frames.APIC(encoding=0, mime=metadata['mime'], type=3, data=img_data)
else: # remove all album art
Expand All @@ -485,7 +485,7 @@ def set_metadata(file_path: str, metadata: dict):
audio['©alb'] = [album]
audio['trkn'] = [tuple((int(x) for x in track_place.split('/')))]
audio['rtng'] = [int(rating)]
if metadata['art'] is not None:
if metadata.get('art') is not None:
image_format = 14 if metadata['mime'].endswith('png') else 13
img_data = b64decode(metadata['art'])
audio['covr'] = [MP4Cover(img_data, imageformat=image_format)]
Expand All @@ -500,7 +500,7 @@ def set_metadata(file_path: str, metadata: dict):
audio['album'] = [album]
audio['rtng'] = [rating]
audio['trkn'] = track_place
if metadata['art'] is not None:
if metadata.get('art') is not None:
img_data = metadata['art'] # b64 data
audio['metadata_block_picture'] = img_data
audio['mime'] = metadata['mime']
Expand All @@ -514,7 +514,7 @@ def set_metadata(file_path: str, metadata: dict):
audio['TRACKNUMBER'] = track_number # type: ignore
audio['TRACKTOTAL'] = track_place.split('/')[1] # type: ignore
audio['ITUNESADVISORY'] = rating # type: ignore
if metadata['art'] is not None:
if metadata.get('art') is not None:
if ext == '.flac':
img_data = b64decode(metadata['art'])
pic = mutagen.flac.Picture()
Expand All @@ -527,6 +527,7 @@ def set_metadata(file_path: str, metadata: dict):
audio['APIC:'] = metadata['art'] # type: ignore
audio['mime'] = metadata['mime'] # type: ignore
else:
# remove existing album art
if ext == '.flac':
audio.clear_pictures() # type: ignore
else:
Expand Down Expand Up @@ -1279,7 +1280,7 @@ def custom_art(text):

def get_youtube_comments(url, limit=-1): # -> generator
# TODO: use proxies = get_proxy()
return YTCommentDLer.get_comments_from_url(url, sort_by=SORT_BY_POPULAR, limit=limit)
return yt_comment_downloader.get_comments_from_url(url, sort_by=SORT_BY_POPULAR, limit=limit)


def timestamp_to_time(text):
Expand Down

0 comments on commit a08e535

Please sign in to comment.