copy sources from branch develop/0.1.0
This commit is contained in:
committed by
Thomas Peetz
parent
cb0fa3f728
commit
c222d4cd7a
+14
-23
@@ -7,7 +7,6 @@ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
from datetime import datetime
|
||||
from enum import Enum, auto
|
||||
from pathlib import Path
|
||||
from typing import Dict, Union
|
||||
from uuid import UUID
|
||||
|
||||
import requests
|
||||
@@ -22,8 +21,6 @@ parser.add_argument('--tool', '-t', default='yt-dlp')
|
||||
parser.add_argument('--dry-run', '-m', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
type FileInfo = Dict[str, Union[str, bool]]
|
||||
|
||||
class FileStatus(Enum):
|
||||
DOWNLOADED = auto()
|
||||
RENAMED = auto()
|
||||
@@ -64,41 +61,37 @@ def __parse_output__(lines_list: list[str]) -> str | None:
|
||||
return file_name
|
||||
|
||||
|
||||
def is_file_downloaded(media_file: FileInfo, media_dir: Path) -> FileStatus:
|
||||
file_name_as_title = f"{media_file['file_name']}"
|
||||
file_title = Path(media_dir, f"{file_name_as_title}.mp4")
|
||||
def is_file_downloaded(item: dict, dir: Path) -> FileStatus:
|
||||
file_name_as_title = f"{item['file_name']}"
|
||||
file_title = Path(dir, file_name_as_title, ".mp4")
|
||||
if file_title.exists():
|
||||
log.info(f"{file_name_as_title} has been downloaded")
|
||||
media_file['review'] = False
|
||||
media_file['should_download'] = False
|
||||
item['should_download'] = 0
|
||||
return FileStatus.DOWNLOADED
|
||||
file_name_as_id = f"{media_file['id']}"
|
||||
file_with_id_as_name = Path(media_dir, f"{file_name_as_id}.mp4")
|
||||
file_name_as_id = f"{item['id']}"
|
||||
file_with_id_as_name = Path(dir, file_name_as_id, ".mp4")
|
||||
if file_with_id_as_name.exists():
|
||||
log.info(f"{file_with_id_as_name} has been downloaded and renamed")
|
||||
media_file['cloud_link'] = file_with_id_as_name.as_posix()
|
||||
media_file['review'] = False
|
||||
media_file['should_download'] = False
|
||||
item['cloud_link'] = file_with_id_as_name
|
||||
item['should_download'] = 0
|
||||
return FileStatus.RENAMED
|
||||
log.info("could not find file - start download")
|
||||
return FileStatus.UNKNOWN
|
||||
|
||||
|
||||
def update_status(item_id: UUID, file_info: FileInfo):
|
||||
def update_status(item_id: UUID, file_info: dict):
|
||||
update = requests.put(f"http://127.0.0.1:8800/media/files/{item_id}", json=file_info)
|
||||
status = update.status_code
|
||||
log.info(f"update status: {status}")
|
||||
if status < 300:
|
||||
log.info(f"update result: {update.json()}")
|
||||
log.info(f"update status: {update.status_code}")
|
||||
log.info(f"update result: {update.json()}")
|
||||
|
||||
|
||||
def rename_file(file_info: FileInfo):
|
||||
def rename_file(file_info: dict):
|
||||
item_id = file_info['id']
|
||||
file = Path(args.dir, file_info['file_name'])
|
||||
new_file_path = file.with_name(f"{item_id}{file.suffix}")
|
||||
log.info(f"rename {file} to {new_file_path}")
|
||||
file.rename(Path(new_file_path))
|
||||
file_info['cloud_link'] = new_file_path.as_posix()
|
||||
file_info['cloud_link'] = str(new_file_path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -112,9 +105,6 @@ if __name__ == '__main__':
|
||||
link = item['url']
|
||||
file_id = item['id']
|
||||
log.info(f"{file_id} - {link}")
|
||||
if link is None:
|
||||
item['url'] = ""
|
||||
log.info(f"set url for {file_id} to empty string")
|
||||
download_status: FileStatus = is_file_downloaded(item, args.dir)
|
||||
match download_status:
|
||||
case FileStatus.DOWNLOADED:
|
||||
@@ -129,3 +119,4 @@ if __name__ == '__main__':
|
||||
log.info(f'{item}')
|
||||
update_status(file_id, item)
|
||||
log.info('kontor.download finished')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user