diff --git a/src/prep.py b/src/prep.py index c53cdaf79..6f22365d8 100644 --- a/src/prep.py +++ b/src/prep.py @@ -469,166 +469,189 @@ def get_video(self, videoloc, mode): - - - """ Get and parse mediainfo """ - def exportInfo(self, video, isdir, folder_id, base_dir, export_text): - def filter_mediainfo(data): - filtered = { - "creatingLibrary": data.get("creatingLibrary"), - "media": { - "@ref": data["media"]["@ref"], - "track": [] - } +def exportInfo(self, video, isdir, folder_id, base_dir, export_text): + def filter_mediainfo(data): + filtered = { + "creatingLibrary": data.get("creatingLibrary"), + "media": { + "@ref": data["media"]["@ref"], + "track": [] } - - for track in data["media"]["track"]: - if track["@type"] == "General": - filtered["media"]["track"].append({ - "@type": track["@type"], - "VideoCount": track.get("VideoCount"), - "AudioCount": track.get("AudioCount"), - "MenuCount": track.get("MenuCount"), - "FileExtension": track.get("FileExtension"), - "Format": track.get("Format"), - "Format_Version": track.get("Format_Version"), - "FileSize": track.get("FileSize"), - "Duration": track.get("Duration"), - "OverallBitRate": track.get("OverallBitRate"), - "FrameRate": track.get("FrameRate"), - "FrameCount": track.get("FrameCount"), - "StreamSize": track.get("StreamSize"), - "IsStreamable": track.get("IsStreamable"), - "File_Created_Date": track.get("File_Created_Date"), - "File_Created_Date_Local": track.get("File_Created_Date_Local"), - "File_Modified_Date": track.get("File_Modified_Date"), - "File_Modified_Date_Local": track.get("File_Modified_Date_Local"), - "Encoded_Application": track.get("Encoded_Application"), - "Encoded_Library": track.get("Encoded_Library"), - }) - elif track["@type"] == "Video": - filtered["media"]["track"].append({ - "@type": track["@type"], - "StreamOrder": track.get("StreamOrder"), - "ID": track.get("ID"), - "UniqueID": track.get("UniqueID"), - "Format": track.get("Format"), - "Format_Profile": track.get("Format_Profile"), - "Format_Level": track.get("Format_Level"), - "Format_Settings_CABAC": track.get("Format_Settings_CABAC"), - "Format_Settings_RefFrames": track.get("Format_Settings_RefFrames"), - "CodecID": track.get("CodecID"), - "Duration": track.get("Duration"), - "BitRate": track.get("BitRate"), - "Width": track.get("Width"), - "Height": track.get("Height"), - "Sampled_Width": track.get("Sampled_Width"), - "Sampled_Height": track.get("Sampled_Height"), - "PixelAspectRatio": track.get("PixelAspectRatio"), - "DisplayAspectRatio": track.get("DisplayAspectRatio"), - "FrameRate_Mode": track.get("FrameRate_Mode"), - "FrameRate": track.get("FrameRate"), - "FrameCount": track.get("FrameCount"), - "ColorSpace": track.get("ColorSpace"), - "ChromaSubsampling": track.get("ChromaSubsampling"), - "BitDepth": track.get("BitDepth"), - "ScanType": track.get("ScanType"), - "Delay": track.get("Delay"), - "Delay_Source": track.get("Delay_Source"), - "StreamSize": track.get("StreamSize"), - "Encoded_Library": track.get("Encoded_Library"), - "Encoded_Library_Name": track.get("Encoded_Library_Name"), - "Encoded_Library_Version": track.get("Encoded_Library_Version"), - "Encoded_Library_Settings": track.get("Encoded_Library_Settings"), - "Language": track.get("Language"), - "Default": track.get("Default"), - "Forced": track.get("Forced"), - }) - elif track["@type"] == "Audio": - filtered["media"]["track"].append({ - "@type": track["@type"], - "StreamOrder": track.get("StreamOrder"), - "ID": track.get("ID"), - "UniqueID": track.get("UniqueID"), - "Format": track.get("Format"), - "Format_Settings_Mode": track.get("Format_Settings_Mode"), - "Format_Settings_Endianness": track.get("Format_Settings_Endianness"), - "CodecID": track.get("CodecID"), - "Duration": track.get("Duration"), - "BitRate_Mode": track.get("BitRate_Mode"), - "BitRate": track.get("BitRate"), - "Channels": track.get("Channels"), - "ChannelPositions": track.get("ChannelPositions"), - "ChannelLayout": track.get("ChannelLayout"), - "SamplesPerFrame": track.get("SamplesPerFrame"), - "SamplingRate": track.get("SamplingRate"), - "SamplingCount": track.get("SamplingCount"), - "FrameRate": track.get("FrameRate"), - "BitDepth": track.get("BitDepth"), - "Compression_Mode": track.get("Compression_Mode"), - "Delay": track.get("Delay"), - "Delay_Source": track.get("Delay_Source"), - "Video_Delay": track.get("Video_Delay"), - "StreamSize": track.get("StreamSize"), - "Language": track.get("Language"), - "Default": track.get("Default"), - "Forced": track.get("Forced"), - }) - elif track["@type"] == "Text": - filtered["media"]["track"].append({ - "@type": track["@type"], - "@typeorder": track.get("@typeorder"), - "StreamOrder": track.get("StreamOrder"), - "ID": track.get("ID"), - "UniqueID": track.get("UniqueID"), - "Format": track.get("Format"), - "CodecID": track.get("CodecID"), - "Duration": track.get("Duration"), - "BitRate": track.get("BitRate"), - "FrameRate": track.get("FrameRate"), - "FrameCount": track.get("FrameCount"), - "ElementCount": track.get("ElementCount"), - "StreamSize": track.get("StreamSize"), - "Title": track.get("Title"), - "Language": track.get("Language"), - "Default": track.get("Default"), - "Forced": track.get("Forced"), - }) - elif track["@type"] == "Menu": - filtered["media"]["track"].append({ - "@type": track["@type"], - "extra": track.get("extra"), - }) - - return filtered - - if not os.path.exists(f"{base_dir}/tmp/{folder_id}/MEDIAINFO.txt") and export_text: - console.print("[bold yellow]Exporting MediaInfo...") - if not isdir: - os.chdir(os.path.dirname(video)) - media_info = MediaInfo.parse(video, output="STRING", full=False, mediainfo_options={'inform_version': '1'}) - with open(f"{base_dir}/tmp/{folder_id}/MEDIAINFO.txt", 'w', newline="", encoding='utf-8') as export: - export.write(media_info) - with open(f"{base_dir}/tmp/{folder_id}/MEDIAINFO_CLEANPATH.txt", 'w', newline="", encoding='utf-8') as export_cleanpath: - export_cleanpath.write(media_info.replace(video, os.path.basename(video))) - console.print("[bold green]MediaInfo Exported.") - - if not os.path.exists(f"{base_dir}/tmp/{folder_id}/MediaInfo.json.txt"): - media_info_json = MediaInfo.parse(video, output="JSON", mediainfo_options={'inform_version': '1'}) - media_info_dict = json.loads(media_info_json) - filtered_info = filter_mediainfo(media_info_dict) - with open(f"{base_dir}/tmp/{folder_id}/MediaInfo.json", 'w', encoding='utf-8') as export: - json.dump(filtered_info, export, indent=4) - - with open(f"{base_dir}/tmp/{folder_id}/MediaInfo.json", 'r', encoding='utf-8') as f: - mi = json.load(f) + } - return mi - - + for track in data["media"]["track"]: + if track["@type"] == "General": + filtered["media"]["track"].append({ + "@type": track["@type"], + "UniqueID": track.get("UniqueID"), + "VideoCount": track.get("VideoCount"), + "AudioCount": track.get("AudioCount"), + "TextCount": track.get("TextCount"), + "MenuCount": track.get("MenuCount"), + "FileExtension": track.get("FileExtension"), + "Format": track.get("Format"), + "Format_Version": track.get("Format_Version"), + "FileSize": track.get("FileSize"), + "Duration": track.get("Duration"), + "OverallBitRate": track.get("OverallBitRate"), + "FrameRate": track.get("FrameRate"), + "FrameCount": track.get("FrameCount"), + "StreamSize": track.get("StreamSize"), + "IsStreamable": track.get("IsStreamable"), + "File_Created_Date": track.get("File_Created_Date"), + "File_Created_Date_Local": track.get("File_Created_Date_Local"), + "File_Modified_Date": track.get("File_Modified_Date"), + "File_Modified_Date_Local": track.get("File_Modified_Date_Local"), + "Encoded_Application": track.get("Encoded_Application"), + "Encoded_Library": track.get("Encoded_Library"), + }) + elif track["@type"] == "Video": + filtered["media"]["track"].append({ + "@type": track["@type"], + "StreamOrder": track.get("StreamOrder"), + "ID": track.get("ID"), + "UniqueID": track.get("UniqueID"), + "Format": track.get("Format"), + "Format_Profile": track.get("Format_Profile"), + "Format_Level": track.get("Format_Level"), + "Format_Tier": track.get("Format_Tier"), + "HDR_Format": track.get("HDR_Format"), + "HDR_Format_Version": track.get("HDR_Format_Version"), + "HDR_Format_Profile": track.get("HDR_Format_Profile"), + "HDR_Format_Level": track.get("HDR_Format_Level"), + "HDR_Format_Settings": track.get("HDR_Format_Settings"), + "HDR_Format_Compression": track.get("HDR_Format_Compression"), + "HDR_Format_Compatibility": track.get("HDR_Format_Compatibility"), + "CodecID": track.get("CodecID"), + "Duration": track.get("Duration"), + "BitRate": track.get("BitRate"), + "Width": track.get("Width"), + "Height": track.get("Height"), + "Stored_Height": track.get("Stored_Height"), + "Sampled_Width": track.get("Sampled_Width"), + "Sampled_Height": track.get("Sampled_Height"), + "PixelAspectRatio": track.get("PixelAspectRatio"), + "DisplayAspectRatio": track.get("DisplayAspectRatio"), + "FrameRate_Mode": track.get("FrameRate_Mode"), + "FrameRate": track.get("FrameRate"), + "FrameRate_Num": track.get("FrameRate_Num"), + "FrameRate_Den": track.get("FrameRate_Den"), + "FrameCount": track.get("FrameCount"), + "ColorSpace": track.get("ColorSpace"), + "ChromaSubsampling": track.get("ChromaSubsampling"), + "ChromaSubsampling_Position": track.get("ChromaSubsampling_Position"), + "BitDepth": track.get("BitDepth"), + "Delay": track.get("Delay"), + "Delay_Source": track.get("Delay_Source"), + "StreamSize": track.get("StreamSize"), + "Language": track.get("Language"), + "Default": track.get("Default"), + "Forced": track.get("Forced"), + "colour_description_present": track.get("colour_description_present"), + "colour_description_present_Source": track.get("colour_description_present_Source"), + "colour_range": track.get("colour_range"), + "colour_range_Source": track.get("colour_range_Source"), + "colour_primaries": track.get("colour_primaries"), + "colour_primaries_Source": track.get("colour_primaries_Source"), + "transfer_characteristics": track.get("transfer_characteristics"), + "transfer_characteristics_Source": track.get("transfer_characteristics_Source"), + "matrix_coefficients": track.get("matrix_coefficients"), + "matrix_coefficients_Source": track.get("matrix_coefficients_Source"), + "MasteringDisplay_ColorPrimaries": track.get("MasteringDisplay_ColorPrimaries"), + "MasteringDisplay_ColorPrimaries_Source": track.get("MasteringDisplay_ColorPrimaries_Source"), + "MasteringDisplay_Luminance": track.get("MasteringDisplay_Luminance"), + "MasteringDisplay_Luminance_Source": track.get("MasteringDisplay_Luminance_Source"), + "MaxCLL": track.get("MaxCLL"), + "MaxCLL_Source": track.get("MaxCLL_Source"), + "MaxFALL": track.get("MaxFALL"), + "MaxFALL_Source": track.get("MaxFALL_Source"), + }) + elif track["@type"] == "Audio": + filtered["media"]["track"].append({ + "@type": track["@type"], + "StreamOrder": track.get("StreamOrder"), + "ID": track.get("ID"), + "UniqueID": track.get("UniqueID"), + "Format": track.get("Format"), + "Format_Commercial_IfAny": track.get("Format_Commercial_IfAny"), + "Format_Settings_Endianness": track.get("Format_Settings_Endianness"), + "Format_AdditionalFeatures": track.get("Format_AdditionalFeatures"), + "CodecID": track.get("CodecID"), + "Duration": track.get("Duration"), + "BitRate_Mode": track.get("BitRate_Mode"), + "BitRate": track.get("BitRate"), + "Channels": track.get("Channels"), + "ChannelPositions": track.get("ChannelPositions"), + "ChannelLayout": track.get("ChannelLayout"), + "SamplesPerFrame": track.get("SamplesPerFrame"), + "SamplingRate": track.get("SamplingRate"), + "SamplingCount": track.get("SamplingCount"), + "FrameRate": track.get("FrameRate"), + "FrameCount": track.get("FrameCount"), + "Compression_Mode": track.get("Compression_Mode"), + "Delay": track.get("Delay"), + "Delay_Source": track.get("Delay_Source"), + "Video_Delay": track.get("Video_Delay"), + "StreamSize": track.get("StreamSize"), + "Language": track.get("Language"), + "ServiceKind": track.get("ServiceKind"), + "Default": track.get("Default"), + "Forced": track.get("Forced"), + "extra": track.get("extra"), + }) + elif track["@type"] == "Text": + filtered["media"]["track"].append({ + "@type": track["@type"], + "@typeorder": track.get("@typeorder"), + "StreamOrder": track.get("StreamOrder"), + "ID": track.get("ID"), + "UniqueID": track.get("UniqueID"), + "Format": track.get("Format"), + "CodecID": track.get("CodecID"), + "Duration": track.get("Duration"), + "BitRate": track.get("BitRate"), + "FrameRate": track.get("FrameRate"), + "FrameCount": track.get("FrameCount"), + "ElementCount": track.get("ElementCount"), + "StreamSize": track.get("StreamSize"), + "Title": track.get("Title"), + "Language": track.get("Language"), + "Default": track.get("Default"), + "Forced": track.get("Forced"), + }) + elif track["@type"] == "Menu": + filtered["media"]["track"].append({ + "@type": track["@type"], + "extra": track.get("extra"), + }) + + return filtered + + if not os.path.exists(f"{base_dir}/tmp/{folder_id}/MEDIAINFO.txt") and export_text: + console.print("[bold yellow]Exporting MediaInfo...") + if not isdir: + os.chdir(os.path.dirname(video)) + media_info = MediaInfo.parse(video, output="STRING", full=False, mediainfo_options={'inform_version': '1'}) + with open(f"{base_dir}/tmp/{folder_id}/MEDIAINFO.txt", 'w', newline="", encoding='utf-8') as export: + export.write(media_info) + with open(f"{base_dir}/tmp/{folder_id}/MEDIAINFO_CLEANPATH.txt", 'w', newline="", encoding='utf-8') as export_cleanpath: + export_cleanpath.write(media_info.replace(video, os.path.basename(video))) + console.print("[bold green]MediaInfo Exported.") + + if not os.path.exists(f"{base_dir}/tmp/{folder_id}/MediaInfo.json.txt"): + media_info_json = MediaInfo.parse(video, output="JSON", mediainfo_options={'inform_version': '1'}) + media_info_dict = json.loads(media_info_json) + filtered_info = filter_mediainfo(media_info_dict) + with open(f"{base_dir}/tmp/{folder_id}/MediaInfo.json", 'w', encoding='utf-8') as export: + json.dump(filtered_info, export, indent=4) + + with open(f"{base_dir}/tmp/{folder_id}/MediaInfo.json", 'r', encoding='utf-8') as f: + mi = json.load(f) + + return mi """