1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import gzip
import re
import subprocess
import sys
import urllib.request
# NO EXTERNAL DEPENDENCIES YAY
# Wait does mpv count???
# Gimme a video ID
cur = sys.argv[1]
while True:
# First start mpv in the background
# Make sure mpv doesn't take in any input
# Also enable subtitles because why not
proc = subprocess.Popen(['mpv', '--no-video', '--no-input-default-bindings', '--slang=zh-CN', 'https://www.bilibili.com/video/' + cur])
try:
# I could use requests...
# Nope, external dependencies suck, so enjoy this abomination
body = gzip.decompress(urllib.request.urlopen('https://www.bilibili.com/video/' + 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(cur, re.search('<title data-vue-meta="true">(.*?)<', body).group(1))
# Get recommended stuff
rec = [
(re.search('/video/(.*?)/', line).group(1), re.search('title="(.*?)"', line).group(1))
for line in body.split('\n') if 'recommend_more' in line
]
# Print it out the smart way!
print(*enumerate(rec), sep='\n')
# Choose a recommended video
# If you don't like any, just stop the app, burn your computer, and try again
cur = rec[int(input())][0]
print(cur)
finally:
# Kill mpv with fire because sometimes it likes the music too much and refuses to stop if you ask nicely
proc.kill()
|