Update converter.py

This commit is contained in:
Doublefire.Chen
2022-11-04 14:15:39 +08:00
parent 394d077550
commit b22460c315
+12 -26
View File
@@ -1,9 +1,8 @@
import os, re, sys, itertools, json, requests, base64, linecache, time, requests, webbrowser, bs4, time, pyautogui, pyperclip, urllib3, pprint, shutil, platform, subprocess import os, re, sys, itertools, json, requests, base64, linecache, time, requests, bs4, time, pyautogui, pyperclip, urllib3, pprint, shutil, platform, subprocess
import urllib.request
import downloader import downloader
from pathlib import Path #using this module to solve difference path syntax between Mac OS and Windows
host_folder = downloader.host_dir host_folder = downloader.host_dir #get work path
os.chdir(host_folder) os.chdir(host_folder) #change path to work path
lyrics_url = downloader.lyrics_url lyrics_url = downloader.lyrics_url
# Read in the jumbled Spotify lyric text # Read in the jumbled Spotify lyric text
@@ -26,22 +25,9 @@ if substring_403 in fullstring:
quit() quit()
# exception with no token, just redownloads it based on lyrics_url # exception with no token, just redownloads it based on lyrics_url
elif substring_401 in fullstring: elif substring_401 in fullstring:
print("Error, no token found, retrying once") print("Error, token has been expired, please open the browser to get a new one and restart the program")
link_for_cookie = "https://open.spotify.com/lyrics" os._exit(0)
lyrics = webbrowser.open(link_for_cookie, new=0, autoraise=True)
time.sleep(10)
lyrics = webbrowser.open(lyrics_url, new=0, autoraise=True)
time.sleep(1.2)
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl', 'c')
time.sleep(0.1)
pyautogui.hotkey('ctrl', 'w')
pyautogui.hotkey('ctrl', 'w')
print("tab closed")
lyricdata = pyperclip.paste()
z = open("lyrics.txt", "w", encoding="utf-8")
z.write(lyricdata)
z.close()
#exception for successful lyric grab #exception for successful lyric grab
elif substring_success in fullstring: elif substring_success in fullstring:
print("Lyric grab was success, converting now...") print("Lyric grab was success, converting now...")
@@ -60,6 +46,7 @@ filedata = filedata.replace('"', '')
filedata = filedata.replace('hasVocalRemoval:false}', '') filedata = filedata.replace('hasVocalRemoval:false}', '')
filedata = filedata.replace(']', '] ') filedata = filedata.replace(']', '] ')
filedata = filedata.replace('\\', '*') filedata = filedata.replace('\\', '*')
filedata = filedata.replace(',syllables:[] ,endTimeMs:0}', '')
# Write the file out # Write the file out
with open('lyricsfixed.lrc', 'w') as file: with open('lyricsfixed.lrc', 'w') as file:
@@ -262,8 +249,8 @@ os.remove("lyricsfixed.lrc")
os.remove("lyricstimingsremoved.txt") os.remove("lyricstimingsremoved.txt")
os.remove("timingsfixed.lrc") os.remove("timingsfixed.lrc")
os.remove("lyrics.txt") os.remove("lyrics.txt")
os.remove("currentsong.txt")
print(downloader)
#set up variables for moving lyric and setting up cover.jpg location #set up variables for moving lyric and setting up cover.jpg location
host_folder = downloader.host_dir host_folder = downloader.host_dir
lyrics = "Lyrics" lyrics = "Lyrics"
@@ -271,9 +258,9 @@ artist_name = downloader.artist_name
albumdir = downloader.albumdir albumdir = downloader.albumdir
song = downloader.song song = downloader.song
cover = downloader.lyrics_url cover = downloader.lyrics_url
originallyricsfile = (host_folder + "\\output.lrc") originallyricsfile = (Path(host_folder)/"output.lrc")
movedlyricsfile = (albumdir + "\\" + downloader.track_number + ". " + song + ".lrc") movedlyricsfile = (Path(albumdir)/(str(downloader.track_number) + ". " + str(song) + ".lrc"))
movedcoverjpg = (albumdir + "\\" + "cover.jpg") movedcoverjpg = (Path(albumdir)/"cover.jpg")
#prints folder where lyric went #prints folder where lyric went
print("\n") print("\n")
@@ -290,4 +277,3 @@ def open_file(path):
subprocess.Popen(["xdg-open", path]) subprocess.Popen(["xdg-open", path])
open_file(albumdir) open_file(albumdir)