[DEV] add basic tools in .bin

This commit is contained in:
Edouard DUPIN 2017-03-20 22:26:06 +01:00
parent 113bec9c89
commit 7aed755e5c
5 changed files with 6639 additions and 0 deletions

23
.bin/convertFile.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# user input
MAXLEN=1200
RESIZE_DIR_NAME="resized_picture"
nb_elem=0
for i in *jpg *.jpeg *.JPG *.JPEG; do
nb_elem=`expr $nb_elem + 1`
done
idelem=0
[ -d $RESIZE_DIR_NAME ] || mkdir $RESIZE_DIR_NAME
for i in *.jpg *.jpeg *.JPG *.JPEG; do
if [ -e $i ] ; then
idelem=`expr $idelem + 1`
echo "#convert file (" $idelem "/" $nb_elem "): " $i " ==> " $RESIZE_DIR_NAME/$i
convert $i -resize ${MAXLEN}x${MAXLEN} $RESIZE_DIR_NAME/$i
fi
done

6144
.bin/cpplint.py vendored Executable file

File diff suppressed because it is too large Load Diff

31
.bin/replaceSed.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
listFiles=" `find . -name "*.php"` "
listFiles+=" `find . -name "*.cpp"` "
listFiles+=" `find . -name "*.cxx"` "
listFiles+=" `find . -name "*.c"` "
listFiles+=" `find . -name "*.h"` "
listFiles+=" `find . -name "*.hpp"` "
listFiles+=" `find . -name "*.hxx"` "
listFiles+=" `find . -name "*.inl"` "
listFiles+=" `find . -name "*.java"` "
listFiles+=" `find . -name "*.m"` "
listFiles+=" `find . -name "*.mm"` "
listFiles+=" `find . -name "*.mk"` "
listFiles+=" `find . -name "*.md"` "
listFiles+=" `find . -name "*.py"` "
echo "Replace : \"$1\" ==> \"$2\""
for iii in $listFiles
do
echo "* File : "$iii
sed -ri "s|$1|$2|" $iii
#sed -ri 'N; s/[ \t]*\n[\t ]*else/ else/' $iii
#sed -ri 'N; s/[ \t]*\n[\t ]*\{/ \{/' $iii
#sed -ri 'N; s/[ \t]*\n[\t ]*\{/ \{/' $iii
#sed -ri 'N; s/[ \t]*\n[\t ]*\{/ \{/' $iii
#sed -ri 'N; s/[ \t]*\n[\t ]*\{/ \{/' $iii
done

257
.bin/videoRename.py Executable file
View File

