Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability improvements #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 21 additions & 17 deletions SmolPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class SmolPlayer:
def __init__(self):
def __init__(self, window):
directory = getcwd()
chdir(directory)
self.ticker = 0
Expand All @@ -36,7 +36,7 @@ def __init__(self):
self.volume = 42
self.run = True
self.threadLock = threading.Lock()
self.window = tkinter.Tk()
self.window = window
self.window.title('SmolPlayer')
self.window.configure(background='#323740')
self.width, self.height = self.window.winfo_screenwidth(), self.window.winfo_screenheight()
Expand Down Expand Up @@ -172,7 +172,8 @@ def play(self):
self.player.stop()
self.play()
except Exception as error:
self.threadLock.release()
if self.threadLock.locked():
self.threadLock.release()
if 'ssl' and 'SSL' in str(error):
messagebox.showwarning(title="Python Needs to Be Installed",
message="Because of SSL security issues, you need to install Python on your Mac if you want to use this app.")
Expand Down Expand Up @@ -205,6 +206,8 @@ def shuffle(self):
with open('urllist.txt', 'r', encoding='utf-8') as f:
urls = f.readlines()
combined = list(zip(songs, urls))
if not combined:
return
shuffle(combined)
songs[:], urls[:] = zip(*combined)
with open('songlist.txt', 'w', encoding='utf-8') as f:
Expand All @@ -222,15 +225,11 @@ def pause(self):
self.playButton.config(state='normal')
self.pauseButton.place_forget()
self.playButton.place(x=300, y=10)
else:
pass

def set_volume(self, amount):
try:
if self.player:
self.player.audio_set_volume(int(amount))
self.volume = amount
except:
pass

def set_scrubber(self, amount):
try:
Expand All @@ -240,7 +239,8 @@ def set_scrubber(self, amount):
self.musicScrubber.set(0)

def skip(self):
self.player.stop()
if self.player:
self.player.stop()
self.paused = False

def add(self, event=None):
Expand Down Expand Up @@ -289,11 +289,12 @@ def add(self, event=None):
f.write(f'{songTitle}\n')
self.refresh()
break
else:
pass

def up_next(self):
index = int(self.queueBox.curselection()[0])
selected = self.queueBox.curselection()
if len(selected) == 0:
return
index = int(selected[0])
with open('songlist.txt', 'r', encoding='utf-8') as f:
songs = f.readlines()
with open('urllist.txt', 'r', encoding='utf-8') as f:
Expand Down Expand Up @@ -344,6 +345,8 @@ def check(self, url):

def delete_song(self, event=None):
selected = self.queueBox.curselection()
if len(selected) == 0:
return
self.queueBox.delete(selected)
selected = int(selected[0])
with open("songlist.txt", "r", encoding='utf-8') as f:
Expand Down Expand Up @@ -390,8 +393,9 @@ def on_closing(self):


if __name__ == '__main__':
if not os.path.exists('songlist.txt'):
os.system('touch songlist.txt')
if not os.path.exists('urllist.txt'):
os.system('touch urllist.txt')
SmolPlayer()
for filename in ['songlist.txt', 'urllist.txt']:
if not os.path.exists(filename):
open(filename, 'w').close()
mainWindow = tkinter.Tk()
SmolPlayer(mainWindow)
mainWindow.quit()
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
youtube-dl
requests
python_vlc
pafy
beautifulsoup4