Merge pull request 'fix/improve-gpt-script' (#1) from fix/improve-gpt-script into main
Reviewed-on: Klagarge/medias-migration#1
This commit is contained in:
commit
5110f41152
@ -55,7 +55,6 @@ def encode(input_file, codec, remove_source=False, save_log=False):
|
|||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-i", input_file,
|
"-i", input_file,
|
||||||
"-map", "0",
|
"-map", "0",
|
||||||
"-cq", str(cq),
|
|
||||||
] + extra_params + [
|
] + extra_params + [
|
||||||
"-c:v", ffmpeg_codec,
|
"-c:v", ffmpeg_codec,
|
||||||
"-preset", "p4",
|
"-preset", "p4",
|
||||||
|
@ -55,8 +55,6 @@ def get_video_metadata(file_path):
|
|||||||
"channels": stream.get("channels", 0),
|
"channels": stream.get("channels", 0),
|
||||||
"flags": {
|
"flags": {
|
||||||
"default": stream.get("disposition", {}).get("default", 0) == 1,
|
"default": stream.get("disposition", {}).get("default", 0) == 1,
|
||||||
"forced": stream.get("disposition", {}).get("forced", 0) == 1,
|
|
||||||
"hearing_impaired": stream.get("disposition", {}).get("hearing_impaired", 0) == 1,
|
|
||||||
"visual_impaired": stream.get("disposition", {}).get("visual_impaired", 0) == 1,
|
"visual_impaired": stream.get("disposition", {}).get("visual_impaired", 0) == 1,
|
||||||
"original": stream.get("disposition", {}).get("original", 0) == 1,
|
"original": stream.get("disposition", {}).get("original", 0) == 1,
|
||||||
"commentary": stream.get("disposition", {}).get("comment", 0) == 1
|
"commentary": stream.get("disposition", {}).get("comment", 0) == 1
|
||||||
@ -73,7 +71,6 @@ def get_video_metadata(file_path):
|
|||||||
"default": stream.get("disposition", {}).get("default", 0) == 1,
|
"default": stream.get("disposition", {}).get("default", 0) == 1,
|
||||||
"forced": stream.get("disposition", {}).get("forced", 0) == 1,
|
"forced": stream.get("disposition", {}).get("forced", 0) == 1,
|
||||||
"hearing_impaired": stream.get("disposition", {}).get("hearing_impaired", 0) == 1,
|
"hearing_impaired": stream.get("disposition", {}).get("hearing_impaired", 0) == 1,
|
||||||
"visual_impaired": stream.get("disposition", {}).get("visual_impaired", 0) == 1,
|
|
||||||
"original": stream.get("disposition", {}).get("original", 0) == 1,
|
"original": stream.get("disposition", {}).get("original", 0) == 1,
|
||||||
"commentary": stream.get("disposition", {}).get("comment", 0) == 1
|
"commentary": stream.get("disposition", {}).get("comment", 0) == 1
|
||||||
}
|
}
|
||||||
@ -86,13 +83,13 @@ def get_video_metadata(file_path):
|
|||||||
print(f"❌ Error processing {file_path}: {str(e)}")
|
print(f"❌ Error processing {file_path}: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def process_file(file_path, output_file=None):
|
def process_file(file_path, output_dir=None):
|
||||||
"""
|
"""
|
||||||
Process a single video file and write metadata to JSON.
|
Process a single video file and write metadata to JSON.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_path (str): Path to the video file
|
file_path (str): Path to the video file
|
||||||
output_file (str, optional): Path to output JSON file
|
output_dir (str, optional): Directory where the output JSON file will be saved
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile(file_path):
|
if not os.path.isfile(file_path):
|
||||||
print(f"❌ File not found: {file_path}")
|
print(f"❌ File not found: {file_path}")
|
||||||
@ -106,27 +103,34 @@ def process_file(file_path, output_file=None):
|
|||||||
metadata = get_video_metadata(file_path)
|
metadata = get_video_metadata(file_path)
|
||||||
|
|
||||||
if metadata:
|
if metadata:
|
||||||
if not output_file:
|
# Generate output filename based on input file
|
||||||
# Generate output filename based on input file
|
filename = os.path.basename(os.path.splitext(file_path)[0]) + "_metadata.json"
|
||||||
|
|
||||||
|
if output_dir:
|
||||||
|
# Ensure output directory exists
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
output_path = os.path.join(output_dir, filename)
|
||||||
|
else:
|
||||||
|
# If no output directory specified, save in the same directory as the input file
|
||||||
base_name = os.path.splitext(file_path)[0]
|
base_name = os.path.splitext(file_path)[0]
|
||||||
output_file = f"{base_name}_metadata.json"
|
output_path = f"{base_name}_metadata.json"
|
||||||
|
|
||||||
# Write metadata to JSON file
|
# Write metadata to JSON file
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
json.dump(metadata, f, indent=2, ensure_ascii=False)
|
json.dump(metadata, f, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
print(f"✅ Metadata saved to {output_file}")
|
print(f"✅ Metadata saved to {output_path}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def process_directory(directory_path, output_file=None):
|
def process_directory(directory_path, output_dir=None):
|
||||||
"""
|
"""
|
||||||
Process all video files in a directory and write metadata to JSON.
|
Process all video files in a directory and write metadata to JSON.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
directory_path (str): Path to the directory
|
directory_path (str): Path to the directory
|
||||||
output_file (str, optional): Path to output JSON file
|
output_dir (str, optional): Directory where the output JSON file will be saved
|
||||||
"""
|
"""
|
||||||
if not os.path.isdir(directory_path):
|
if not os.path.isdir(directory_path):
|
||||||
print(f"❌ Directory not found: {directory_path}")
|
print(f"❌ Directory not found: {directory_path}")
|
||||||
@ -152,31 +156,38 @@ def process_directory(directory_path, output_file=None):
|
|||||||
print(f"❌ No supported video files found in {directory_path}")
|
print(f"❌ No supported video files found in {directory_path}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not output_file:
|
# Generate output filename based on directory name
|
||||||
# Generate output filename based on directory name
|
dir_name = os.path.basename(os.path.normpath(directory_path))
|
||||||
dir_name = os.path.basename(os.path.normpath(directory_path))
|
filename = f"{dir_name}_metadata.json"
|
||||||
output_file = f"{dir_name}_metadata.json"
|
|
||||||
|
if output_dir:
|
||||||
|
# Ensure output directory exists
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
output_path = os.path.join(output_dir, filename)
|
||||||
|
else:
|
||||||
|
# If no output directory specified, save in the current directory
|
||||||
|
output_path = filename
|
||||||
|
|
||||||
# Write all metadata to a single JSON file
|
# Write all metadata to a single JSON file
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
json.dump(all_metadata, f, indent=2, ensure_ascii=False)
|
json.dump(all_metadata, f, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
print(f"✅ Metadata for {file_count} files saved to {output_file}")
|
print(f"✅ Metadata for {file_count} files saved to {output_path}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Extract metadata from video files and save as JSON.")
|
parser = argparse.ArgumentParser(description="Extract metadata from video files and save as JSON.")
|
||||||
parser.add_argument("input", help="Path to input video file or directory")
|
parser.add_argument("input", help="Path to input video file or directory")
|
||||||
parser.add_argument("-o", "--output", help="Path to output JSON file")
|
parser.add_argument("-o", "--output", help="Directory path where output JSON files will be saved")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
input_path = args.input
|
input_path = args.input
|
||||||
output_file = args.output
|
output_dir = args.output
|
||||||
|
|
||||||
if os.path.isfile(input_path):
|
if os.path.isfile(input_path):
|
||||||
process_file(input_path, output_file)
|
process_file(input_path, output_dir)
|
||||||
elif os.path.isdir(input_path):
|
elif os.path.isdir(input_path):
|
||||||
process_directory(input_path, output_file)
|
process_directory(input_path, output_dir)
|
||||||
else:
|
else:
|
||||||
print(f"❌ Path not found: {input_path}")
|
print(f"❌ Path not found: {input_path}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user