home · contact · privacy
For sync, identify missing files by .digest.b64 rather than relative path. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 25 Dec 2024 19:55:58 +0000 (20:55 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 25 Dec 2024 19:55:58 +0000 (20:55 +0100)
src/sync.py
src/ytplom/http.py

index adfcef3b4c825949dd9d6abb0122ee2ae27ddda2..dde4348492c62cfd8c620524fee6ebfc6de84c9c 100755 (executable)
@@ -4,14 +4,13 @@
 # included libs
 from typing import Any, Callable
 from json import loads as json_loads
-from pathlib import Path
 from urllib.request import urlopen
 # non-included libs
 from paramiko import SSHClient  # type: ignore
 from scp import SCPClient  # type: ignore
 from ytplom.db import DbConn, PATH_DB
-from ytplom.misc import (PATH_DOWNLOADS, PATH_TEMP, Config, QuotaLog,
-                         VideoFile, YoutubeQuery, YoutubeVideo)
+from ytplom.misc import (
+        PATH_TEMP, Config, QuotaLog, VideoFile, YoutubeQuery, YoutubeVideo)
 from ytplom.http import PAGE_NAMES
 
 
@@ -95,15 +94,16 @@ def fill_missing(scp: SCPClient, config: Config) -> None:
                        (config.host, config.port)):
         url_missing = f'http://{host}:{port}/{PAGE_NAMES["missing"]}'
         with urlopen(url_missing) as response:
-            missings += [[Path(p) for p in json_loads(response.read())]]
+            missings += [list(json_loads(response.read()))]
+    conn = DbConn()
     for i, direction_mover in enumerate([('local->remote', scp.put),
                                          ('remote->local', scp.get)]):
         direction, mover = direction_mover
-        for path in (p for p in missings[i]
-                     if p not in missings[int(not bool(i))]):
-            full_path = PATH_DOWNLOADS.joinpath(path)
-            print(f'SYNC: sending {direction} file {path}')
-            mover(full_path, full_path)
+        for digest in (d for d in missings[i]
+                       if d not in missings[int(not bool(i))]):
+            vf = VideoFile.get_one(conn, digest)
+            print(f'SYNC: sending {direction} file {vf.full_path}')
+            mover(vf.full_path, vf.full_path)
 
 
 def main():
index 7f4780f9da9b88a9a3595a01e89fa4142b52bff5..001438396606f23530822ad8df2d9b7f36feb132 100644 (file)
@@ -350,7 +350,7 @@ class _TaskHandler(BaseHTTPRequestHandler):
 
     def _send_missing_json(self) -> None:
         with DbConn() as conn:
-            missing = [str(f.rel_path) for f in VideoFile.get_all(conn)
+            missing = [f.digest.b64 for f in VideoFile.get_all(conn)
                        if f.missing]
         self._send_http(json_dumps(missing),
                         headers=[(_HEADER_CONTENT_TYPE, _HEADER_APP_JSON)])