This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrofi-anime
executable file
·61 lines (50 loc) · 1.85 KB
/
rofi-anime
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import subprocess
import os
endstring=".mkv"
def update_bookmark(dir,number):
with open(dir+"/.bookmark",'w') as f:
f.write(number)
def read_bookmark(dir):
if not os.path.isfile(dir+"/.bookmark"):
update_bookmark(dir,"1")
return "1"
with open(dir+"/.bookmark","r") as f:
return(f.readlines()[0].replace("\n",""))
def call_rofi(entries,command):
proc = subprocess.Popen(command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
for e in entries:
proc.stdin.write((e+"\n").encode('utf-8'))
proc.stdin.close()
answer = proc.stdout.read().decode('utf-8')
return answer.replace("\n","")
def get_chapter(file):
name,number = file.replace(endstring,"").split(" - ")
return int(number)
def get_files(dir):
chapters = [file for file in os.listdir(dir) if file.endswith(endstring)]
chapters.sort(key=lambda file: get_chapter(file))
return chapters
def get_folders(dir):
return [file for file in os.listdir(dir) if os.path.isdir(dir+"/"+file)]
def choose_folder(dir):
command = ['rofi','-dmenu','-lines','4','-i','-p',"Anime"]
folders = get_folders(dir)
folder = call_rofi(folders,command)
return folder if folder in folders else None
def choose_chapter(dir):
command = ['rofi','-dmenu','-lines','4','-i','-p',"Chapter\nLast Chapter "+read_bookmark(dir)]
chapters = get_files(dir)
chapter = call_rofi(chapters,command)
return chapter if chapter in chapters else None
dir = "/home/alex/Videos/Anime/"
folder = choose_folder(dir)
if folder != None:
chapter = choose_chapter(dir+"/"+folder)
if chapter != None:
chapter_dir = dir+"/"+folder+"/"+chapter
chapter_number = str(get_chapter(chapter_dir))
update_bookmark(dir+"/"+folder,chapter_number)
subprocess.Popen(['mpv',chapter_dir])