1## Copyright (c) MediaArea.net SARL. All Rights Reserved. 2 # 3 # Use of this source code is governed by a BSD-style license that can 4 # be found in the License.html file in the root of the source tree. 5 ## 6 7#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8# 9# Python example 10# 11# To make this example working, you must put MediaInfo.Dll, MediaInfoDLL.py 12# and example.ogg in the same folder 13# 14# HowToUse_Dll.py and HowToUse_Dll3.py are same 15# MediaInfoDLL.py and MediaInfoDLL3.py are same 16# but all files are kept in order to not break programs calling them. 17# 18#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 19 20from MediaInfoDLL import * 21 22MI = MediaInfo() 23 24Version=MI.Option_Static("Info_Version", "0.7.7.0;MediaInfoDLL_Example_Python;0.7.7.0") 25if Version=="": 26 print("MediaInfo.Dll: this version of the DLL is not compatible") 27 exit 28 29 30#Information about MediaInfo 31print("Info_Parameters") 32MI.Option_Static("Info_Parameters") 33 34print("") 35print("Info_Capacities") 36print(MI.Option_Static("Info_Capacities")) 37 38print("") 39print("Info_Codecs") 40print(MI.Option_Static("Info_Codecs")) 41 42 43#An example of how to use the library 44print("") 45print("Open") 46MI.Open("Example.ogg") 47 48print("") 49print("Inform with Complete=false") 50MI.Option_Static("Complete") 51print(MI.Inform()) 52 53print("") 54print("Inform with Complete=true") 55MI.Option_Static("Complete", "1") 56print(MI.Inform()) 57 58print("") 59print("Custom Inform") 60MI.Option_Static("Inform", "General;Example : FileSize=%FileSize%") 61print(MI.Inform()) 62 63print("") 64print("Get with Stream=General and Parameter='FileSize'") 65print(MI.Get(Stream.General, 0, "FileSize")) 66 67print("") 68print("GetI with Stream=General and Parameter=46") 69print(MI.GetI(Stream.General, 0, 46)) 70 71print("") 72print("Count_Get with StreamKind=Stream_Audio") 73print(MI.Count_Get(Stream.Audio)) 74 75print("") 76print("Get with Stream=General and Parameter='AudioCount'") 77print(MI.Get(Stream.General, 0, "AudioCount")) 78 79print("") 80print("Get with Stream=Audio and Parameter='StreamCount'") 81print(MI.Get(Stream.Audio, 0, "StreamCount")) 82 83print("") 84print("Close") 85MI.Close() 86 87#By buffer example 88 89#Open example file for reading 90try: 91 File=open('Example.ogg', 'rb') 92except IOError: 93 exit(1) 94 95#Get file size 96File.seek(0,2) 97Size=File.tell() 98File.seek(0) 99 100print("") 101print("Open_Buffer_Init") 102MI.Open_Buffer_Init(Size, 0) 103 104print("") 105print("Parsing loop") 106while True: 107 Buffer=File.read(7*188) 108 if Buffer: 109 #Send the buffer to MediaInfo 110 Status=c_size_t(MI.Open_Buffer_Continue(Buffer, len(Buffer))).value 111 if Status & 0x08: #Bit3=Finished 112 break 113 114 #Test if there is a MediaInfo request to go elsewhere 115 Seek = c_longlong(MI.Open_Buffer_Continue_GoTo_Get()).value 116 if Seek != -1: 117 File.seek(Seek) #Seek the file 118 MI.Open_Buffer_Init(Size, File.tell()) #Inform MediaInfo we have seek 119 else: 120 break 121 122print("") 123print("Open_Buffer_Finalize") 124MI.Open_Buffer_Finalize() 125 126print("") 127print("Get with Stream=General and Parameter='Format'") 128print(MI.Get(Stream.General, 0, "Format")) 129