slitaz-tools view tinyutils/decode @ rev 878
tazbox: add icons to the buttons (Yad 0.26 supports custom icons)
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri May 02 20:02:16 2014 +0000 (2014-05-02) |
parents | c79e656b37a5 |
children | 5d80f6fdbdb7 |
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-2014 SliTaz GNU/Linux - BSD License
7 #
8 # Author: Christophe Lincoln <pankso@slitaz.org>
9 #
10 . /lib/libtaz.sh
11 export TEXTDOMAIN='slitaz-tools' #i18n
13 # NOTES:
14 # Do we need a --out=/output/path option ?
15 # Use convert for [.png|.jpg] --> .raw ?
16 # Use separators and give decoded file size ?
17 # Use mencoder for flash video files (and other format) ?
20 #
21 # Functions
22 #
24 # Small help and usage.
25 usage() {
26 cat << EOT
28 $(_n 'Decode audio and video files')
30 $(boldify "$(_ 'Usage:')")
31 $(basename $0) [$(_n 'option')] [$(_n 'file')|$(_n 'URL')] ...
33 $(boldify "$(_ 'Examples:')")
34 $(basename $0) audio.mp3 audio.ogg
35 $(basename $0) $(_n '/path/to/files/*')
36 $(basename $0) http://www.myurl/$(_n 'file').avi
38 EOT
39 }
41 # Check if a tool is installed. Don't force users and auto install package
42 # Decode is a cmdline line tool, let's have auto install option in GUI.
43 check_tool() {
44 dec=$1
45 name="$(basename "$file")"
46 if [ ! -x /usr/bin/$1 ]; then
47 _ 'Missing decoder: $dec'
48 _ 'Skipping file: $name'
49 continue
50 else
51 _ 'Decoding: $name'
52 newline
53 fi
54 }
56 # Decode a file.
57 decoder() {
58 newline; separator; newline
59 if [ ! -f "$file" ]; then
60 _ 'No file: $file'
61 continue
62 fi
63 ext=$(echo ${file##*.} | tr '[A-Z]' '[a-z]')
64 case $ext in
65 mp3)
66 check_tool "mpg123"
67 mpg123 --rate 44100 --stereo --buffer 3072 --resync \
68 -w "${file%.*}.wav" "$file" ;;
69 ogg)
70 check_tool "oggdec"
71 oggdec "$file" ;;
72 avi|wmv|mov|flv)
73 check_tool "ffmpeg"
74 # *.flv --> mencoder file.flv -ovc lavc -oac mp3lame -o file.avi
75 ffmpeg -y -i "$file" "${file%.*}.mpg"
76 du -sh "${file%.*}.mpg" ;;
77 wav|mpg|--*)
78 # Skip decoded files and --options.
79 name="$(basename "$file")"
80 _ 'Skipping file: $name'
81 continue ;;
82 *) _ 'Unsupported file: $file' ;;
83 esac
84 }
86 #
87 # Commands
88 #
90 case "$1" in
91 -h|--help|"") usage ;;
92 *)
93 for file in "$@"; do
94 debug "$file"
95 case "$file" in
96 http://*)
97 busybox wget "$file"
98 file="$(basename "$file")"
99 decoder && rm "$file" ;;
100 *.*)
101 decoder ;;
102 esac
103 done
104 newline ;;
105 esac
107 exit 0