Difference between revisions of "Python Sample Export Videos"

From truxwiki.com
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
This sample shows the how to export video files in Python.
+
This sample shows how to export video files from Truxton using Python.
  
=Source Code=
+
=Global Export=
 +
This will export the videos from an instance of Truxton.
 
<source line lang="python">
 
<source line lang="python">
 
import sys
 
import sys
Line 7: Line 8:
 
import truxton
 
import truxton
  
def main():
+
def main() -> None:
  
 
  t = truxton.create()
 
  t = truxton.create()
Line 16: Line 17:
 
  exporter.addoption( exporter.eotar, "UniqueVideosFromTruxton.tar" )  
 
  exporter.addoption( exporter.eotar, "UniqueVideosFromTruxton.tar" )  
 
  exporter.addoption( exporter.eounique, "1" )
 
  exporter.addoption( exporter.eounique, "1" )
 +
exporter.addoption( exporter.eometa, "1" )
 +
exporter.execute()
  
  exporter.execute()
+
  return None
  
 
if __name__ == "__main__":
 
if __name__ == "__main__":
     main()
+
     sys.exit(main())
 
</source>
 
</source>
  
 
=Code Walkthrough=
 
=Code Walkthrough=
The above code shows how to export a category of file types from Truxton.
+
The above code shows how to export a category of files from Truxton.
  
 
Line 8 creates the exporter.
 
Line 8 creates the exporter.
Line 38: Line 41:
 
Line 13 tells the exporter to only output one copy of a file.
 
Line 13 tells the exporter to only output one copy of a file.
 
Only unique file contents will be output, no copies.
 
Only unique file contents will be output, no copies.
 +
 +
Line 14 tells the exporter to include a file called <code>FileMeta.json</code> that contains metdata about the exported file.
  
 
Line 15 begins the process of exporting the files.
 
Line 15 begins the process of exporting the files.
 
This provides no feedback, we suggest you monitor the output folder.
 
This provides no feedback, we suggest you monitor the output folder.
 +
 +
=Media Export=
 +
This will export the videos from a single media in Truxton.
 +
It is identical to the sample above but adds a single criteria that limits the results to a single media.
 +
<source lang="python" highlight="10">
 +
import sys
 +
sys.path.append('C:/Program Files/Truxton/SDK')
 +
import truxton
 +
 +
def main() -> None:
 +
 +
t = truxton.create()
 +
exporter = t.newexporter()
 +
exporter.addcriteria( exporter.fqgroup, truxton.Type_VideoCategory )
 +
exporter.addcriteria( exporter.fqmedia, "1931adc6-fd91-0ecc-5597-21d058a2dfc7" )
 +
exporter.addoption( exporter.eoname, "{hash}.{ext}" )
 +
exporter.addoption( exporter.eofolder, "c:\\temp" )
 +
exporter.addoption( exporter.eotar, "UniqueVideosFromTruxton.tar" )
 +
exporter.addoption( exporter.eounique, "1" )
 +
exporter.addoption( exporter.eometa, "1" )
 +
exporter.execute()
 +
 +
return None
 +
 +
if __name__ == "__main__":
 +
    sys.exit(main())
 +
</source>

Latest revision as of 16:55, 11 September 2024

This sample shows how to export video files from Truxton using Python.

Global Export

This will export the videos from an instance of Truxton.

 1 import sys
 2 sys.path.append('C:/Program Files/Truxton/SDK')
 3 import truxton
 4 
 5 def main() -> None:
 6 
 7  t = truxton.create()
 8  exporter = t.newexporter()
 9  exporter.addcriteria( exporter.fqgroup, truxton.Type_VideoCategory )
10  exporter.addoption( exporter.eoname, "{hash}.{ext}" )
11  exporter.addoption( exporter.eofolder, "c:\\temp" )
12  exporter.addoption( exporter.eotar, "UniqueVideosFromTruxton.tar" ) 
13  exporter.addoption( exporter.eounique, "1" )
14  exporter.addoption( exporter.eometa, "1" )
15  exporter.execute()
16 
17  return None
18 
19 if __name__ == "__main__":
20     sys.exit(main())

Code Walkthrough

The above code shows how to export a category of files from Truxton.

Line 8 creates the exporter.

Line 9 tells the exporter that we want all file types in the Type_VideoCategory.

Line 10 tells the exporter to use the MD5 hash as the filename and the extension registered for the type of file as the extension.

Line 11 will cause the exporter to write the output the file to the c:\temp folder.

Line 12 sets the format of the output to TAR in a file named UniqueVideosFromTruxton.tar

Line 13 tells the exporter to only output one copy of a file. Only unique file contents will be output, no copies.

Line 14 tells the exporter to include a file called FileMeta.json that contains metdata about the exported file.

Line 15 begins the process of exporting the files. This provides no feedback, we suggest you monitor the output folder.

Media Export

This will export the videos from a single media in Truxton. It is identical to the sample above but adds a single criteria that limits the results to a single media.

import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton

def main() -> None:

 t = truxton.create()
 exporter = t.newexporter()
 exporter.addcriteria( exporter.fqgroup, truxton.Type_VideoCategory )
 exporter.addcriteria( exporter.fqmedia, "1931adc6-fd91-0ecc-5597-21d058a2dfc7" )
 exporter.addoption( exporter.eoname, "{hash}.{ext}" )
 exporter.addoption( exporter.eofolder, "c:\\temp" )
 exporter.addoption( exporter.eotar, "UniqueVideosFromTruxton.tar" ) 
 exporter.addoption( exporter.eounique, "1" )
 exporter.addoption( exporter.eometa, "1" )
 exporter.execute()

 return None

if __name__ == "__main__":
    sys.exit(main())