Refresh and added usage tracking

This commit is contained in:
Hannes
2026-04-24 00:47:51 +02:00
parent 8519d9f62e
commit 477b1bf985
45 changed files with 726 additions and 166 deletions
+87 -13
View File
@@ -324,13 +324,64 @@ class subtitles:
return " ".join(parts)
# def get_media_info(file):
# cmd = [
# "ffprobe",
# "-v", "error",
# "-show_entries",
# (
# "format=duration:"
# "stream=index,codec_type,codec_name,"
# "width,height,r_frame_rate,bit_rate,duration,nb_frames,"
# "pix_fmt,field_order,time_base,display_aspect_ratio,"
# "color_space,color_transfer,color_primaries,bits_per_raw_sample,"
# "sample_rate,channels,bits_per_sample,"
# "stream_disposition=forced,default:"
# "stream_tags=language,title"
# ),
# "-of", "json",
# file
# ]
# try:
# result = subprocess.run(cmd, capture_output=True, text=True, check=True)
# info = json.loads(result.stdout)
# except subprocess.CalledProcessError as e:
# print(f"Error running ffprobe: {e.stderr}")
# return None, [], [], []
# # Container / file duration (string seconds, per ffprobe convention)
# duration = None
# if "format" in info:
# duration = info["format"].get("duration")
# video_streams = []
# audio_streams = []
# subtitle_streams = []
# for stream in info.get("streams", []):
# stream_type = stream.get("codec_type")
# if stream_type == "video":
# video_streams.append(stream)
# elif stream_type == "audio":
# audio_streams.append(stream)
# elif stream_type == "subtitle":
# subtitle_streams.append(stream)
# if duration is not None:
# duration = float(duration)
# else:
# duration = float('nan')
# return duration, video_streams, audio_streams, subtitle_streams
def get_media_info(file):
cmd = [
"ffprobe",
"-v", "error",
"-show_entries",
(
"format=duration:"
"format=duration:format_tags=title:"
"stream=index,codec_type,codec_name,"
"width,height,r_frame_rate,bit_rate,duration,nb_frames,"
"pix_fmt,field_order,time_base,display_aspect_ratio,"
@@ -348,13 +399,18 @@ def get_media_info(file):
info = json.loads(result.stdout)
except subprocess.CalledProcessError as e:
print(f"Error running ffprobe: {e.stderr}")
return None, [], [], []
return None, [], [], [], None
# Container / file duration (string seconds, per ffprobe convention)
# Duration
duration = None
if "format" in info:
duration = info["format"].get("duration")
# ✅ Extract container title
title = None
if "format" in info:
title = info["format"].get("tags", {}).get("title")
video_streams = []
audio_streams = []
subtitle_streams = []
@@ -368,16 +424,27 @@ def get_media_info(file):
elif stream_type == "subtitle":
subtitle_streams.append(stream)
return float(duration), video_streams, audio_streams, subtitle_streams
if duration is not None:
duration = float(duration)
else:
duration = float('nan')
return duration, video_streams, audio_streams, subtitle_streams, title
def seconds_to_hms(seconds):
h = int(seconds // 3600)
m = int((seconds % 3600) // 60)
s = int(seconds % 60)
return f"{h:02}:{m:02}:{s:02}"
if type(seconds) is float:
h = int(seconds // 3600)
m = int((seconds % 3600) // 60)
s = int(seconds % 60)
return f"{h:02}:{m:02}:{s:02}"
else:
return "ERROR"
def get_stream_bitrate(file_size, duration):
return int((file_size * 8)/duration/1000000) if duration > 0 else 0
if type(duration) is float:
if duration != float('nan'):
return round(float((file_size * 8)/duration/1000000), 2) if duration > 0 else 0
return float('nan')
class video_file:
def __init__(self, path, base_tab=""):
@@ -386,7 +453,7 @@ class video_file:
self.name = os.path.basename(path) # 25.mkv
self.size = os.path.getsize(path)
self.duration, videos, audios, subs = get_media_info(path)
self.duration, videos, audios, subs, title = get_media_info(path)
self.sort_video_info(videos)
self.sort_audio_info(audios)
@@ -395,6 +462,7 @@ class video_file:
self.bitrate = get_stream_bitrate(self.size, self.duration)
self.size = human_readable_size(self.size) # 198MB
self.duration = seconds_to_hms(self.duration)
self.title = title
def sort_video_info(self, videos):
self.videos = []
@@ -422,6 +490,8 @@ class video_file:
else:
np(f"{os.path.dirname(self.path)}/", INFO_STYLE)
np(f"\t{self.name} ({self.size}, {self.duration}, {self.bitrate} MB/s):", NORMAL_STYLE)
if self.title:
np(f"\t\tTitle: \"{self.title}\"", NORMAL_STYLE)
for video in self.videos:
np(f"\t\t{video}", NORMAL_STYLE)
for audio in self.audios:
@@ -484,14 +554,15 @@ def handle_folders(dirs, all_files):
file = file.path
if check_video_ext(os.path.splitext(file)[1]):
dir_files.append(file)
else:
np(f"{file} is not a compatabile Video file", WARN_STYLE)
# else:
# np(f"{file} is not a compatabile Video file", WARN_STYLE)
if(dir_files != []):
dir_files.sort()
all_files.append(dir_files)
if __name__ == "__main__":
# print(sys.argv)
subprocess.run(["python", "/home/honney/.bin/tracker.py", "add", "ff"])
file_dir_array = []
if len(sys.argv) == 0:
print("Something went horribly wrong!")
@@ -504,7 +575,10 @@ if __name__ == "__main__":
dirs = []
for argv in sys.argv[1:]:
if os.path.isfile(argv):
files.append(os.path.abspath(argv))
if check_video_ext(os.path.splitext(argv)[1]):
files.append(os.path.abspath(argv))
# else:
# np(f"{os.path.abspath(argv)} is not a compatabile Video file", WARN_STYLE)
elif os.path.isdir(argv):
dirs.append(os.path.abspath(argv))
else: