aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorAnthony Wang2023-07-21 18:48:40 -0500
committerAnthony Wang2023-07-21 18:48:40 -0500
commit5aee36caa754ed29295cc7b4d8f6cd9c61182d11 (patch)
tree0fd1df1d4199436fd23a6ea24a5ff85890a736c8 /main.py
parent7267b6eb927ea9e2a43f3d5d24484c854403fbde (diff)
Remove redundant try finally blockHEADmaster
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py49
1 files changed, 22 insertions, 27 deletions
diff --git a/main.py b/main.py
index b8008c8..91575ed 100755
--- a/main.py
+++ b/main.py
@@ -17,33 +17,28 @@ while True:
# First start mpv in the background
# Also enable subtitles because why not
proc = subprocess.Popen(['mpv', '--no-video', '--slang=zh-CN', url + cur])
- # The try finally block is to ensure that proc gets killed no matter what
- try:
- # I could use the Python requests library...
- # Nope, external dependencies suck, so enjoy this abomination
- body = gzip.decompress(urllib.request.urlopen(url + cur).read()).decode('utf-8')
- # Sometimes I forget what I'm even listening to
- # I WILL parse HTML with regex, you can't stop me
- print('NOW PLAYING', url + cur, re.search('"true">(.*?)<', body).group(1))
- # Get recommended stuff
- # I figured out the regexes by playing around with curl --compressed and then grepping
- lines = body.split('\n')
- rec = [
- (
- re.search('/video/(.*?)/', line).group(1), # ID
- re.search('title="(.*?)"', line).group(1), # Video name
- re.search('"name">(.*?)<', line).group(1), # up主 name
- lines[i + 1].strip() # View count
- )
- for i, line in enumerate(lines) if 'recommend_more' in line
- ]
- # Print it out the smart way!
- # Who needs loops smh
- print(*enumerate(rec), sep='\n')
- proc.wait()
- finally:
- # Kill mpv with fire because sometimes it likes the music too much and refuses to stop if you ask nicely
- proc.kill()
+ # I could use the Python requests library...
+ # Nope, external dependencies suck, so enjoy this abomination
+ body = gzip.decompress(urllib.request.urlopen(url + cur).read()).decode('utf-8')
+ # Sometimes I forget what I'm even listening to
+ # I WILL parse HTML with regex, you can't stop me
+ print('NOW PLAYING', url + cur, re.search('"true">(.*?)<', body).group(1))
+ # Get recommended stuff
+ # I figured out the regexes by playing around with curl --compressed and then grepping
+ lines = body.split('\n')
+ rec = [
+ (
+ re.search('/video/(.*?)/', line).group(1), # ID
+ re.search('title="(.*?)"', line).group(1), # Video name
+ re.search('"name">(.*?)<', line).group(1), # up主 name
+ lines[i + 1].strip() # View count
+ )
+ for i, line in enumerate(lines) if 'recommend_more' in line
+ ]
+ # Print it out the smart way!
+ # Who needs loops smh
+ print(*enumerate(rec), sep='\n')
+ proc.wait()
# Choose a recommended video
# If you don't like any, just stop the app, burn your computer, and try again
cur = rec[int(input("Choose next: "))][0]