aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2023-05-31 16:41:45 -0500
committerAnthony Wang2023-05-31 16:41:45 -0500
commit71b2bda6e0d29bafe8257d5c3a497dbc12e2b9c3 (patch)
treed38a93154e2ba8327241897e73bb16568862e0e1
parent907c25b94faf38a77b07d6e3558f0c805ab51739 (diff)
Add main.py
-rw-r--r--main.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..7bd135c
--- /dev/null
+++ b/main.py
@@ -0,0 +1,20 @@
+import gzip
+import re
+import subprocess
+import sys
+import urllib.request
+
+cur = sys.argv[1]
+while True:
+ proc = subprocess.Popen(['mpv', '--no-video', '--no-input-default-bindings', '--slang=zh-CN', 'https://www.bilibili.com/video/' + cur])
+ try:
+ body = gzip.decompress(urllib.request.urlopen('https://www.bilibili.com/video/' + cur).read()).decode('utf-8')
+ print(cur, re.search('<title data-vue-meta="true">(.*?)<', body).group(1))
+ 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(*enumerate(rec), sep='\n')
+ cur = rec[int(input())][0]
+ finally:
+ proc.kill()