Code review with pylint (not complete)
This commit is contained in:
parent
f7d8edba6a
commit
6d9c0da66a
1 changed files with 47 additions and 22 deletions
|
@ -1,10 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# export-video.py
|
||||
# ---------------
|
||||
# little python script to encode vide file for the web
|
||||
#
|
||||
|
||||
"""
|
||||
export-video
|
||||
Little scrip to export video file for The Internet :D
|
||||
"""
|
||||
import sys
|
||||
import getopt
|
||||
import re
|
||||
|
@ -15,6 +13,7 @@ logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
|||
|
||||
|
||||
def usage():
|
||||
""" Print usage"""
|
||||
print("export-video -i input -o output [-d --desinterlace]")
|
||||
|
||||
params = {
|
||||
|
@ -66,24 +65,38 @@ def execute(command, shell=False):
|
|||
|
||||
|
||||
def find_executable(exec_name):
|
||||
"""
|
||||
find executable with which command
|
||||
exec_name (string) : executable to find
|
||||
"""
|
||||
if not exec_name:
|
||||
raise ValueError("find_executable: exec_name required")
|
||||
return execute(['which', exec_name])
|
||||
|
||||
|
||||
def listFile(directory, pattern, recursive):
|
||||
def list_file(directory, pattern, recursive):
|
||||
"""
|
||||
list files from a directory
|
||||
directory (string) : source directory
|
||||
pattern (string) : regex used to found files
|
||||
recursive (boolean) : should i serach on sub-folder?
|
||||
"""
|
||||
logging.info('searching in directory %s', directory)
|
||||
files_list = []
|
||||
try:
|
||||
dirs = os.listdir(directory)
|
||||
except:
|
||||
except OSError:
|
||||
logging.error('error : %s not a directory?', directory)
|
||||
return
|
||||
|
||||
for i in dirs:
|
||||
if os.path.isdir(directory + "/" + i) and recursive:
|
||||
logging.info('directory found : %s', i)
|
||||
files_list.extend(listFile(directory + "/" + i, pattern))
|
||||
files_list.extend(list_file(
|
||||
directory + "/" + i,
|
||||
pattern,
|
||||
recursive
|
||||
))
|
||||
else:
|
||||
if re.search(pattern, i) is not None:
|
||||
logging.info('file found : %s', i)
|
||||
|
@ -92,10 +105,18 @@ def listFile(directory, pattern, recursive):
|
|||
|
||||
|
||||
def get_file_name(path):
|
||||
"""
|
||||
find basename without extension
|
||||
path (string) : complete path + file
|
||||
"""
|
||||
return os.path.splitext(os.path.basename(path))[0]
|
||||
|
||||
|
||||
def process_arg(sysarg):
|
||||
"""
|
||||
Process arguments
|
||||
sysarg (list) : list of arguments
|
||||
"""
|
||||
try:
|
||||
opts, args = getopt.getopt(
|
||||
sysarg, "hi:o:dp:a:v:2",
|
||||
|
@ -138,10 +159,14 @@ def process_arg(sysarg):
|
|||
|
||||
|
||||
def encode_h264(src, dest):
|
||||
if (params["twopass"]):
|
||||
""" Encode file
|
||||
src (string) : source video file
|
||||
dest (string) : destination file
|
||||
"""
|
||||
if params["twopass"]:
|
||||
logging.debug("two pass encoding started ...")
|
||||
firstpass = [
|
||||
exec_ffmpeg,
|
||||
EXEC_FFMPEG,
|
||||
"-y",
|
||||
"-i", src,
|
||||
"-codec:va", "libx264",
|
||||
|
@ -152,7 +177,7 @@ def encode_h264(src, dest):
|
|||
"/dev/null"
|
||||
]
|
||||
secondpass = [
|
||||
exec_ffmpeg,
|
||||
EXEC_FFMPEG,
|
||||
"-i", src,
|
||||
"-pass", "2",
|
||||
"-codec:v", "libx264",
|
||||
|
@ -167,7 +192,7 @@ def encode_h264(src, dest):
|
|||
else:
|
||||
logging.debug("one pass encoding started ...")
|
||||
encode = [
|
||||
exec_ffmpeg,
|
||||
EXEC_FFMPEG,
|
||||
"-i", src,
|
||||
"-codec:v", "libx264",
|
||||
"-b:v ", params["vbitrate"]
|
||||
|
@ -181,8 +206,8 @@ def encode_h264(src, dest):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exec_ffmpeg = find_executable("ffmpeg")
|
||||
if not exec_ffmpeg:
|
||||
EXEC_FFMPEG = find_executable("ffmpeg")
|
||||
if not EXEC_FFMPEG:
|
||||
print('ffmpeg not found, exiting')
|
||||
sys.exit(2)
|
||||
process_arg(sys.argv[1:])
|
||||
|
@ -194,20 +219,20 @@ if __name__ == "__main__":
|
|||
print("Can't batch export to a single file! Bye Bye")
|
||||
sys.exit(2)
|
||||
logging.info('%s is a directory', params["file_input"])
|
||||
video_files = listFile(
|
||||
params["file_input"],
|
||||
params["pattern"],
|
||||
params["recursive"]
|
||||
)
|
||||
video_files = list_file(
|
||||
params["file_input"],
|
||||
params["pattern"],
|
||||
params["recursive"]
|
||||
)
|
||||
for f in video_files:
|
||||
logging.info('batch encode | file %s to %s', f)
|
||||
logging.info('batch encode | file %s', f)
|
||||
encode_h264(f, params["file_output"] + get_file_name(f))
|
||||
else:
|
||||
if os.path.isfile(params["file_input"]):
|
||||
if not params["file_output"]:
|
||||
params["file_output"] = get_file_name(params["file_input"])
|
||||
else:
|
||||
if(os.path.isdir(params["file_output"])):
|
||||
if os.path.isdir(params["file_output"]):
|
||||
params["file_input"] += get_file_name(params["file_input"])
|
||||
logging.info('%s is a file', params["file_input"])
|
||||
encode_h264(params["file_input"], params["file_output"])
|
||||
|
|
Reference in a new issue