# 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
(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():