video-stream/driver/queues.py

55 lines
1.2 KiB
Python
Raw Normal View History

from os import remove
2022-01-31 12:01:11 +00:00
QUEUE = {}
def clean_trash(file_name: str, cid: int, clear_all: bool = False):
for i in QUEUE:
chat_queue = QUEUE[i][1:] if (i == cid and (not clear_all)) else QUEUE[i]
for f in chat_queue:
if f[1] == file_name:
file_name = None
break
if file_name:
try:
remove(file_name)
except FileNotFoundError:
pass
2022-01-31 12:01:11 +00:00
def add_to_queue(chat_id, songname, link, ref, type, quality):
if chat_id in QUEUE:
chat_queue = QUEUE[chat_id]
chat_queue.append([songname, link, ref, type, quality])
return int(len(chat_queue) -1)
2022-01-31 12:01:11 +00:00
else:
QUEUE[chat_id] = [[songname, link, ref, type, quality]]
2022-01-31 12:01:11 +00:00
def get_queue(chat_id):
if chat_id in QUEUE:
chat_queue = QUEUE[chat_id]
return chat_queue
else:
return 0
2022-01-31 12:01:11 +00:00
def pop_an_item(chat_id):
if chat_id in QUEUE:
chat_queue = QUEUE[chat_id]
chat_queue.pop(0)
return 1
else:
return 0
2022-01-31 12:01:11 +00:00
def clear_queue(chat_id):
if chat_id in QUEUE:
for i in QUEUE[chat_id]:
if "t.me" in i[2]:
clean_trash(i[1], chat_id, True)
2022-01-31 12:01:11 +00:00
QUEUE.pop(chat_id)
return 1
else:
return 0