Skip to content

Commit

Permalink
move handle results
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed May 28, 2024
1 parent cdeb968 commit ad72300
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 139 deletions.
5 changes: 4 additions & 1 deletion ofscraper/download/alt_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
import ofscraper.utils.live.screens as progress_utils
from ofscraper.download.shared.classes.retries import download_retry
from ofscraper.download.shared.common.alt_common import (
handle_result_alt,
media_item_keys_alt,
media_item_post_process_alt,
)

from ofscraper.download.shared.common.handle_result import (
handle_result_alt,
)
from ofscraper.download.shared.common.general import (
check_forced_skip,
downloadspace,
Expand Down
4 changes: 3 additions & 1 deletion ofscraper/download/alt_downloadbatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import ofscraper.utils.system.system as system
from ofscraper.download.shared.classes.retries import download_retry
from ofscraper.download.shared.common.alt_common import (
handle_result_alt,
media_item_keys_alt,
media_item_post_process_alt,
)
from ofscraper.download.shared.common.handle_result import (
handle_result_alt,
)
from ofscraper.download.shared.common.general import (
check_forced_skip,
downloadspace,
Expand Down
2 changes: 1 addition & 1 deletion ofscraper/download/main_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
get_update_count,
size_checker,
)
from ofscraper.download.shared.common.main_common import handle_result_main
from ofscraper.download.shared.common.handle_result import handle_result_main
from ofscraper.download.shared.utils.log import get_url_log, path_to_file_logger
from ofscraper.download.shared.utils.metadata import force_download
from ofscraper.download.shared.common.send_bar_msg import (
Expand Down
2 changes: 1 addition & 1 deletion ofscraper/download/main_downloadbatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
get_update_count,
size_checker,
)
from ofscraper.download.shared.common.main_common import handle_result_main
from ofscraper.download.shared.common.handle_result import handle_result_main
from ofscraper.download.shared.utils.log import get_url_log, path_to_file_logger
from ofscraper.download.shared.utils.metadata import force_download

Expand Down
82 changes: 0 additions & 82 deletions ofscraper/download/shared/common/alt_common.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,8 @@
import subprocess

import arrow

import ofscraper.classes.placeholder as placeholder
import ofscraper.db.operations as operations
import ofscraper.download.shared.common.general as common
import ofscraper.download.shared.globals as common_globals
import ofscraper.download.shared.utils.keyhelpers as keyhelpers
import ofscraper.download.shared.utils.log as common_logs
import ofscraper.download.shared.utils.paths as common_paths
import ofscraper.utils.dates as dates
import ofscraper.utils.settings as settings
import ofscraper.utils.system.system as system
from ofscraper.db.operations_.media import download_media_update
from ofscraper.download.shared.utils.metadata import force_download


async def handle_result_alt(
sharedPlaceholderObj, ele, audio, video, username, model_id
):
tempPlaceholder = await placeholder.tempFilePlaceholder(
ele, f"temp_{ele.id or await ele.final_filename}.mp4"
).init()
temp_path = tempPlaceholder.tempfilepath
temp_path.unlink(missing_ok=True)
t = subprocess.run(
[
settings.get_ffmpeg(),
"-i",
str(video["path"]),
"-i",
str(audio["path"]),
"-c",
"copy",
"-movflags",
"use_metadata_tags",
str(temp_path),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if t.stderr.decode().find("Output") == -1:
common_globals.log.debug(f"{common_logs.get_medialog(ele)} ffmpeg failed")
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} ffmpeg {t.stderr.decode()}"
)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} ffmpeg {t.stdout.decode()}"
)

video["path"].unlink(missing_ok=True)
audio["path"].unlink(missing_ok=True)

common_globals.log.debug(
f"Moving intermediate path {temp_path} to {sharedPlaceholderObj.trunicated_filepath}"
)
common_paths.moveHelper(temp_path, sharedPlaceholderObj.trunicated_filepath, ele)
(
common_paths.addGlobalDir(sharedPlaceholderObj.filedir)
if system.get_parent_process()
else common_paths.addLocalDir(sharedPlaceholderObj.filedir)
)
if ele.postdate:
newDate = dates.convert_local_time(ele.postdate)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} Attempt to set Date to {arrow.get(newDate).format('YYYY-MM-DD HH:mm')}"
)
common_paths.set_time(sharedPlaceholderObj.trunicated_filepath, newDate)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} Date set to {arrow.get(sharedPlaceholderObj.trunicated_filepath.stat().st_mtime).format('YYYY-MM-DD HH:mm')}"
)
if ele.id:
await download_media_update(
ele,
filepath=sharedPlaceholderObj.trunicated_filepath,
model_id=model_id,
username=username,
downloaded=True,
hashdata=await common.get_hash(
sharedPlaceholderObj, mediatype=ele.mediatype
),
size=sharedPlaceholderObj.size,
)
common.add_additional_data(sharedPlaceholderObj, ele)
return ele.mediatype, video["total"] + audio["total"]


