diff options
author | Anthony Wang | 2023-05-31 17:17:16 -0500 |
---|---|---|
committer | Anthony Wang | 2023-05-31 17:17:16 -0500 |
commit | ebf8314278d6e45b95fc6b0d70f04d0fc86ce2d7 (patch) | |
tree | 3646b9adf5ba7ea7781f9ec078daaffaa689f025 | |
parent | a1998c647aa51ceb0e7a9f83d364176d9074f9e8 (diff) |
Show video author, actually disable mpv keyboard input
-rwxr-xr-x | main.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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! |