105 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			105 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env python
 | |
| 
 | |
| import sys
 | |
| import subprocess
 | |
| import json
 | |
| 
 | |
| from pprint import pprint
 | |
| 
 | |
| try:
 | |
|   audio_lang=sys.argv[2]
 | |
| except IndexError:
 | |
|   audio_lang=""
 | |
| try:
 | |
|   sub_lang=sys.argv[3]
 | |
| except IndexError:
 | |
|   sub_lang=""
 | |
| try:
 | |
|   if sys.argv[4]=="hi":
 | |
|     prefer_hi=True
 | |
|   else:
 | |
|     prefer_hi=False
 | |
| except IndexError:
 | |
|   prefer_hi=False
 | |
| audio_info=""
 | |
| sub_info=""
 | |
| sub_hi_info=""
 | |
| streams=json.loads(subprocess.run(["ffprobe", "-v", "error", "-show_streams", "-print_format", "json", sys.argv[1]], capture_output=True).stdout.decode("utf-8"))["streams"]
 | |
| for i in streams:
 | |
|   matched=True
 | |
|   match i["codec_type"]:
 | |
|     case "video":
 | |
|       out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]+" "+str(i["width"])+" "+str(i["height"])+" "+i["pix_fmt"]+" "+i["r_frame_rate"]
 | |
|       try:
 | |
|         out=out+" "+str(int(i["bit_rate"])/1000)
 | |
|       except KeyError:
 | |
|         try:
 | |
|           out=out+" "+str(int(i["tags"]["BPS"])/1000)
 | |
|         except KeyError:
 | |
|           out=out+" unknown"
 | |
|       print(out)
 | |
|     case "audio":
 | |
|       try:
 | |
|         if audio_lang!="" and audio_lang!=i["tags"]["language"]:
 | |
|           matched=False
 | |
|       except:
 | |
|         pass
 | |
|       out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]+" "+str(i["sample_rate"])+" "+i["channel_layout"]
 | |
|       try:
 | |
|         out=out+" "+str(int(i["bit_rate"])/1000)
 | |
|       except KeyError:
 | |
|         try:
 | |
|           out=out+" "+str(int(i["tags"]["BPS"])/1000)
 | |
|         except KeyError:
 | |
|           out=out+" unknown"
 | |
|       out=out+" "+i["tags"]["language"]
 | |
|       if i["disposition"]["default"]==1:
 | |
|         out=out+" default"
 | |
|       if matched==True:
 | |
|         audio_info=out
 | |
|       if audio_lang=="":
 | |
|         print(out)
 | |
|     case "subtitle":
 | |
|       hi_flag=False
 | |
|       try:
 | |
|         if sub_lang!="" and sub_lang!=i["tags"]["language"]:
 | |
|           matched=False
 | |
|       except:
 | |
|         pass
 | |
|       out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]+" "+i["tags"]["language"]
 | |
|       if i["disposition"]["default"]==1:
 | |
|         out=out+" default"
 | |
|       if i["disposition"]["hearing_impaired"]==1:
 | |
|         out=out+" hi"
 | |
|         if matched==True:
 | |
|           sub_hi_info=out
 | |
|         hi_flag=True
 | |
|       try:
 | |
|         if i["tags"]["title"].find("SDH")!=-1:
 | |
|           out=out+" hi"
 | |
|           if matched==True:
 | |
|             sub_hi_info=out
 | |
|             hi_flag=True
 | |
|       except KeyError:
 | |
|         pass
 | |
|       if hi_flag==False and matched==True:
 | |
|         sub_info=out
 | |
|       if sub_lang=="":
 | |
|         print(out)
 | |
|     case _:
 | |
|       out=str(i["index"])+" "+i["codec_type"]+" "+i["codec_name"]
 | |
| if audio_info!="" and audio_lang!="":
 | |
|   print(audio_info)
 | |
| if prefer_hi==False:
 | |
|   if sub_info!="" and sub_lang!="":
 | |
|     print(sub_info)
 | |
|   else:
 | |
|     if sub_hi_info!="" and sub_lang!="":
 | |
|       print(sub_hi_info)
 | |
| else:
 | |
|   if sub_hi_info!="" and sub_lang!="":
 | |
|     print(sub_hi_info)
 | |
|   else:
 | |
|     if sub_info!="" and sub_lang!="":
 | |
|       print(sub_info)
 |