moar
This commit is contained in:
parent
89cd4a3b20
commit
ee8391fbc7
1 changed files with 23 additions and 10 deletions
|
@ -10,20 +10,26 @@ def read_conf():
|
|||
conf['configuration']['mq_user'],
|
||||
conf['configuration']['mq_password'])
|
||||
|
||||
|
||||
def remaining_space_gb():
|
||||
from shutil import disk_usage
|
||||
total, used, free = disk_usage("/")
|
||||
return free / 1024**3
|
||||
|
||||
|
||||
def pop():
|
||||
def all_transcodes():
|
||||
folder_path = '/var/lib/jellyfin/transcodes'
|
||||
files = os.listdir(folder_path)
|
||||
a = []
|
||||
for file in files:
|
||||
file_path = os.path.join(folder_path, file)
|
||||
creation_time = os.path.getctime(file_path)
|
||||
a.append((file, creation_time))
|
||||
space = os.path.getsize(file_path)
|
||||
a.append((file, creation_time, space))
|
||||
return a
|
||||
|
||||
|
||||
def pop(files):
|
||||
if a:
|
||||
a.sort(key=lambda t: t[1])
|
||||
return a[0]
|
||||
|
@ -31,7 +37,7 @@ def pop():
|
|||
return None
|
||||
|
||||
|
||||
def send_to_mq(mq_host, mq_user, mq_pass, space_rem):
|
||||
def send_to_mq(mq_host, mq_user, mq_pass, space_rem, transcode_space):
|
||||
import pika
|
||||
import json
|
||||
creds = pika.PlainCredentials(mq_user, mq_pass)
|
||||
|
@ -40,7 +46,7 @@ def send_to_mq(mq_host, mq_user, mq_pass, space_rem):
|
|||
channel = conn.channel()
|
||||
|
||||
space_rem = round(space_rem, 2)
|
||||
msg = f'Paperino, manca spazio su disco: {space_rem}'
|
||||
msg = f'Paperino, manca spazio su disco: {space_rem}|{transcode_space}'
|
||||
ROOM_ID = '!KABwGlTSmXAbzCOhCX:goulash.lezzo.org'
|
||||
|
||||
response = {
|
||||
|
@ -60,14 +66,21 @@ def send_to_mq(mq_host, mq_user, mq_pass, space_rem):
|
|||
def main(mq_host, mq_user, mq_pass):
|
||||
while True:
|
||||
space_rem = remaining_space_gb()
|
||||
send_to_mq(mq_host, mq_user, mq_pass, space_rem)
|
||||
if space_rem < 1.0:
|
||||
send_to_mq(mq_host, mq_user, mq_pass, space_rem)
|
||||
|
||||
if space_rem >= 1.0:
|
||||
time.sleep(60)
|
||||
else:
|
||||
files = all_transcodes()
|
||||
total_space = sum(map(lambda t: t[2], files))
|
||||
send_to_mq(mq_host, mq_user, mq_pass, space_rem, total_space)
|
||||
|
||||
while remaining_space_gb() < 2.0:
|
||||
file = pop()
|
||||
file = pop(files)
|
||||
if not file:
|
||||
break
|
||||
else:
|
||||
os.remove(file)
|
||||
time.sleep(60)
|
||||
files = all_transcodes()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue