moved update and download functionality to kontor-schema
This commit is contained in:
@@ -1,14 +1,4 @@
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
|
||||
from cement import Controller, ex
|
||||
from kontor_schema import KontorDB
|
||||
from kontor_video import VideoLink, MediaVideo
|
||||
|
||||
|
||||
class VideoType(Enum):
|
||||
MEDIA_FILE = "media_file"
|
||||
MEDIA_VIDEO = "media_video"
|
||||
|
||||
|
||||
class Media(Controller):
|
||||
@@ -23,8 +13,8 @@ class Media(Controller):
|
||||
)
|
||||
def update_title(self):
|
||||
db = self.app.kontor_db
|
||||
updates = db.get_update_list()
|
||||
self.app.log.info(f"found {len(updates)} links for update")
|
||||
updates = db.update_titles()
|
||||
self.app.log.info(f"{len(updates)} entries updated")
|
||||
|
||||
@ex(
|
||||
label='download',
|
||||
@@ -43,25 +33,12 @@ class Media(Controller):
|
||||
if self.app.pargs.media_dir is not None:
|
||||
data['media_dir'] = self.app.pargs.media_dir
|
||||
db = self.app.kontor_db
|
||||
downloads = db.get_download_list(data['media_dir'])
|
||||
downloads = db.get_download_list()
|
||||
self.app.log.info(f"found {len(downloads)} links for download")
|
||||
#for file_id, url in downloads.items():
|
||||
# link = VideoLink(url, VideoType.MEDIA_FILE)
|
||||
# file_name = link.download(download_dir=data['media_dir'])
|
||||
# if file_name is None:
|
||||
# db.update_entry('media_file', file_id, {'file_name': None, 'should_download': 1})
|
||||
# else:
|
||||
# download_file = Path(file_name)
|
||||
# download_file.with_name(f"{file_id}{download_file.suffix}")
|
||||
# link.file_name = download_file.name
|
||||
# link.should_download = 0
|
||||
# link.cloud_link = download_file.absolute()
|
||||
# db.update_entry('media_file', file_id,
|
||||
# {
|
||||
# 'file_name': download_file.name,
|
||||
# 'should_download': 0,
|
||||
# 'cloud_link': download_file.absolute()}
|
||||
# )
|
||||
for entry_id in downloads:
|
||||
result = db.download_file(entry_id, download_dir=data['media_dir'])
|
||||
if result is not None:
|
||||
self.app.log.info(f"file {result} successfully downloaded")
|
||||
|
||||
@ex(
|
||||
help='add url to database',
|
||||
|
||||
Reference in New Issue
Block a user