|
|
@@ -0,0 +1,63 @@
|
|
|
+from pymongo import MongoClient, errors, DESCENDING, ASCENDING
|
|
|
+from bson.objectid import ObjectId
|
|
|
+import time
|
|
|
+import re
|
|
|
+import os
|
|
|
+import subprocess
|
|
|
+
|
|
|
+RAW_DIRECTORY="/home/david"
|
|
|
+
|
|
|
+class db():
|
|
|
+ DB = "videos"
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ self.client = MongoClient('localhost', 27017)
|
|
|
+ self.raw_files = self.client[self.DB]["raw"]
|
|
|
+ self.cut_files = self.client[self.DB]["cut"]
|
|
|
+ self.ul_files = self.client[self.DB]["ul"]
|
|
|
+
|
|
|
+ def jsonable(self, el):
|
|
|
+ if el is None or "_id" not in el:
|
|
|
+ return el
|
|
|
+
|
|
|
+ el["_id"] = str(el["_id"])
|
|
|
+ return el
|
|
|
+
|
|
|
+ def raw(self, _id=None):
|
|
|
+ ret = None
|
|
|
+ if _id:
|
|
|
+ ret = self.raw_files.find_one({"_id": ObjectId(id)})
|
|
|
+ else:
|
|
|
+ ret = [ self.jsonable(r) for r in self.raw_files.find() ]
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+ def insert_raw(self, rawfile):
|
|
|
+ try:
|
|
|
+ self.raw_files.insert_one(rawfile)
|
|
|
+ return True
|
|
|
+ except errors.DuplicateKeyError:
|
|
|
+ print("Dup")
|
|
|
+ return False
|
|
|
+
|
|
|
+ def insert_raw_list(self):
|
|
|
+ for fname in os.listdir(RAW_DIRECTORY):
|
|
|
+ if fname.endswith("flv"):
|
|
|
+ self.insert_raw(file_info(os.path.join(RAW_DIRECTORY,fname)))
|
|
|
+
|
|
|
+
|
|
|
+def get_video_length(fname):
|
|
|
+ process="ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal %s" % fname
|
|
|
+ process=process.split(" ")
|
|
|
+ out,err= subprocess.Popen(process,stdout=subprocess.PIPE).communicate()
|
|
|
+ out=out.decode('utf-8')
|
|
|
+ if "." in out:
|
|
|
+ out = out.split(".")[0]
|
|
|
+ return out
|
|
|
+def file_info(fname):
|
|
|
+ return {'file':fname,
|
|
|
+ 'length': get_video_length(fname),
|
|
|
+ 'date': time.ctime(os.path.getctime(fname))
|
|
|
+ }
|
|
|
+
|
|
|
+
|