From 71374e317e21caa32624f4529034896db103cbdb Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Tue, 20 Aug 2013 11:54:46 +0200 Subject: [PATCH] add rename-video script --- bin/rename-video.sh | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 bin/rename-video.sh diff --git a/bin/rename-video.sh b/bin/rename-video.sh new file mode 100755 index 0000000..017179d --- /dev/null +++ b/bin/rename-video.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +get_videoinfo() { + local -a mediainfo + IFS=, + mediainfo=( $(mediainfo --Output='Video;%Width%,%Height%,%ScanType%,%Format%,%Codec%' "$1") ) + mediainfo=( $(ffprobe -select_streams v -show_entries stream=codec_name,width,height -of compact "$1" 2> /dev/null) ) + local width=${mediainfo[0]} + local height=${mediainfo[1]} + local scan=${mediainfo[2]} + local format=${mediainfo[3]} + local codecid=${mediainfo[4]} + + echo ${mediainfo[@]} + return + + # same tests xbmc does: + # https://github.com/xbmc/xbmc/blob/master/xbmc/utils/StreamDetails.cpp#L514 + if (( $width <= 720 && $height <= 480 )); then + resolution=480 + elif (( $width <= 768 && $height <= 576)); then + resolution=576 + elif (( $width <= 960 && $height <= 544)); then + resolution=540 + elif (( $width <= 1280 && $height <= 720)); then + resolution=720 + else + resolution=1080 + fi + + if [[ "$scan" == "Progressive" ]]; then + resolution+="p" + elif [[ "$scan" == "Interlaced" ]]; then + resolution+="i" + fi + + vcodec= + if [[ "$format" == "AVC" ]]; then + vcodec=h264 + elif [[ "$format" == "VC-1" && "$codecid" == "WVC1" ]]; then + vcodec=wvc1 + elif [[ "$codecid" == "XVID" ]]; then + vcodec=xvid + elif [[ "$codecid" == "DIV3" || "$codecid" == "DX50" || "$codecid" == "DIVX" ]]; then + vcodec=divx + elif [[ "$codecid" == "V_MPEG2" ]]; then + vcodec=mpeg2 + elif [[ "$codecid" == "MP42" ]]; then + vcodec=mp42 + else + echo $f + echo $format $codecid + fi +} + +#TODO +get_audioinfo() { + local -a mediainfo + IFS=, + mediainfo=( $(mediainfo --Output='General;%Audio_Format_List%,%Audio_Language_List%,%AudioCount%' "$1") ) + IFS=' / ' + local format=( ${mediainfo[0]} ) + local lang=( ${mediainfo[1]} ) + local cnt=${mediainfo[2]} + + audio= + local -i i=0 + while (( $i < $cnt )) ; do + local iformat=${format[$i]} + local ilang=${lang[$i]} + + acodec= + if [[ "$iformat" == "DTS" ]]; then + acodec=dts + elif [[ "$iformat" == "AC-3" ]]; then + acodec=ac3 + elif [[ "$iformat" == "MPEG Audio" ]]; then + acodec=mp3 + else + echo "$f" + echo "$iformat" + fi + alang= + if [[ "$ilang" == "English" ]]; then + alang=en + elif [[ "$ilang" == "German" ]]; then + alang=de + elif [[ "$ilang" == "French" ]]; then + alang=fr + else + echo "$f" + echo "$ilang" + fi + audio+="[${alang}]{${acodec}}" + i+=1 + done +} + +for f in "$@"; do + echo "$f" + get_videoinfo "$f" + #get_audioinfo "$f" +# echo "{$resolution}{$vcodec}$audio" +done -- 2.48.1