added synced lyrics

This commit is contained in:
Brandon4466
2023-01-11 11:16:31 -08:00
parent 68183931c1
commit bbd9e7a0a3
5 changed files with 115 additions and 7 deletions

View File

@@ -1 +1 @@
{"access_token": "BQAqKVHJsNl_kpE1qwGfqWAnFRKSPdrXMdJUuIkquM2H0gqmIeQFJJfNoOwib9R0JKFSvB7ZUyB1IlpzyHBAY0QQpvqdqorQXj4fraqgHVUCvQpb7Bg6ee4wn_urnF7nSzaZe7fnNEHZIH18XqSCSx73XoPk-UdTkvi3kxxOO6vH8tsAah7GHEUnrMlG7g", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "AQDs4x9WTbYtoqePbR9tvRWCcJHs1Hh3vrXpIHBtBdkJIDJ-Mu14B-vLEqOnowqw1HzZI5H5ytOFS2y9xBCcDyDU0uMA_D0MRPtujyCUYb9sdnD-D6WC2fN7bFiGeoo-YAo", "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673401175}
{"access_token": "BQC2e3LU31cnEU0wNqqtrcWUrhsiMvTo7uO4Ypujo-RvZ0eonbYIyb5rwEdZj5GlN60dp3OFUq0xQcsliPiFRYUbGLCEc7de2l6IE4XKq-4WZFRw29RJ4TVHaKLERPI9cGcIgS3koLKHxSAomRGRkIAOOsfAU6Nu5CSTemp793_B22-PRWIC4XR7QMd7gQ", "token_type": "Bearer", "expires_in": 3600, "scope": "user-modify-playback-state user-read-playback-state", "expires_at": 1673465722, "refresh_token": "AQDs4x9WTbYtoqePbR9tvRWCcJHs1Hh3vrXpIHBtBdkJIDJ-Mu14B-vLEqOnowqw1HzZI5H5ytOFS2y9xBCcDyDU0uMA_D0MRPtujyCUYb9sdnD-D6WC2fN7bFiGeoo-YAo"}

50
Photograph Ed Sheeran.lrc Normal file
View File

@@ -0,0 +1,50 @@
[00:00.000] 作词 : Ed Sheeran/Johnny McDaid/Thomas Leonard/Martin Harrington
[00:01.000] 作曲 : Ed Sheeran/Johnny McDaid/Thomas Leonard/Martin Harrington
[00:17.250]Loving can hurt
[00:21.670]Loving can hurt sometimes
[00:26.220]But its the only thing that I know
[00:34.790]When it gets hard
[00:39.010]You know it can get hard sometimes
[00:44.010]It is the only thing that makes us feel alive
[00:54.290]We keep this love in a photograph
[00:58.540]We made these memories for ourselves
[01:02.410]Where our eyes are never closing
[01:04.870]Our hearts were never broken
[01:07.250]And times forever frozen still
[01:10.800]So you can keep me inside the pocket of your ripped jeans
[01:18.290]Holding me closer'til our eyes meet
[01:22.640]You won't ever be alone
[01:27.380]Wait for me to come home
[01:32.920]Loving can heal
[01:37.020]Loving can mend your soul
[01:41.710]And its the only thing that I know, know
[01:50.070]I swear it will get easier
[01:54.010]Remember that with every piece of ya
[01:59.140]And its the only thing we take with us when we die
[02:10.070]We keep this love in a photograph
[02:14.210]We made these memories for ourselves
[02:18.040]Where our eyes are never closing
[02:20.350]Our hearts were never broken
[02:22.620]And times forever frozen still
[02:26.440]So you can keep me inside the pocket of your ripped jeans
[02:33.840]Holding me closer'til our eyes meet
[02:38.160]You won't ever be alone
[02:44.240]And if you hurt me thats okay baby
[02:48.740]Only words bleed
[02:51.590]Inside these pages you just hold me
[02:55.800]And I won't ever let you go
[03:00.780]Wait for me to come home ×4
[03:20.020]Oh you can fit me inside the necklace you got
[03:24.850]When you were sixteen
[03:27.180]Next to your heartbeat where I should be
[03:31.590]Keep it deep within your soul
[03:37.590]And if you hurt me
[03:40.390]But thats okay baby
[03:42.100]Only words bleed
[03:44.670]Inside these pages you just hold me
[03:49.230]I won't ever let you go
[03:55.300]When Im away
[03:58.380]I will remember how you kissed me
[04:02.880]Under the lamppost back on 6th street
[04:07.060]Hearing you whisper through the phone
[04:11.840]Wait for me to come home

BIN
icons/lyrics.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

6
lyrics.py Normal file
View File

@@ -0,0 +1,6 @@
import syncedlyrics
import pylrc
lrc = syncedlyrics.search("[Photograph] [Ed Sheeran]")
print(lrc)

View File

@@ -13,6 +13,8 @@ import os
import pyautogui
import threading
import platform
import syncedlyrics
import textwrap
# Set the Spotify app's client ID and client secret
client_id = "69b82a34d0fb40be80b020eae8e80f25"
@@ -76,8 +78,13 @@ def oauthLogin():
threading.Thread(target=oauthLogin).start()
token = spotipy.util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
# Create a Spotify object with the user's authorization token
spotify = spotipy.Spotify(auth=token)
def createToken():
spotify = spotipy.Spotify(auth=token)
return spotify
spotify = createToken()
# Create the tkinter window
root = ttk.Tk()
@@ -160,11 +167,24 @@ def get_devices():
unloadSearching_Devices()
loadDevices_list()
devices_list.delete(0, ttk.END)
try:
list_of_devices = spotify.devices()
except (spotipy.exceptions.SpotifyException, requests.exceptions.HTTPError):
createToken()
pass
list_of_devices = spotify.devices()
for num_of_device, garbage in enumerate(list_of_devices["devices"]):
devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"])
root.after(6500, get_devices)
def loadLyrics_pressed():
unloadNow_playing()
loadLyrics()
def unloadLyrics_pressed():
unloadLyrics()
loadNow_playing()
# def hide_devices():
# get_devices_button.grid()
# devices_list.grid_remove()
@@ -176,6 +196,7 @@ play_img = ttk.PhotoImage(file="icons/play-circle-x2.png")
pause_img = ttk.PhotoImage(file="icons/pause-circle-x2.png")
next_img = ttk.PhotoImage(file="icons/skip-next-x2.png")
previous_img = ttk.PhotoImage(file="icons/skip-previous-x2.png")
lyrics_img = ttk.PhotoImage(file="icons/lyrics.png")
# album_art_img = ttk.PhotoImage(file="album_art.png")
# canvas = ttk.Canvas(root, width=480, height=320)
@@ -184,6 +205,7 @@ previous_img = ttk.PhotoImage(file="icons/skip-previous-x2.png")
frame_artist_song = tk.Frame(root)
frame_controls = tk.Frame(root)
lyrics_button = tk.Frame(root)
root.grid_rowconfigure(0, weight=1)
root.grid_rowconfigure(1, weight=1)
@@ -219,13 +241,21 @@ progress_bar = tk.Progressbar(root, orient=ttk.HORIZONTAL, length=480)
searching_for_devices_label = tk.Label(root, text="Searching for Devices...", font=("Helvetica", 24))
device_name_label = tk.Label(frame_artist_song, text="", font=("Helvetica", 12))
# background_image_label = tk.Label(root, image=album_art_img)
lyrics_label = tk.Label(root, text="", font=("Helvetica", 32))
loadLyrics_button = ttk.Button(lyrics_button, image=lyrics_img, command=loadLyrics_pressed, borderwidth=0)
now_playing_button = tk.Button(root, text="Now Playing", command=unloadLyrics_pressed)
root.bind("<Return>", search)
# Function to update the song label with the current track's name
def update_song_label():
global lrc
# Get the current playback information
try:
current_playback = spotify.current_playback()
except (spotipy.exceptions.SpotifyException, requests.exceptions.HTTPError):
createToken()
pass
# If there is no current playback, set the text of the song label to "No playback"
if current_playback is None:
# nothing_playing_obj = '{"item": {"artists": [{"name": "Nothing Playing"}],"duration_ms": 0,"name": "Nothing Playing"},"progress_ms": 0}'
@@ -233,6 +263,12 @@ def update_song_label():
get_devices()
# Update the song label every 1 second
else:
try:
track_name = current_playback["item"]["name"]
pass
except TypeError:
sleep(1)
update_song_label()
track_name = current_playback["item"]["name"]
artist_name = current_playback["item"]["artists"][0]["name"]
track_duration = current_playback["item"]["duration_ms"]
@@ -255,11 +291,17 @@ def update_song_label():
# print("this is the same image")
# else:
# pass
loadNow_playing()
# loadNow_playing()
if track_name == song_label.cget("text"):
track_progress_label.config(text=("{}:{:02d}".format(track_progress_min, track_progress_sec)))
track_progress_formatted = ("{}:{:02d}".format(track_progress_min, track_progress_sec))
track_progress_label.config(text=track_progress_formatted)
progress_bar.config(maximum=track_duration)
progress_bar.config(value=track_progress)
for line in str(lrc).splitlines():
if track_progress_formatted in line:
lyric = line.split("]")[1]
wrapped_lyric = textwrap.fill(lyric, 21)
lyrics_label.config(text=wrapped_lyric)
root.after(1000, update_song_label)
else:
# album_art_data = Image.open(requests.get(album_art_url, stream=True).raw)
@@ -269,6 +311,7 @@ def update_song_label():
artist_label.config(text=artist_name)
track_duration_label.config(text=("{}:{:02d}".format(track_duration_min, track_duration_sec)))
volumeslider_button.set(value=current_volume)
lrc = syncedlyrics.search("[" + track_name + "] [" + artist_name + "]")
root.after(1000, update_song_label)
# if album_art_url == "12345":
# open_url = urlopen(album_art_url)
@@ -290,9 +333,11 @@ def update_song_label():
def loadNow_playing():
# background_image_label.place(x=0, y=0)
volumeslider_button.grid(row=1, column=1, rowspan=3, sticky="e", padx=(0,20))
lyrics_button.grid(row=1, column=1, padx=(0,380))
frame_artist_song.grid(row=1, column=1, pady=(0,5))
frame_controls.grid(row=2, column=1, pady=(20,0))
device_name_label.grid(pady=(0,10))
loadLyrics_button.grid()
device_name_label.grid()
artist_label.grid()
song_label.grid()
previous_button.grid(row=0, column=0, padx=(0,10))
@@ -310,6 +355,7 @@ def unloadNow_playing():
play_button.grid_forget()
next_button.grid_forget()
progress_bar.grid_forget()
loadLyrics_button.grid_forget()
def loadDevices_list():
devices_list.grid(row=1, column=1, pady=10)
@@ -325,11 +371,17 @@ def loadSearching_Devices():
def unloadSearching_Devices():
searching_for_devices_label.grid_forget()
def loadLyrics():
now_playing_button.grid(row=0, column=1)
lyrics_label.grid(row=1, column=1, pady=20)
def unloadLyrics():
now_playing_button.grid_forget()
lyrics_label.grid_forget()
# Start updating the song label
wait_for_connection()
loadNow_playing()
update_song_label()
# Run the GUI