def test2(self): # File exists, verify user expansion works for input try: file_item.video_file('~/Movies/class_video_test/MVI_4299.MOV') except FileNotFoundError: self.fail('file_item.video_file() raised FileNotFoundError ' + 'unexpectedly')
def test5(self): # Verify all files in the folder correctly load test_path = os.path.expanduser('~/Movies/dance_tutorials/' + 'spain_videos_miguel/') for f in os.listdir(test_path): if os.path.isfile(os.path.join(test_path, f)): try: file_item.video_file(os.path.join(test_path, f)) except FileNotFoundError: self.fail('file_item.video_file() raised ' + 'FileNotFoundError unexpectedly')
def test6(self): # File exists, verify relative path works for input try: test_file = file_item.video_file('../../Movies/' + 'class_video_test/' + 'MVI_4299.MOV') self.assertEqual(test_file.get_creation_time(), None) self.assertEqual(test_file.get_hash(), '33b1fc20712a0c117fbb3a4defbda653') except FileNotFoundError: self.fail('file_item.video_file() raised FileNotFoundError ' + 'unexpectedly')
def test4(self): # File exists, verify datetime is set from file name, not MP4 # metadata try: test_file = file_item.video_file('~/Movies/dance_tutorials/' + 'spain_videos_miguel/' + 'VID_20150330_221716.mp4') self.assertEqual(test_file.get_creation_time(), datetime.datetime(2015, 3, 30, 22, 17, 16)) self.assertEqual(test_file.get_hash(), 'f38216382749375018eb71c5671df046') except FileNotFoundError: self.fail('file_item.video_file() raised FileNotFoundError ' + 'unexpectedly')
def add_filepath(self, filepath): if not os.path.exists(filepath): return None filename = os.path.basename(filepath) vid_file = file_item.video_file(filepath, self.res, self.restore_file_display, self.update_tag, tags={}) # Check whether this file exists already for f in self.vid_files: if f.get_hash() == vid_file.get_hash(): print('File already exists: %s' % vid_file.get_filename()) return None # Update the database in memory self.vid_files.append(vid_file) # Add the file info to the display self.display_add_file(vid_file) # Update the database on the filesystem self.update_stored_info(vid_file) return vid_file
def __init__(self, master=None): # Initialize lists of data self.vid_files = [] # Representation of file data self.draw_depth = 0 # Perform widget setup super().__init__(master) self.master = master self.pack() self.create_widgets() # Load our stored database on startup self.db = sqlite3.connect('sql-videos.db') self.cursor = self.db.cursor() try: # Load the table of file information if it exists self.cursor.execute( "SELECT * FROM {tn}".format(tn=self.table_name)) data = self.cursor.fetchall() # Get the column names names = self.db.execute("SELECT * FROM {tn}"\ .format(tn=self.tag_table)) names = [nm[0] for nm in names.description] # print(names) for entry in data: # Find the value's twin in the tags table # print(entry) entry_idx = entry[0] fetch_cmd = "SELECT * FROM {tn} "\ "WHERE {idx}='{myid}';"\ .format(tn=self.tag_table, idx=self.t_ID, myid=entry_idx) # print(fetch_cmd) self.cursor.execute(fetch_cmd) rows = self.cursor.fetchall() tags = dict(zip(names, rows[0])) # print(tags) del tags['ID'] vf = file_item.video_file(entry[1], self.res, self.restore_file_display, self.update_tag, fdatetime=entry[2], fhash=entry[3], tags=tags, table_index=entry[0]) self.vid_files.append(vf) self.display_add_file(vf) except sqlite3.OperationalError: # If the table does not exist, create one try: self.cursor.execute("CREATE TABLE {tn} "\ "({tid} INTEGER PRIMARY KEY AUTOINCREMENT,"\ "{f} {ft})"\ .format(tid=self.t_ID, tn=self.table_name, f=self.t_filename, ft='INTEGER')) self.db.commit() for t_col in self.t_columns: self.cursor.execute("ALTER TABLE {tn} "\ "ADD COLUMN '{cn}' {ct}"\ .format(tn=self.table_name, cn=t_col, ct='TEXT')) self.cursor.execute("CREATE TABLE {tn} "\ "({tid} INTEGER PRIMARY KEY)"\ .format(tn=self.tag_table, tid=self.t_ID)) except sqlite3.OperationalError: print("Something went wrong") print(sys.exc_info()) pass