@@ -13,7 +13,7 @@ def create_table():
1313 db = connect ()
1414 cursor = db .cursor ()
1515 sql = [
16- "create table upload_queue (id integer primary key autoincrement, video_path text, config_path text, locked integer default 0);" ,
16+ "create table upload_queue (id integer primary key autoincrement, video_path text, locked integer default 0);" ,
1717 "create unique index idx_video_path on upload_queue(video_path);" ,
1818 ]
1919 for s in sql :
@@ -28,17 +28,26 @@ def create_table():
2828def get_single_upload_queue ():
2929 db = connect ()
3030 cursor = db .cursor ()
31- cursor .execute ("select video_path, config_path from upload_queue where locked = 0 limit 1;" )
31+ cursor .execute ("select video_path from upload_queue where locked = 0 limit 1;" )
3232 row = cursor .fetchone ()
33- result = {'video_path' : row [0 ], 'config_path' : row [ 1 ] } if row else None
33+ result = {'video_path' : row [0 ]} if row else None
3434 db .close ()
3535 return result
3636
37- def insert_upload_queue (video_path : str , config_path : str ):
37+ def get_all_upload_queue ():
38+ db = connect ()
39+ cursor = db .cursor ()
40+ cursor .execute ("select video_path from upload_queue;" )
41+ rows = cursor .fetchall ()
42+ result = [{'video_path' : row [0 ]} for row in rows ]
43+ db .close ()
44+ return result
45+
46+ def insert_upload_queue (video_path : str ):
3847 try :
3948 db = connect ()
4049 cursor = db .cursor ()
41- cursor .execute ("insert into upload_queue (video_path, config_path ) values (?, ? );" , (video_path , config_path ))
50+ cursor .execute ("insert into upload_queue (video_path) values (?);" , (video_path ,))
4251 db .commit ()
4352 db .close ()
4453 return True
@@ -76,12 +85,16 @@ def update_upload_queue_lock(video_path: str, locked: int):
7685 # Create Table
7786 create_table ()
7887 # Insert Test Data
79- insert_upload_queue ('test.mp4' , 'config.yaml ' )
88+ insert_upload_queue ('' )
8089 # Insert again to check the unique index
81- print (insert_upload_queue ('test.mp4' , 'config.yaml' ))
82- # Get the single upload queue, shold be {'video_path': 'test.mp4', 'config_path': 'config.yaml'}
83- print (get_single_upload_queue ())
90+ # print(insert_upload_queue(''))
91+ # Get the single upload queue, shold be {'video_path': 'test.mp4'}
92+ # print(get_single_upload_queue())
93+ # Get all upload queue
94+ print (get_all_upload_queue ())
95+ # unlock the upload queue
96+ update_upload_queue_lock ('test.mp4' , 0 )
8497 # Delete the upload queue
85- delete_upload_queue ('test.mp4 ' )
98+ delete_upload_queue ('' )
8699 # Get the single upload queue after delete, should be None
87100 print (get_single_upload_queue ())
0 commit comments