File: HowToUse_Dll.py

package info (click to toggle)
libmediainfo 20.09%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 17,296 kB
  • sloc: cpp: 205,411; ansic: 5,215; asm: 2,081; xml: 1,476; sh: 1,062; java: 1,032; cs: 944; python: 653; makefile: 383; pascal: 197; javascript: 188
file content (128 lines) | stat: -rw-r--r-- 3,236 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
##  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 #
 #  Use of this source code is governed by a BSD-style license that can
 #  be found in the License.html file in the root of the source tree.
 ##

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# Python example
#
# To make this example working, you must put MediaInfo.Dll, MediaInfoDLL.py
# and example.ogg in the same folder
#
# HowToUse_Dll.py and HowToUse_Dll3.py are same
# MediaInfoDLL.py and MediaInfoDLL3.py are same
# but all files are kept in order to not break programs calling them.
#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

from MediaInfoDLL import *

MI = MediaInfo()

Version=MI.Option_Static("Info_Version", "0.7.7.0;MediaInfoDLL_Example_Python;0.7.7.0")
if Version=="":
    print("MediaInfo.Dll: this version of the DLL is not compatible")
    exit


#Information about MediaInfo
print("Info_Parameters")
MI.Option_Static("Info_Parameters")

print("")
print("Info_Capacities")
print(MI.Option_Static("Info_Capacities"))

print("")
print("Info_Codecs")
print(MI.Option_Static("Info_Codecs"))


#An example of how to use the library
print("")
print("Open")
MI.Open("Example.ogg")

print("")
print("Inform with Complete=false")
MI.Option_Static("Complete")
print(MI.Inform())

print("")
print("Inform with Complete=true")
MI.Option_Static("Complete", "1")
print(MI.Inform())

print("")
print("Custom Inform")
MI.Option_Static("Inform", "General;Example : FileSize=%FileSize%")
print(MI.Inform())

print("")
print("Get with Stream=General and Parameter='FileSize'")
print(MI.Get(Stream.General, 0, "FileSize"))

print("")
print("GetI with Stream=General and Parameter=46")
print(MI.GetI(Stream.General, 0, 46))

print("")
print("Count_Get with StreamKind=Stream_Audio")
print(MI.Count_Get(Stream.Audio))

print("")
print("Get with Stream=General and Parameter='AudioCount'")
print(MI.Get(Stream.General, 0, "AudioCount"))

print("")
print("Get with Stream=Audio and Parameter='StreamCount'")
print(MI.Get(Stream.Audio, 0, "StreamCount"))

print("")
print("Close")
MI.Close()

#By buffer example

#Open example file for reading
try:
    File=open('Example.ogg', 'rb')
except IOError:
    exit(1)

#Get file size
File.seek(0,2)
Size=File.tell()
File.seek(0)

print("")
print("Open_Buffer_Init")
MI.Open_Buffer_Init(Size, 0)

print("")
print("Parsing loop")
while True:
    Buffer=File.read(7*188)
    if Buffer:
        #Send the buffer to MediaInfo
        Status=c_size_t(MI.Open_Buffer_Continue(Buffer, len(Buffer))).value
        if Status & 0x08: #Bit3=Finished
            break

        #Test if there is a MediaInfo request to go elsewhere
        Seek = c_longlong(MI.Open_Buffer_Continue_GoTo_Get()).value
        if  Seek != -1:
            File.seek(Seek) #Seek the file
            MI.Open_Buffer_Init(Size, File.tell()) #Inform MediaInfo we have seek
    else:
        break

print("")
print("Open_Buffer_Finalize")
MI.Open_Buffer_Finalize()

print("")
print("Get with Stream=General and Parameter='Format'")
print(MI.Get(Stream.General, 0, "Format"))