@ -0,0 +1,257 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license APACHE v2.0 (see license file)
##
import os
import shutil
import errno
import fnmatch
import stat
import sys
import subprocess
import shlex
##
## @brief Execute the command with no get of output
##
def run_command(cmd_line):
# prepare command line:
args = shlex.split(cmd_line)
print("[INFO] cmd = " + str(args))
try:
# create the subprocess
p = subprocess.Popen(args)
except subprocess.CalledProcessError as e:
print("[ERROR] subprocess.CalledProcessError : " + str(args))
return False
#except:
# debug.error("Exception on : " + str(args))
# launch the subprocess:
output, err = p.communicate()
# Check error :
if p.returncode == 0:
return True
else:
return False
##
## @brief Get list of all Files in a specific path (with a regex)
## @param[in] path (string) Full path of the machine to search files (start with / or x:)
## @param[in] regex (string) Regular expression to search data
## @param[in] recursive (bool) List file with recursive search
## @param[in] remove_path (string) Data to remove in the path
## @return (list) return files requested
##
def get_list_of_file_in_path(path, filter, recursive = False, remove_path=""):
out = []
if os.path.isdir(os.path.realpath(path)):
tmp_path = os.path.realpath(path)
else:
print("[E] path does not exist : '" + str(path) + "'")
for root, dirnames, filenames in os.walk(tmp_path):
deltaRoot = root[len(tmp_path):]
while len(deltaRoot) > 0 \
and ( deltaRoot[0] == '/' \
or deltaRoot[0] == '\\' ):
deltaRoot = deltaRoot[1:]
if recursive == False \
and deltaRoot != "":
return out
tmpList = []
for elem in filter:
tmpppp = fnmatch.filter(filenames, elem)
for elemmm in tmpppp:
tmpList.append(elemmm)
# Import the module :
for cycleFile in tmpList:
#for cycleFile in filenames:
add_file = os.path.join(tmp_path, deltaRoot, cycleFile)
if len(remove_path) != 0:
if add_file[:len(remove_path)] != remove_path:
print("[E] Request remove start of a path that is not the same: '" + add_file[:len(remove_path)] + "' demand remove of '" + str(remove_path) + "'")
else:
add_file = add_file[len(remove_path)+1:]
out.append(add_file)
return out;
def rm_date(data):
val = data.split("_France 2_")
if len(val) == 2:
return val[0]
val = data.split("_France 3_")
if len(val) == 2:
return val[0]
val = data.split("_France 4_")
if len(val) == 2:
return val[0]
val = data.split("_France 5_")
if len(val) == 2:
return val[0]
val = data.split("_France O_")
if len(val) == 2:
return val[0]
val = data.split("_NT1_")
if len(val) == 2:
return val[0]
val = data.split("_TF1_")
if len(val) == 2:
return val[0]
val = data.split("_TMC_")
if len(val) == 2:
return val[0]
val = data.split("_Gulli_")
if len(val) == 2:
return val[0]
return data
def rename_group(list_element, extention):
for elem in list_files:
reduced_name = rm_date(elem[:-(len(extention)+1)])
print("file: " + reduced_name)
# remove the date in the channel ...
val = reduced_name.split(" - ")
if len(val) == 1:
#standard film ...
print(" FILM")
if val[0] + "." + extention != elem:
print(" ==> rename ...")
print(" " + elem)
print(" " + val[0] + "." + extention)
out = val[0] + "." + extention
if os.path.isfile(out):
print(" " + out + " ==> exist ...")
offset = 0
while offset < 98:
offset += 1
out = val[0] + "__________" + str(offset) + "." + extention
if os.path.isfile(out):
print(" " + out + " ==> exist ...")
else:
break
if offset >= 98:
print(" " + out + " ==> Cen not move ...")
continue
cmd_line = "mv " + elem.replace(" ", "\ ").replace("'", "\\'") + " " + out.replace(" ", "\ ").replace("'", "\\'")
ret = run_command(cmd_line)
elif len(val) == 2:
print(" ???")
valll = val[0] + " - " + val[1]
if valll + "." + extention != elem:
print(" ==> rename ...")
print(" " + elem)
print(" " + valll + "." + extention)
out = valll + "." + extention
if os.path.isfile(out):
offset = 0
while offset < 98:
offset += 1
out = valll + "__________" + str(offset) + "." + extention
if os.path.isfile(out):
print(" " + out + " ==> exist ...")
else:
break
if offset >= 98:
print(" " + out + " ==> Cen not move ...")
continue
cmd_line = "mv " + elem.replace(" ", "\ ").replace("'", "\\'") + " " + out.replace(" ", "\ ").replace("'", "\\'")
ret = run_command(cmd_line)
elif val[1][:6] == "Saison" \
or val[1][1:7] == "pisode":
# remove space ... not needed to parse ...
tmp = val[1].replace(" ", "")
saison_id = -1
episode_id = -1
if tmp[:6] == "Saison":
# start with saison ...
tmp = tmp[6:]
parts = tmp.split("pisode")
if len(parts) == 1:
# only the saison ID
saison_id = int(parts[0])
else:
vallllll = ""
for vvv in parts[0]:
if vvv not in "0123456789":
break
vallllll += vvv
saison_id = int(vallllll)
while len(parts[1]) > 0 and parts[1][0] not in "0123456789":
parts[1] = parts[1][1:]
episode_id = int(parts[1])
else:
# start with Episode
while len(tmp) > 0 and tmp[0] not in "0123456789":
tmp = tmp[1:]
parts = tmp.split("Saison")
if len(parts) == 1:
# only the Episode ID
episode_id = int(parts[0])
else:
saison_id = int(parts[1])
episode_id = int(parts[0])
print(" SERIE TV")
special_element = "s"
if saison_id == -1:
special_element += "XX"
elif saison_id < 10:
special_element += "0" + str(saison_id)
else:
special_element += str(saison_id)
special_element += "-e"
if episode_id == -1:
special_element += "XX"
elif episode_id < 10:
special_element += "0" + str(episode_id)
else:
special_element += str(episode_id)
valll = val[0] + "-" + special_element + "-" + val[2]
if valll + "." + extention != elem:
print(" ==> rename ...")
print(" " + elem)
print(" " + valll + "." + extention)
out = valll + "." + extention
if os.path.isfile(out):
print(" " + out + " ==> exist ...")
offset = 0
while offset < 98:
offset += 1
out = valll + "__________" + str(offset) + "." + extention
if os.path.isfile(out):
print(" " + out + " ==> exist ...")
else:
break
if offset >= 98:
print(" " + out + " ==> Cen not move ...")
continue
cmd_line = "mv " + elem.replace(" ", "\ ").replace("'", "\\'") + " " + out.replace(" ", "\ ").replace("'", "\\'")
ret = run_command(cmd_line)
else:
print(" ??????????????")
for extention in ["ts","avi","mkv","mp4"]:
list_files = get_list_of_file_in_path(".", ["*."+extention])
rename_group(list_files, extention)

