aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/main.py b/main.py
index ba771e8..a3f8c52 100755
--- a/main.py
+++ b/main.py
@@ -15,9 +15,10 @@ url = 'https://www.bilibili.com/video/'
cur = sys.argv[1]
while True:
# First start mpv in the background
- # Make sure mpv doesn't take in any input
+ # Disable mpv keyboard input
+ # That took me a stupidly long time to figure out
# Also enable subtitles because why not
- proc = subprocess.Popen(['mpv', '--no-video', '--no-input-default-bindings', '--slang=zh-CN', url + cur])
+ proc = subprocess.Popen(['mpv', '--no-video', '--no-input-terminal', '--slang=zh-CN', url + cur])
# The try finally block is to ensure that proc gets killed no matter what
try:
# I could use requests...
@@ -25,10 +26,14 @@ while True:
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', cur, re.search('<title data-vue-meta="true">(.*?)<', body).group(1))
+ print('NOW PLAYING', cur, re.search('"true">(.*?)<', body).group(1))
# Get recommended stuff
rec = [
- (re.search('/video/(.*?)/', line).group(1), re.search('title="(.*?)"', line).group(1))
+ (
+ re.search('/video/(.*?)/', line).group(1),
+ re.search('title="(.*?)"', line).group(1),
+ re.search('"name">(.*?)<', line).group(1)
+ )
for line in body.split('\n') if 'recommend_more' in line
]
# Print it out the smart way!