-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpv_ed2k.py
executable file
·42 lines (35 loc) · 1.15 KB
/
mpv_ed2k.py
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
37
38
39
40
41
42
#!/usr/bin/python3
import os.path
import subprocess
import re
import anime
import configparser
import argparse
def get_config(config_file=os.path.expanduser("~/.config/weltschmerz/weltschmerz.cfg")):
config = configparser.ConfigParser()
config.read_file(open(config_file))
parser = argparse.ArgumentParser(
description="Play file matching ed2k in the database."
)
parser.add_argument(
"--database", help="database to use", default=config.get("client", "database")
)
parser.add_argument("ed2k", help="ed2k hash to query")
args = parser.parse_args()
return args
if __name__ == "__main__":
config = get_config()
dbs = anime.DatabaseSession(config.database, False)
# try:
uri = config.ed2k
ed2k_match = re.match(r"(mpv-ed2k://)?(?P<ed2k>[0-9A-Fa-f]{32})", uri)
ed2k = ed2k_match.group("ed2k")
local_file = (
dbs.session.query(anime.LocalFile)
.filter(anime.LocalFile.hash_ed2k == ed2k)
.first()
)
if local_file:
print(local_file.directory)
print(local_file.filename)
subprocess.call(["mpv", "--load-scripts=no", local_file.full_path])