184
.bin/videoTranscode.py Executable file
View File

@ -0,0 +1,184 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
## @author Edouard DUPIN
##
## @copyright 2016, Edouard DUPIN, all right reserved
##
## @license APACHE v2.0 (see license file)
##
import os
import fnmatch
import sys
import subprocess
import shlex
##
## @brief Execute the command with no get of output
##
def run_command(cmd_line):
# prepare command line:
args = shlex.split(cmd_line)
print("[INFO] cmd = " + str(args))
try:
# create the subprocess
p = subprocess.Popen(args)
except subprocess.CalledProcessError as e:
print("[ERROR] subprocess.CalledProcessError : " + str(args))
return False
#except:
# debug.error("Exception on : " + str(args))
# launch the subprocess:
output, err = p.communicate()
# Check error :
if p.returncode == 0:
return True
else:
return False
##
## @brief Get list of all Files in a specific path (with a regex)
## @param[in] path (string) Full path of the machine to search files (start with / or x:)
## @param[in] regex (string) Regular expression to search data
## @param[in] recursive (bool) List file with recursive search
## @param[in] remove_path (string) Data to remove in the path
## @return (list) return files requested
##
def get_list_of_file_in_path(path, regex="*", recursive = False, remove_path=""):
out = []
if os.path.isdir(os.path.realpath(path)):
tmp_path = os.path.realpath(path)
tmp_rule = regex
else:
debug.error("path does not exist : '" + str(path) + "'")
for root, dirnames, filenames in os.walk(tmp_path):
deltaRoot = root[len(tmp_path):]
while len(deltaRoot) > 0 \
and ( deltaRoot[0] == '/' \
or deltaRoot[0] == '\\' ):
deltaRoot = deltaRoot[1:]
if recursive == False \
and deltaRoot != "":
return out
tmpList = filenames
if len(tmp_rule) > 0:
tmpList = fnmatch.filter(filenames, tmp_rule)
# Import the module :
for cycleFile in tmpList:
#for cycleFile in filenames:
add_file = os.path.join(tmp_path, deltaRoot, cycleFile)
if len(remove_path) != 0:
if add_file[:len(remove_path)] != remove_path:
print("ERROR : Request remove start of a path that is not the same: '" + add_file[:len(remove_path)] + "' demand remove of '" + str(remove_path) + "'")
else:
add_file = add_file[len(remove_path)+1:]
out.append(add_file)
return out;
#ffmpeg -i 000.ts -threads 0 -vcodec libx264 -crf 20 -force_key_frames expr:gte\(t,n_forced*1\) -s 720x540 -acodec mp2 -ac 2 -ab 192k -ar 48000 -async 1 -deinterlace 000_transcoded.ts
#ffmpeg -i 000.ts -threads 0 -vcodec libx264 -crf 20 -force_key_frames expr:gte\(t,n_forced*1\) -acodec mp2 -ac 2 -ab 192k -ar 48000 -async 1 -deinterlace 000_transcoded.ts
list_files_ts = get_list_of_file_in_path('.', "*.ts")
list_files_flv = get_list_of_file_in_path('.', "*.flv")
list_files_mp4 = get_list_of_file_in_path('.', "*.mp4")
list_files_avi = get_list_of_file_in_path('.', "*.avi")
list_files_mkv = get_list_of_file_in_path('.', "*.mkv")
# remove all encoded element in the other files (TS)
for elem_mkv in list_files_mkv:
index = 0
for elem_ts in list_files_ts:
if elem_mkv[:-3]+"ts" == elem_ts:
break;
index += 1
if index != len(list_files_ts):
print("[INFO] remove from list '" + list_files_ts[index] + "' ==> already transcoded")
del list_files_ts[index]
# remove all encoded element in the other files (FLV)
for elem_mkv in list_files_mkv:
index = 0
for elem_flv in list_files_flv:
if elem_mkv[:-3]+"flv" == elem_flv:
break;
index += 1
if index != len(list_files_flv):
print("[INFO] remove from list '" + list_files_flv[index] + "' ==> already transcoded")
del list_files_flv[index]
# remove all encoded element in the other files (mp4)
for elem_mkv in list_files_mkv:
index = 0
for elem_mp4 in list_files_mp4:
if elem_mkv[:-3]+"mp4" == elem_mp4:
break;
index += 1
if index != len(list_files_mp4):
print("[INFO] remove from list '" + list_files_mp4[index] + "' ==> already transcoded")
del list_files_mp4[index]
# remove all encoded element in the other files (TS)
for elem_mkv in list_files_mkv:
index = 0
for elem_avi in list_files_avi:
if elem_mkv[:-3]+"ts" == elem_avi:
break;
index += 1
if index != len(list_files_avi):
print("[INFO] remove from list '" + list_files_avi[index] + "' ==> already transcoded")
del list_files_avi[index]
print("list of elements TS : ")
for elem in list_files_ts:
print(" - '" + elem + "'")
print("list of elements MP4 : ")
for elem in list_files_mp4:
print(" - '" + elem + "'")
print("list of elements FLV : ")
for elem in list_files_flv:
print(" - '" + elem + "'")
print("list of elements AVI : ")
for elem in list_files_avi:
print(" - '" + elem + "'")
print("list of elements MKV : ")
for elem in list_files_mkv:
print(" - '" + elem + "'")
def trancode_local(list_of_file=[], extention="ts", total_count_of_file=0, offset=0) :
print("Start strancoding: '." + extention + "' ... " + str(len(list_of_file)))
id_elem = 0
for elem in list_of_file:
id_elem += 1
print(" ========================================================================================")
print(" == " + str(offset+id_elem) + " / " + str(total_count_of_file))
print(" == Trancode: '" + elem.replace("'", "\'") + "'")
print(" ========================================================================================")
cmd_line = "ffmpeg -i "
cmd_line += elem.replace(" ", "\ ").replace("'", "\\'")
cmd_line += " -threads 4 -vcodec libx264 -crf 22 -force_key_frames expr:gte\(t,n_forced*1\) -acodec mp2 -ac 2 -ab 192k -ar 48000 -async 1 -deinterlace tmp_transcoded.mkv"
ret = run_command(cmd_line)
print(" ret value = " + str(ret))
if ret == False:
print("[ERROR] Trancode: error occured ...")
exit(-1)
print(" move in: '" + elem[:-len(extention)] + "mkv'")
cmd_line = "mv tmp_transcoded.mkv " + elem.replace(" ", "\ ").replace("'", "\\'")[:-len(extention)] + "mkv"
ret = run_command(cmd_line)
offset = 0;
trancode_local(list_files_ts , "ts", len(list_files_ts) + len(list_files_mp4) + len(list_files_flv) + len(list_files_avi), offset)
offset += len(list_files_ts);
trancode_local(list_files_mp4 , "mp4", len(list_files_ts) + len(list_files_mp4) + len(list_files_flv) + len(list_files_avi), offset)
offset += len(list_files_mp4);
trancode_local(list_files_flv , "flv", len(list_files_ts) + len(list_files_mp4) + len(list_files_flv) + len(list_files_avi), offset)
offset += len(list_files_flv);
trancode_local(list_files_avi , "avi", len(list_files_ts) + len(list_files_mp4) + len(list_files_flv) + len(list_files_avi), offset)