def _sync_db(self):
with DbConn() as conn:
VideoFile.purge_deleteds(conn)
+ conn.commit()
known_paths = [file.rel_path for file in VideoFile.get_all(conn)]
- old_cwd = Path.cwd()
- chdir(PATH_DOWNLOADS)
- for path in [p for p in Path('.').iterdir() if p.is_file()]:
- yt_id = self._id_from_filename(path)
- if path not in known_paths:
- print(f'SYNC: new file {path}, saving to YT ID "{yt_id}".')
- file = VideoFile(digest=None,
- rel_path=path,
- yt_id=yt_id,
- tags_str=VideoFile.tags_default.joined)
+ old_cwd = Path.cwd()
+ chdir(PATH_DOWNLOADS)
+ for path in [p for p in Path('.').iterdir() if p.is_file()]:
+ yt_id = self._id_from_filename(path)
+ if path not in known_paths:
+ print(f'SYNC: new file {path}, saving to YT ID "{yt_id}".')
+ file = VideoFile(digest=None,
+ rel_path=path,
+ yt_id=yt_id,
+ tags_str=VideoFile.tags_default.joined)
+ with DbConn() as conn:
file.save(conn)
conn.commit()
+ with DbConn() as conn:
+ for path in [p for p in Path('.').iterdir() if p.is_file()]:
+ yt_id = self._id_from_filename(path)
if (yt_id not in self._last_updates
or 'present' != self._last_updates[yt_id]['status']):
- self._update_status(
- yt_id,
- 'present',
- str(path),
- VideoFile.get_by_yt_id(conn, yt_id).digest.b64)
+ digest64 = VideoFile.get_by_yt_id(conn, yt_id).digest.b64
+ self._update_status(yt_id, 'present', str(path), digest64)
self._files = VideoFile.get_all(conn)
- chdir(old_cwd)
+ chdir(old_cwd)
def last_update_for(self,
conn: DbConn,