slitaz-tools view tinyutils/decode @ rev 1028

tazbox: fix help
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed May 09 12:08:12 2018 +0200 (2018-05-09)
parents 5d80f6fdbdb7
children
line source
1 #!/bin/sh
2 #
3 # Decode is a cmdline tool to decode all kinds of files such as audio or video.
4 # Lets you decode a single file, many files on cmdline or a full directory.
5 #
6 # Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
7 #
8 # Author: Christophe Lincoln <pankso@slitaz.org>
9 #
11 . /lib/libtaz.sh
12 export TEXTDOMAIN='slitaz-tools' #i18n
15 # NOTES:
16 # Do we need a --out=/output/path option ?
17 # Use convert for [.png|.jpg] --> .raw ?
18 # Use separators and give decoded file size ?
19 # Use mencoder for flash video files (and other format) ?
22 #
23 # Functions
24 #
27 # Small help and usage.
29 usage() {
30 cat << EOT
32 $(_n 'Decode audio and video files')
34 $(boldify "$(_ 'Usage:')")
35 $(basename $0) [$(_n 'option')] [$(_n 'file')|$(_n 'URL')] ...
37 $(boldify "$(_ 'Examples:')")
38 $(basename $0) audio.mp3 audio.ogg
39 $(basename $0) $(_n '/path/to/files/*')
40 $(basename $0) http://www.myurl/$(_n 'file').avi
42 EOT
43 }
46 # Check if a tool is installed. Don't force users and auto install package
47 # Decode is a cmdline line tool, let's have auto install option in GUI.
49 check_tool() {
50 dec=$1
51 name="$(basename "$file")"
52 if [ ! -x /usr/bin/$1 ]; then
53 _ 'Missing decoder: %s' "$dec"
54 _ 'Skipping file: %s' "$name"
55 continue
56 else
57 _ 'Decoding: %s' "$name"
58 newline
59 fi
60 }
63 # Decode a file.
65 decoder() {
66 newline; separator; newline
67 if [ ! -f "$file" ]; then
68 _ 'No file: %s' "$file"
69 continue
70 fi
71 ext=$(echo ${file##*.} | tr '[A-Z]' '[a-z]')
72 case $ext in
73 mp3)
74 check_tool "mpg123"
75 mpg123 --rate 44100 --stereo --buffer 3072 --resync \
76 -w "${file%.*}.wav" "$file" ;;
77 ogg)
78 check_tool "oggdec"
79 oggdec "$file" ;;
80 avi|wmv|mov|flv)
81 check_tool "ffmpeg"
82 # *.flv --> mencoder file.flv -ovc lavc -oac mp3lame -o file.avi
83 ffmpeg -y -i "$file" "${file%.*}.mpg"
84 du -sh "${file%.*}.mpg" ;;
85 wav|mpg|--*)
86 # Skip decoded files and --options.
87 name="$(basename "$file")"
88 _ 'Skipping file: %s' "$name"
89 continue ;;
90 *) _ 'Unsupported file: %s' "$file" ;;
91 esac
92 }
95 #
96 # Commands
97 #
99 case "$1" in
100 -h|--help|"") usage ;;
101 *)
102 for file in "$@"; do
103 debug "$file"
104 case "$file" in
105 http://*)
106 busybox wget "$file"
107 file="$(basename "$file")"
108 decoder && rm "$file" ;;
109 *.*)
110 decoder ;;
111 esac
112 done
113 newline ;;
114 esac
116 exit 0