]> git.rmz.io Git - dotfiles.git/blob - bin/rename-video.sh
qutebrowser: add stm new issue quickmark
[dotfiles.git] / bin / rename-video.sh
1 #!/bin/bash
2
3 get_videoinfo() {
4 local -a mediainfo
5 IFS=,
6 mediainfo=( $(mediainfo --Output='Video;%Width%,%Height%,%ScanType%,%Format%,%Codec%' "$1") )
7 #TODO ffprobe returns better parseable output but doesn't give info on scan_type (use it for audio only?)
8 # IFS='|'
9 # mediainfo=( $(ffprobe -select_streams v -show_entries stream=codec_name,width,height -of compact=nk=1 -i file:"$1" 2> /dev/null) )
10 local width=${mediainfo[0]}
11 local height=${mediainfo[1]}
12 local scan=${mediainfo[2]}
13 local format=${mediainfo[3]}
14 local codecid=${mediainfo[4]}
15
16 # same tests xbmc does:
17 # https://github.com/xbmc/xbmc/blob/master/xbmc/utils/StreamDetails.cpp#L514
18 if (( $width <= 720 && $height <= 480 )); then
19 resolution=480
20 elif (( $width <= 768 && $height <= 576)); then
21 resolution=576
22 elif (( $width <= 960 && $height <= 544)); then
23 resolution=540
24 elif (( $width <= 1280 && $height <= 720)); then
25 resolution=720
26 else
27 resolution=1080
28 fi
29
30 if [[ "$scan" == "Progressive" ]]; then
31 resolution+="p"
32 elif [[ "$scan" == "Interlaced" ]]; then
33 resolution+="i"
34 fi
35
36 vcodec=
37 if [[ "$format" == "AVC" ]]; then
38 vcodec=h264
39 elif [[ "$format" == "VC-1" && "$codecid" == "WVC1" ]]; then
40 vcodec=wvc1
41 elif [[ "$codecid" == "XVID" ]]; then
42 vcodec=xvid
43 elif [[ "$codecid" == "DIV3" || "$codecid" == "DX50" || "$codecid" == "DIVX" ]]; then
44 vcodec=divx
45 elif [[ "$codecid" == "V_MPEG2" ]]; then
46 vcodec=mpeg2
47 elif [[ "$codecid" == "MP42" ]]; then
48 vcodec=mp42
49 else
50 echo $f
51 echo $format $codecid
52 fi
53 }
54
55 #TODO
56 get_audioinfo() {
57 local -a mediainfo
58 IFS=,
59 mediainfo=( $(mediainfo --Output='General;%Audio_Format_List%,%Audio_Language_List%,%AudioCount%' "$1") )
60 IFS=' / '
61 local format=( ${mediainfo[0]} )
62 local lang=( ${mediainfo[1]} )
63 local cnt=${mediainfo[2]}
64
65 audio=
66 local -i i=0
67 while (( $i < $cnt )) ; do
68 local iformat=${format[$i]}
69 local ilang=${lang[$i]}
70
71 acodec=
72 if [[ "$iformat" == "DTS" ]]; then
73 acodec=dts
74 elif [[ "$iformat" == "AC-3" ]]; then
75 acodec=ac3
76 elif [[ "$iformat" == "MPEG Audio" ]]; then
77 acodec=mp3
78 else
79 echo "$f"
80 echo "$iformat"
81 fi
82 alang=
83 if [[ "$ilang" == "English" ]]; then
84 alang=en
85 elif [[ "$ilang" == "German" ]]; then
86 alang=de
87 elif [[ "$ilang" == "French" ]]; then
88 alang=fr
89 else
90 echo "$f"
91 echo "$ilang"
92 fi
93 audio+="[${alang}]{${acodec}}"
94 i+=1
95 done
96 }
97
98 for f in "$@"; do
99 echo "$f"
100 get_videoinfo "$f"
101 #get_audioinfo "$f"
102 # echo "{$resolution}{$vcodec}$audio"
103 done