Skip to content

Commit

Permalink
Fix: pypa/setuptools#250 이슈로 인한 구조변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Cardroid committed Jul 12, 2022
1 parent 499babd commit e1989e7
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 32 deletions.
File renamed without changes.
File renamed without changes.
28 changes: 0 additions & 28 deletions src/encoder.py → py_media_compressor/encoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from enum import Enum, auto, unique
import os
import ffmpeg
from tqdm import tqdm
import log
Expand All @@ -24,7 +23,6 @@ def has_name(cls, name: str) -> bool:
return name in cls._member_map_


def media_compress_encode(inputFilepath: str, outputFilepath: str, isForce=False, maxHeight=1440) -> bool:
"""미디어를 압축합니다.
Args:
Expand All @@ -34,14 +32,12 @@ def media_compress_encode(inputFilepath: str, outputFilepath: str, isForce=False
max_height (int, optional): 미디어의 최대 세로 픽셀. Defaults to 1440.
Returns:
bool: 성공여부
"""

logger = log.get_logger(name=f"{os.path.splitext(os.path.basename(__file__))[0]}.main")

if not os.path.isfile(inputFilepath):
logger.error(f"입력 파일이 존재하지 않습니다. Filepath: {inputFilepath}")
return False

probe = ffmpeg.probe(inputFilepath)
video_stream = next((stream for stream in probe["streams"] if stream["codec_type"] == "video"), None)
Expand Down Expand Up @@ -94,7 +90,6 @@ def media_compress_encode(inputFilepath: str, outputFilepath: str, isForce=False
if isForce:
logger.warning(f"강제로 재인코딩을 실시합니다... is_force: {isForce}")
else:
return True

audio_stream_info = None

Expand All @@ -120,13 +115,6 @@ def media_compress_encode(inputFilepath: str, outputFilepath: str, isForce=False

stream = ffmpeg.overwrite_output(stream)

try:
_, stderr = ffmpeg.run(cmd="ffmpeg", stream_spec=stream, capture_stderr=True)
logger.info(utils.string_decode(stderr))
except ffmpeg.Error as err:
logger.error(utils.string_decode(err.stderr))

return True


def get_output_fileext(filepath: str):
Expand Down Expand Up @@ -252,25 +240,9 @@ def main():
output_filepath = f"{temp_filename} ({(count := count + 1)}){ext}"
fileinfo["output_file"] = output_filepath

media_compress_encode(inputFilepath=fileinfo["input_file"], outputFilepath=fileinfo["output_file"], isForce=is_force, maxHeight=args["height"])

if not os.path.isfile(fileinfo["output_file"]):
fileinfo["state"] = FileTaskState.ERROR
logger.error(f"압축 처리를 완료했지만, 출력파일이 존재하지 않습니다. \nOutput Filepath: {fileinfo['output_file']}")
else:
fileinfo["state"] = FileTaskState.SUCCESS
fileinfo["output_md5_hash"] = utils.get_MD5_hash(fileinfo["output_file"])

logger.info(f"압축 처리 완료: \nOutput Filepath: {fileinfo['output_file']}\nOutput File MD5 Hash: {fileinfo['output_md5_hash']}")

if is_replace:
os.replace(fileinfo["output_file"], output_filepath := f"{os.path.splitext(fileinfo['input_file'])[0]}{ext}")

if os.path.splitext(fileinfo["input_file"])[1] != os.path.splitext(fileinfo["output_file"])[1]:
os.remove(fileinfo["input_file"])

fileinfo["output_file"] = output_filepath
logger.info(f"덮어쓰기 완료: {fileinfo['output_file']}")

logger.debug(f"처리완료 최종 파일 정보: \n{pformat(fileinfo)}")

Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import setuptools

required_packages = [
"tqdm",
"tqdm==4.64.0",
"ffmpeg-python==0.2.0",
"colorlog==6.6.0",
"pyyaml==6.0",
]

setuptools.setup(
name="pymediacompressor",
name="py-media-compressor",
version="0.0.1",
author="cardroid",
author_email="carbonsindh@gmail.com",
description="Media compression encoder with ffmpeg Python wrapper",
install_requires=required_packages,
license="MIT",
packages=setuptools.find_packages(where="src"),
package_dir={"": "src"},
packages=setuptools.find_packages(where="py_media_compressor"),
package_dir={"": "py_media_compressor"},
python_requires=">=3.8",
include_package_data=True,
entry_points={"console_scripts": ["encode=encoder:main"]},
Expand Down

0 comments on commit e1989e7

Please sign in to comment.