Atrinik Client  4.0
update.py
1 #!/usr/bin/env python
2 
3 import sys, os
4 
5 try:
6  import gst, gst.pbutils
7 except:
8  print("Could not import py-gst, make sure it's installed (Debian: python-gst0.10 package)")
9  sys.exit(1)
10 
12  def __init__(self):
13  pass
14 
15  def examine_file(self, file):
16  newitem = gst.pbutils.Discoverer(50000000000)
17 
18  try:
19  self.info = newitem.discover_uri("file://" + file)
20  except:
21  return False
22 
23  return True
24 
25  def get_duration(self):
26  return self.info.get_duration() / 1000000000.0
27 
28 def main():
29  print("Updating durations database...")
30 
31  currdir = os.path.dirname(os.path.abspath(__file__))
32  path = os.path.join(currdir, "..")
33  info = GSTFileInfo()
34 
35  for node in os.listdir(path):
36  fullpath = os.path.join(path, node)
37 
38  if os.path.isfile(fullpath):
39  if not info.examine_file(fullpath):
40  continue
41 
42  duration = int(info.get_duration())
43 
44  if duration:
45  fp = open(os.path.join(currdir, node), "w")
46  fp.write("{}".format(duration))
47  fp.close()
48 
49  print("Done!")
50 
51 if __name__ == "__main__":
52  main()
int main(int argc, char *argv[])
Definition: main.c:614