From bbd9e7a0a315083ed12c9444ca3b4f05acc04982 Mon Sep 17 00:00:00 2001 From: Brandon4466 Date: Wed, 11 Jan 2023 11:16:31 -0800 Subject: [PATCH] added synced lyrics --- .cache-thebrandon45 | 2 +- Photograph Ed Sheeran.lrc | 50 +++++++++++++++++++++++++++++ icons/lyrics.png | Bin 0 -> 867 bytes lyrics.py | 6 ++++ program-embedded.py | 64 ++++++++++++++++++++++++++++++++++---- 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 Photograph Ed Sheeran.lrc create mode 100644 icons/lyrics.png create mode 100644 lyrics.py diff --git a/.cache-thebrandon45 b/.cache-thebrandon45 index b4c65c1..8863fdb 100644 --- a/.cache-thebrandon45 +++ b/.cache-thebrandon45 @@ -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} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/Photograph Ed Sheeran.lrc b/Photograph Ed Sheeran.lrc new file mode 100644 index 0000000..a69f658 --- /dev/null +++ b/Photograph Ed Sheeran.lrc @@ -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 it’s 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 it’s 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 it’s 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 that’s 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 that’s 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 I’m 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 diff --git a/icons/lyrics.png b/icons/lyrics.png new file mode 100644 index 0000000000000000000000000000000000000000..02b5e647b0dcdda12186a30ff46dc702b41e4453 GIT binary patch literal 867 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmUKs7M+SzC{oH>NS%G|oWRD45dJguM!v-tY$DUh!@P+6=(yLU`z6LcLCBs@Y8vBJ&@uo z@Q5r1(g|SvA=~LZ0|Qg4r;B4q#=W;QY_mfgCEU)>me^vnLc&Moh*GOsf>g7RqDN52 zjgGxx|Cm|Vy8Pi?l%&0F;}*kr&ki5sH*pi@6jO`nIMzR7f#>7oiP914i=W4pzkiog z$e&}p*?7+Lxw2(x3xGgDW!iC-NmUKP2NW)_e_`0&@a=`R_5t$*!5Pf+m{g6Uxu(Sg zEnjkaQd)?u@kN=ry&~_Yl|)~1<9$?kZL#I<*P8dVUUn_nDs%Ml8dvR0v$oevUvko_ z>-fwmSEf#{*}r5d+o}AG8Y}J3o)3Cb-Kd!mzs`Hs-17%E%-s9;J;S71jp+{g3O{x4 zF}k10IePWxBgu-@oKHGs^3+PL!W}Mg7|7kSIksY^?J21QDGRw<7RRQ{?n<`leb+`LfN_Rr&ITo-ceW!KNvKCtk@G`U}oc-Pr(;LG99opqpX=GzrH z87s?{IsEA}-@#PFnfvl#_B4iKpte0Hg%Yf`ENwp?$#jQ5_hq7vX~WFDNuN3H=1e*J zrZlUeWA(yZ*_d)uE9M!Ik~_q2?P%Ja7FM)Nt#`r};R?SW)(4pkGScj0=62SnTx79ky z%^6E3Pnz{g?D;O?c;<7An=d}+G{{S{cRnp9A|hfUU(X<^Hzh9a@6{*3l&4za8c~vx zSdwa$T$Bo=7>o>zjCBnRbqx(e3@xn;46ICzw1K370iW*E*C-lt^HVa@DsgM5FNh5X PYGCkm^>bP0l+XkKNR42v literal 0 HcmV?d00001 diff --git a/lyrics.py b/lyrics.py new file mode 100644 index 0000000..78318fe --- /dev/null +++ b/lyrics.py @@ -0,0 +1,6 @@ +import syncedlyrics +import pylrc + +lrc = syncedlyrics.search("[Photograph] [Ed Sheeran]") + +print(lrc) \ No newline at end of file diff --git a/program-embedded.py b/program-embedded.py index 68f65ef..a7133cf 100644 --- a/program-embedded.py +++ b/program-embedded.py @@ -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("", search) # Function to update the song label with the current track's name def update_song_label(): + global lrc # Get the current playback information - current_playback = spotify.current_playback() + 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