async def media_item_post_process_alt(audio, video, ele, username, model_id):
if (audio["total"] + video["total"]) == 0:
Expand Down
130 changes: 130 additions & 0 deletions ofscraper/download/shared/common/handle_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import pathlib
import subprocess

import arrow

import ofscraper.download.shared.common.general as common
import ofscraper.download.shared.globals as common_globals
import ofscraper.download.shared.utils.log as common_logs
import ofscraper.download.shared.utils.paths as common_paths
import ofscraper.utils.dates as dates
import ofscraper.utils.system.system as system
import ofscraper.classes.placeholder as placeholder




import ofscraper.utils.settings as settings
from ofscraper.db.operations_.media import download_media_update


async def handle_result_main(result, ele, username, model_id):
total, temp, placeholderObj = result
path_to_file = placeholderObj.trunicated_filepath
await common.size_checker(temp, ele, total)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} {await ele.final_filename} size match target: {total} vs actual: {pathlib.Path(temp).absolute().stat().st_size}"
)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} renaming {pathlib.Path(temp).absolute()} -> {path_to_file}"
)
common_paths.moveHelper(temp, path_to_file, ele)
(
common_paths.addGlobalDir(placeholderObj.filedir)
if system.get_parent_process()
else common_paths.addLocalDir(placeholderObj.filedir)
)
if ele.postdate:
newDate = dates.convert_local_time(ele.postdate)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} Attempt to set Date to {arrow.get(newDate).format('YYYY-MM-DD HH:mm')}"
)
common_paths.set_time(path_to_file, newDate)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} Date set to {arrow.get(path_to_file.stat().st_mtime).format('YYYY-MM-DD HH:mm')}"
)

if ele.id:
await download_media_update(
ele,
filepath=path_to_file,
model_id=model_id,
username=username,
downloaded=True,
hashdata=await common.get_hash(path_to_file, mediatype=ele.mediatype),
size=placeholderObj.size,
)
await common.set_profile_cache_helper(ele)
common.add_additional_data(placeholderObj, ele)

return ele.mediatype, total


async def handle_result_alt(
sharedPlaceholderObj, ele, audio, video, username, model_id
):
tempPlaceholder = await placeholder.tempFilePlaceholder(
ele, f"temp_{ele.id or await ele.final_filename}.mp4"
).init()
temp_path = tempPlaceholder.tempfilepath
temp_path.unlink(missing_ok=True)
t = subprocess.run(
[
settings.get_ffmpeg(),
"-i",
str(video["path"]),
"-i",
str(audio["path"]),
"-c",
"copy",
"-movflags",
"use_metadata_tags",
str(temp_path),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if t.stderr.decode().find("Output") == -1:
common_globals.log.debug(f"{common_logs.get_medialog(ele)} ffmpeg failed")
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} ffmpeg {t.stderr.decode()}"
)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} ffmpeg {t.stdout.decode()}"
)

video["path"].unlink(missing_ok=True)
audio["path"].unlink(missing_ok=True)

common_globals.log.debug(
f"Moving intermediate path {temp_path} to {sharedPlaceholderObj.trunicated_filepath}"
)
common_paths.moveHelper(temp_path, sharedPlaceholderObj.trunicated_filepath, ele)
(
common_paths.addGlobalDir(sharedPlaceholderObj.filedir)
if system.get_parent_process()
else common_paths.addLocalDir(sharedPlaceholderObj.filedir)
)
if ele.postdate:
newDate = dates.convert_local_time(ele.postdate)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} Attempt to set Date to {arrow.get(newDate).format('YYYY-MM-DD HH:mm')}"
)
common_paths.set_time(sharedPlaceholderObj.trunicated_filepath, newDate)
common_globals.log.debug(
f"{common_logs.get_medialog(ele)} Date set to {arrow.get(sharedPlaceholderObj.trunicated_filepath.stat().st_mtime).format('YYYY-MM-DD HH:mm')}"
)
if ele.id:
await download_media_update(
ele,
filepath=sharedPlaceholderObj.trunicated_filepath,
model_id=model_id,
username=username,
downloaded=True,
hashdata=await common.get_hash(
sharedPlaceholderObj, mediatype=ele.mediatype
),
size=sharedPlaceholderObj.size,
)
common.add_additional_data(sharedPlaceholderObj, ele)
return ele.mediatype, video["total"] + audio["total"]
53 changes: 0 additions & 53 deletions ofscraper/download/shared/common/main_common.py

This file was deleted.

0 comments on commit ad72300

Please sign in to comment.