Files
999/scripts/transfer_phone_archive.py
T

62 lines
2.7 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
transfer_phone_archive.py
=========================
Фоновый перенос данных со смартфона в архив:
- Музыка (Music, Audiobooks) ПОЛНОСТЬЮ ИСКЛЮЧЕНА и остаётся нетронутой на телефоне.
- Переносятся: Download, футажи, Pictures, DCIM/MyAlbums, DCIM/Camera.
"""
import os
import sys
import subprocess
import time
from pathlib import Path
DEST_ROOT = Path("/mnt/data/архив_с_телефона")
DEST_ROOT.mkdir(parents=True, exist_ok=True)
LOG_FILE = DEST_ROOT / "transfer_log.txt"
# ИСКЛЮЧАЕМ Music и Audiobooks по прямому требованию пользователя!
FOLDERS_TO_PULL = [
("Download", "/storage/emulated/0/Download", DEST_ROOT / "Download"),
("футажи", "/storage/emulated/0/футажи", DEST_ROOT / "футажи"),
("Pictures", "/storage/emulated/0/Pictures", DEST_ROOT / "Pictures"),
("DCIM/MyAlbums", "/storage/emulated/0/DCIM/MyAlbums", DEST_ROOT / "DCIM/MyAlbums"),
("DCIM/Camera", "/storage/emulated/0/DCIM/Camera", DEST_ROOT / "DCIM/Camera"),
]
def log(msg: str):
timestamp = time.strftime("[%Y-%m-%d %H:%M:%S]")
line = f"{timestamp} {msg}"
print(line, flush=True)
with open(LOG_FILE, "a", encoding="utf-8") as f:
f.write(line + "\n")
def main():
log("=== ПЕРЕНОС ДАННЫХ СО СМАРТФОНА (МУЗЫКА ОСТАЁТСЯ НА ТЕЛЕФОНЕ) ===")
start_all = time.time()
for idx, (name, src_path, dst_path) in enumerate(FOLDERS_TO_PULL, 1):
dst_path.parent.mkdir(parents=True, exist_ok=True)
log(f"[{idx}/{len(FOLDERS_TO_PULL)}] Копирование «{name}» ({src_path} -> {dst_path})...")
t0 = time.time()
cmd = ["adb", "-s", "3aeea825", "pull", src_path, str(dst_path.parent)]
try:
res = subprocess.run(cmd, capture_output=True, text=True)
elapsed = time.time() - t0
if res.returncode == 0:
log(f"-> Успешно перенесено «{name}» за {elapsed:.1f} сек.")
else:
log(f"-> Завершено с предупреждением «{name}» ({elapsed:.1f} сек): {res.stderr.strip()[:200]}")
except Exception as e:
log(f"-> Ошибка при копировании «{name}»: {e}")
total_elapsed = time.time() - start_all
log(f"=== ВСЕ ВЫБРАННЫЕ ПАПКИ УСПЕШНО ПЕРЕНЕСЕНЫ за {total_elapsed / 60:.1f} минут! (Музыка осталась на телефоне) ===")
if __name__ == "__main__":
main()