]> git.phdru.name Git - audio-cdr-video.git/commitdiff
Initail import
authorOleg Broytman <phd@phdru.name>
Sun, 1 Dec 2013 17:19:29 +0000 (21:19 +0400)
committerOleg Broytman <phd@phdru.name>
Sun, 1 Dec 2013 17:19:29 +0000 (21:19 +0400)
170 files changed:
audio/.gitignore [new file with mode: 0644]
audio/amixer-max [new file with mode: 0755]
audio/amixer-normal [new file with mode: 0755]
audio/amixer-toggle-mute [new file with mode: 0755]
audio/amixer-toggle-mute2 [new file with mode: 0755]
audio/amixer-volume [new file with mode: 0755]
audio/filetypes.py [new file with mode: 0644]
audio/find-nolist.py [new file with mode: 0755]
audio/fix-list-names.py [new file with mode: 0755]
audio/mjack [new file with mode: 0755]
audio/mk_list.py [new file with mode: 0755]
audio/mk_list_recursive.py [new file with mode: 0755]
audio/mk_list_recursive.sh [new file with mode: 0755]
audio/move-up.py [new file with mode: 0755]
audio/mp3/find-no-v1v2.py [new file with mode: 0755]
audio/mp3/find-no3.py [new file with mode: 0755]
audio/mp3/find-nolist-no3.py [new file with mode: 0755]
audio/mp3/find-v1.py [new file with mode: 0755]
audio/mp3/find-v1v2.py [new file with mode: 0755]
audio/mp3/find-v2.py [new file with mode: 0755]
audio/mp3/id3images.py [new file with mode: 0755]
audio/mp3/id3info.py [new file with mode: 0755]
audio/mp3/id3v1-to-v2.py [new file with mode: 0755]
audio/mp3/id3v2-to-v1.py [new file with mode: 0755]
audio/mp3/lame.sh [new file with mode: 0755]
audio/mp3/list-id3v2-frames.py [new file with mode: 0755]
audio/mp3/name2tag.py [new file with mode: 0755]
audio/mp3/not-mp3s.sh [new file with mode: 0755]
audio/mp3/recode-id3.py [new file with mode: 0755]
audio/mp3/recode-tags-list.sh [new file with mode: 0755]
audio/mp3/recode-tags-recursive.sh [new file with mode: 0755]
audio/mp3/recode-tags.sh [new file with mode: 0755]
audio/mp3/remove-tag.py [new file with mode: 0755]
audio/mp3/tag.py [new file with mode: 0755]
audio/mp3/tag2name.py [new file with mode: 0755]
audio/mp3/upgrade-id3tag.py [new file with mode: 0755]
audio/ogg/playlist2tags.sh [new file with mode: 0755]
audio/ogg/tag.py [new file with mode: 0755]
audio/pa-bt [new file with mode: 0755]
audio/pa-bt-BT3030 [new file with mode: 0755]
audio/pa-bt-Backbeat903 [new file with mode: 0755]
audio/pa-kill [new file with mode: 0755]
audio/pa-mic-off [new file with mode: 0755]
audio/pa-mic-on [new file with mode: 0755]
audio/pa-speaker [new file with mode: 0755]
audio/pa-toggle-mute [new file with mode: 0755]
audio/pa-volume [new file with mode: 0755]
audio/players/action [new file with mode: 0755]
audio/players/audacious-title [new file with mode: 0644]
audio/playlist2name.py [new file with mode: 0755]
audio/playlist2name.sh [new file with mode: 0755]
audio/rename-list.py [new file with mode: 0755]
audio/rename_xx [new file with mode: 0755]
audio/rip [new file with mode: 0755]
audio/shuffle-playlist.py [new file with mode: 0755]
audio/toggle-mute [new file with mode: 0755]
audio/volume [new file with mode: 0755]
cdr-dvdrw-tools/.config [new file with mode: 0644]
cdr-dvdrw-tools/blank [new file with mode: 0755]
cdr-dvdrw-tools/blank+burn [new file with mode: 0755]
cdr-dvdrw-tools/blank+burn+diff [new file with mode: 0755]
cdr-dvdrw-tools/blank+burn+diff-rw [new file with mode: 0755]
cdr-dvdrw-tools/blank+burn-audio [new file with mode: 0755]
cdr-dvdrw-tools/blank+overburn [new file with mode: 0755]
cdr-dvdrw-tools/blank+overburn+diff [new file with mode: 0755]
cdr-dvdrw-tools/blank+overburn+diff-rw [new file with mode: 0755]
cdr-dvdrw-tools/blank-all [new file with mode: 0755]
cdr-dvdrw-tools/blank.sh [new file with mode: 0755]
cdr-dvdrw-tools/burn [new file with mode: 0755]
cdr-dvdrw-tools/burn+diff [new file with mode: 0755]
cdr-dvdrw-tools/burn+diff-rw [new file with mode: 0755]
cdr-dvdrw-tools/burn-audio [new file with mode: 0755]
cdr-dvdrw-tools/burn-multi [new file with mode: 0755]
cdr-dvdrw-tools/burn-test [new file with mode: 0755]
cdr-dvdrw-tools/cdr-complete [new file with mode: 0755]
cdr-dvdrw-tools/cdr-overburn [new file with mode: 0755]
cdr-dvdrw-tools/cdrec-data [new file with mode: 0755]
cdr-dvdrw-tools/cdrkit/dvdrec-data [new file with mode: 0755]
cdr-dvdrw-tools/cdrkit/dvdrw-iso [new file with mode: 0755]
cdr-dvdrw-tools/cdrkit/format-dvd [new file with mode: 0755]
cdr-dvdrw-tools/cdrkit/zero-dvd [new file with mode: 0755]
cdr-dvdrw-tools/cdrw-complete [new file with mode: 0755]
cdr-dvdrw-tools/cdrw-iso [new file with mode: 0755]
cdr-dvdrw-tools/cdrw-overburn [new file with mode: 0755]
cdr-dvdrw-tools/clone-cd [new file with mode: 0755]
cdr-dvdrw-tools/clone-cd-overburn [new file with mode: 0755]
cdr-dvdrw-tools/clone-cd-rw [new file with mode: 0755]
cdr-dvdrw-tools/clone-cd-rw-overburn [new file with mode: 0755]
cdr-dvdrw-tools/clone-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/clone-cdrw-overburn [new file with mode: 0755]
cdr-dvdrw-tools/clone-cdrw-rw [new file with mode: 0755]
cdr-dvdrw-tools/clone-cdrw-rw-overburn [new file with mode: 0755]
cdr-dvdrw-tools/clone-dvd-rw [new file with mode: 0755]
cdr-dvdrw-tools/diff-cd [new file with mode: 0755]
cdr-dvdrw-tools/diff-cdrom [new file with mode: 0755]
cdr-dvdrw-tools/diff-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/diff-image [new file with mode: 0755]
cdr-dvdrw-tools/dvd+rw-tools/dvdrec-data [new file with mode: 0755]
cdr-dvdrw-tools/dvd+rw-tools/dvdrw-iso [new file with mode: 0755]
cdr-dvdrw-tools/dvd+rw-tools/format-dvd [new file with mode: 0755]
cdr-dvdrw-tools/dvd+rw-tools/zero-dvd [new file with mode: 0755]
cdr-dvdrw-tools/dvdr-complete [new file with mode: 0755]
cdr-dvdrw-tools/dvdrec-data [new symlink]
cdr-dvdrw-tools/dvdrw [new file with mode: 0755]
cdr-dvdrw-tools/dvdrw-boot [new file with mode: 0755]
cdr-dvdrw-tools/dvdrw-iso [new symlink]
cdr-dvdrw-tools/format-dvd [new symlink]
cdr-dvdrw-tools/get-cd [new file with mode: 0755]
cdr-dvdrw-tools/get-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/get-cdtext [new file with mode: 0755]
cdr-dvdrw-tools/get-fs [new file with mode: 0755]
cdr-dvdrw-tools/get-iso [new file with mode: 0755]
cdr-dvdrw-tools/get-iso-cd [new file with mode: 0755]
cdr-dvdrw-tools/get-iso-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/get_label [new file with mode: 0755]
cdr-dvdrw-tools/guess_label.py [new file with mode: 0755]
cdr-dvdrw-tools/guess_label.sh [new file with mode: 0755]
cdr-dvdrw-tools/ls-cdrom [new file with mode: 0755]
cdr-dvdrw-tools/ls-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/ls-image [new file with mode: 0755]
cdr-dvdrw-tools/ls-iso [new file with mode: 0755]
cdr-dvdrw-tools/mk-audio [new file with mode: 0755]
cdr-dvdrw-tools/mk-image [new file with mode: 0755]
cdr-dvdrw-tools/mk-image-boot [new file with mode: 0755]
cdr-dvdrw-tools/mk-image-multi [new file with mode: 0755]
cdr-dvdrw-tools/mount-loopback [new file with mode: 0755]
cdr-dvdrw-tools/mp3-to-wavs [new file with mode: 0755]
cdr-dvdrw-tools/overburn [new file with mode: 0755]
cdr-dvdrw-tools/overburn+diff [new file with mode: 0755]
cdr-dvdrw-tools/overburn+diff-rw [new file with mode: 0755]
cdr-dvdrw-tools/overburn-test [new file with mode: 0755]
cdr-dvdrw-tools/scan [new file with mode: 0755]
cdr-dvdrw-tools/search-image.py [new file with mode: 0755]
cdr-dvdrw-tools/test-cdrom [new file with mode: 0755]
cdr-dvdrw-tools/test-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/test-disk [new file with mode: 0755]
cdr-dvdrw-tools/wait-cd [new file with mode: 0755]
cdr-dvdrw-tools/wait-cdrom [new file with mode: 0755]
cdr-dvdrw-tools/wait-cdrw [new file with mode: 0755]
cdr-dvdrw-tools/zero-dvd [new symlink]
readme.txt [new file with mode: 0644]
video/avi_comments.txt [new file with mode: 0644]
video/calc_bitrate [new file with mode: 0755]
video/m_catvideo [new file with mode: 0755]
video/m_cropdetect [new file with mode: 0755]
video/m_encode [new file with mode: 0755]
video/m_encode_comments [new file with mode: 0755]
video/m_encode_comments_a1 [new file with mode: 0755]
video/m_encode_extract_a1 [new file with mode: 0755]
video/m_extract_a1 [new file with mode: 0755]
video/m_extract_a1_comments [new file with mode: 0755]
video/m_fix-avi-index [new file with mode: 0755]
video/m_read-vcd [new file with mode: 0755]
video/m_recode2mp3 [new file with mode: 0755]
video/m_split-avi [new file with mode: 0755]
video/tc-fix-avi-index [new file with mode: 0755]
video/tc_add-comments [new file with mode: 0755]
video/tc_calc_bitrate [new file with mode: 0755]
video/tc_detectclipping [new file with mode: 0755]
video/tc_encode [new file with mode: 0755]
video/tc_encode_comments [new file with mode: 0755]
video/tc_encode_comments_a1 [new file with mode: 0755]
video/tc_encode_extract_a1 [new file with mode: 0755]
video/tc_encode_x264 [new file with mode: 0755]
video/tc_extract_a1 [new file with mode: 0755]
video/tc_extract_a1_comments [new file with mode: 0755]
video/tc_split [new file with mode: 0755]
video/tc_split-avi-size [new file with mode: 0755]
video/tc_split-avi-time [new file with mode: 0755]
video/video [new file with mode: 0644]

diff --git a/audio/.gitignore b/audio/.gitignore
new file mode 100644 (file)
index 0000000..539da74
--- /dev/null
@@ -0,0 +1 @@
+*.py[co]
diff --git a/audio/amixer-max b/audio/amixer-max
new file mode 100755 (executable)
index 0000000..65568cc
--- /dev/null
@@ -0,0 +1,27 @@
+#! /bin/sh
+
+CARD="`cat $HOME/misc/alsa-card`"
+
+echo "
+set Master,0 mute
+set Headphone,0 mute
+set PCM,0 mute
+
+set Master,0 0
+set Headphone,0 0
+set PCM,0 0
+" |
+amixer -c$CARD -s
+
+sleep 1
+
+echo "
+set Master,0 '100%'
+set Headphone,0 '100%'
+set PCM,0 '50%'
+
+set Master,0 unmute
+set Headphone,0 unmute
+set PCM,0 unmute
+" |
+exec amixer -c$CARD -s
diff --git a/audio/amixer-normal b/audio/amixer-normal
new file mode 100755 (executable)
index 0000000..9d20517
--- /dev/null
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+CARD="`cat $HOME/misc/alsa-card`"
+
+echo "
+set Master,0 mute
+set Headphone,0 mute
+set PCM,0 mute
+
+set Master,0 0
+set Headphone,0 0
+set PCM,0 0
+" |
+amixer -c$CARD -s
+
+echo "
+set Master,0 '74%'
+set Headphone,0 '74%'
+set PCM,0 '50%'
+
+set Master,0 unmute
+set Headphone,0 unmute
+set PCM,0 unmute
+" |
+exec amixer -c$CARD -s
diff --git a/audio/amixer-toggle-mute b/audio/amixer-toggle-mute
new file mode 100755 (executable)
index 0000000..feb59f8
--- /dev/null
@@ -0,0 +1,15 @@
+#! /bin/sh
+
+if amixer -c"`cat $HOME/misc/alsa-card`" cget name="Headphone Playback Switch" |
+   grep -Fq ": values=on"
+then
+   echo "
+   set Master,0 mute
+   set Headphone,0 mute
+   set PCM,0 mute" | exec amixer -c"`cat $HOME/misc/alsa-card`" -s
+else
+   echo "
+   set Master,0 unmute
+   set Headphone,0 unmute
+   set PCM,0 unmute" | exec amixer -c"`cat $HOME/misc/alsa-card`" -s
+fi
diff --git a/audio/amixer-toggle-mute2 b/audio/amixer-toggle-mute2
new file mode 100755 (executable)
index 0000000..b461b09
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+cd "$HOME" || exit 1
+
+if [ -f .alsa.save ]; then
+   alsactl restore -f .alsa.save "`cat $HOME/misc/alsa-card`" &&
+   exec rm .alsa.save
+else
+   alsactl store -f .alsa.save "`cat $HOME/misc/alsa-card`" &&
+   echo "
+   set Master,0 0
+   set Headphone,0 0
+   set PCM,0 0" | exec amixer -c"`cat $HOME/misc/alsa-card`" -s
+fi
diff --git a/audio/amixer-volume b/audio/amixer-volume
new file mode 100755 (executable)
index 0000000..8a69c0b
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+if [ "$1" = increase ]; then
+   vol="2%+"
+elif [ "$1" = decrease ]; then
+   vol="2%-"
+elif [ "$1" = INCREASE ]; then
+   vol="10%+"
+elif [ "$1" = DECREASE ]; then
+   vol="10%-"
+else
+   echo "Usage: $0 [increase|decrease|INCREASE|DECREASE]" >&2
+   exit 1
+fi
+
+exec amixer -c`cat $HOME/misc/alsa-card` set PCM,0 "$vol"
diff --git a/audio/filetypes.py b/audio/filetypes.py
new file mode 100644 (file)
index 0000000..43d9090
--- /dev/null
@@ -0,0 +1,71 @@
+
+def is_v1(filename):
+   mp3file = file(filename, 'r')
+   try:
+      mp3file.seek(-128, 2)
+      id3tag = mp3file.read(3)
+   except IOError:
+      id3tag = ''
+   mp3file.close()
+   return id3tag == "TAG"
+
+def is_v2(filename):
+   mp3file = file(filename, 'r')
+   try:
+      id3tag = mp3file.read(3)
+   except IOError:
+      id3tag = ''
+   mp3file.close()
+   return id3tag == "ID3"
+
+def is_mp3(filename):
+   import os
+   pipe = os.popen("file -- '%s'" % filename.replace("'", "'\"'\"'"), 'r')
+   result = pipe.read()
+   code = pipe.close()
+   if code <> None: # error
+      raise IOError, "error %s reading file pipe for file `%s'" % (code, filename)
+
+   result = result[len(filename) + 2:] # + ": "
+   test = "MPEG 1.0 layer 3 audio stream data"
+   return result.startswith(test)
+
+
+def is_wav(filename):
+   wavfile = file(filename, 'r')
+   try:
+      riff_wav = wavfile.read(16)
+   except IOError:
+      riff_wav = ''
+   wavfile.close()
+   return riff_wav[:4] == "RIFF" and riff_wav[8:16] == "WAVEfmt "
+
+
+def is_ogg(filename):
+   oggfile = file(filename, 'r')
+   try:
+      ogg_magic = oggfile.read(4)
+   except IOError:
+      ogg_magic = ''
+   oggfile.close()
+   return ogg_magic == "OggS"
+
+
+def is_flac(filename):
+   flacfile = file(filename, 'r')
+   try:
+      flac_magic = flacfile.read(4)
+   except IOError:
+      flac_magic = ''
+   flacfile.close()
+   return flac_magic == "fLaC"
+
+
+def is_ape(filename):
+   apefile = file(filename, 'r')
+   try:
+      ape_magic = apefile.read(4)
+   except IOError:
+      ape_magic = ''
+   apefile.close()
+   return ape_magic == "MAC "
diff --git a/audio/find-nolist.py b/audio/find-nolist.py
new file mode 100755 (executable)
index 0000000..a0bcc13
--- /dev/null
@@ -0,0 +1,22 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_nolist(arg, dirname, names):
+   if dirname == '.': return
+   for filename in ("play.list", "list.m3u", "playlist.m3u", "playlist.pls",
+         "PlayList.m3u"):
+      if filename in names: return
+   print dirname
+
+
+os.path.walk(start_dir, find_nolist, None)
diff --git a/audio/fix-list-names.py b/audio/fix-list-names.py
new file mode 100755 (executable)
index 0000000..a270639
--- /dev/null
@@ -0,0 +1,36 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def fix_playlist(arg, dirname, names):
+   if dirname == '.': return
+
+   has_mp3 = 0
+   for filename in names:
+      if filename.endswith(".mp3") or filename.endswith(".MP3"):
+         has_mp3 = 1
+         break
+
+   if not has_mp3:
+      return
+
+   for filename in ("play.list", "list.m3u", "playlist.m3u"):
+      if filename in names:
+         if os.path.exists("PlayList.m3u"):
+            sys.exit("ERROR: PlayList.m3u already exists!")
+
+         fullname = "%s/%s" % (dirname, filename)
+         print "Renaming", fullname
+         os.rename(fullname, "%s/PlayList.m3u" % dirname)
+
+
+os.path.walk(start_dir, fix_playlist, None)
diff --git a/audio/mjack b/audio/mjack
new file mode 100755 (executable)
index 0000000..0fc8c1e
--- /dev/null
@@ -0,0 +1,20 @@
+#! /bin/sh
+
+if [ "$1" ]; then
+   device="$1"
+   shift
+else
+   device="/dev/cdrom"
+fi
+
+jack --device "$device" -d "$@" || exit 1
+jdir="`echo jack-*`"
+
+for f in track*.cdda.wav; do
+   newname="`echo $f | sed -e 's/^track//' -e  's/\.cdda\.wav$//'`"
+   mv "$f" "$jdir"/track_"$newname".wav || exit 1
+done
+
+rm "$jdir"/jack.progress || exit 1
+jack --device "$device" --upd-progress "$@" || exit 1
+exec jack --device "$device" -q "$@"
diff --git a/audio/mk_list.py b/audio/mk_list.py
new file mode 100755 (executable)
index 0000000..ec8f20a
--- /dev/null
@@ -0,0 +1,52 @@
+#! /usr/bin/env python
+
+import sys, os
+from filetypes import is_v1, is_v2, is_mp3, is_wav, is_ogg, is_flac, is_ape
+
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+import glob, re
+mp3_file = re.compile("^([^0-9]*)([0-9]+)(.*)$")
+
+
+dir = glob.glob("*")
+if not dir:
+   sys.exit("Dir is empty")
+
+
+new_list = []
+for entry in dir:
+   if not os.path.isfile(entry):
+      continue
+
+   lower = entry.lower()
+   if not is_v1(entry) and not is_v2(entry) and not is_mp3(entry) and \
+         not is_wav(entry) and not is_ogg(entry) and \
+         not is_flac(entry) and not is_ape(entry) and \
+         not lower.endswith(".mp3") and not lower.endswith(".wav") and \
+         not lower.endswith(".ogg") and not lower.endswith(".flac") and \
+         not lower.endswith(".ape"):
+      continue
+
+   match = mp3_file.match(entry)
+   if match:
+      name = match.group(1)
+      number = match.group(2)
+      suffix = match.group(3)
+
+      new_list.append((int(number), locale.strxfrm(name), name, number, suffix))
+   else:
+      number = ''
+      name, suffix = os.path.splitext(entry)
+      new_list.append((number, locale.strxfrm(name), name, number, suffix))
+
+if not new_list:
+   sys.exit()
+
+new_list.sort()
+
+outfile = open("PlayList.m3u", 'w')
+for i, _xname, name, number, suffix in new_list:
+   outfile.write("%s%s%s\n" % (name, number, suffix))
+outfile.close()
diff --git a/audio/mk_list_recursive.py b/audio/mk_list_recursive.py
new file mode 100755 (executable)
index 0000000..441f436
--- /dev/null
@@ -0,0 +1,33 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+prog_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+
+
+def ml_playlist(arg, dirname, names):
+   has_mp3 = 0
+   for filename in names:
+      if filename.endswith(".mp3") or filename.endswith(".MP3"):
+         has_mp3 = 1
+         break
+
+   if not has_mp3:
+      return
+
+   print "Making playlist in", dirname
+   save_dir = os.getcwd()
+   os.chdir(dirname)
+   os.system("%s/mk_list.py" % prog_dir)
+   os.chdir(save_dir)
+
+
+os.path.walk(start_dir, ml_playlist, None)
diff --git a/audio/mk_list_recursive.sh b/audio/mk_list_recursive.sh
new file mode 100755 (executable)
index 0000000..bee4b99
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+PATH=$HOME/lib/audio:$PATH
+umask 022
+
+[ "$1" ] && cd "$1" || exit 1 # or just do it in current directory
+start_dir="`pwd`"
+
+find . -type d -print |
+while read dir; do
+   cd "$dir" || exit 1
+   rm -f PlayList.m3u
+   mk_list.py
+   [ -f PlayList.m3u ] && pwd
+   cd "$start_dir" || exit 1
+done
diff --git a/audio/move-up.py b/audio/move-up.py
new file mode 100755 (executable)
index 0000000..8dc1425
--- /dev/null
@@ -0,0 +1,25 @@
+#! /usr/bin/env python
+
+
+import sys, os
+os.chdir(sys.argv[1])
+
+def report(s):
+   sys.stdout.write("\r%s" % s)
+   sys.stdout.flush()
+
+
+infile = open(sys.argv[2], 'r')
+
+for line in infile.readlines():
+   filename = line[:-1] # chop
+   report(filename)
+   os.rename(filename, "../%s" % filename)
+
+infile.close()
+
+
+filename = sys.argv[2]
+os.rename(filename, "../%s" % filename)
+
+report("%s\r" % (' ' * 72))
diff --git a/audio/mp3/find-no-v1v2.py b/audio/mp3/find-no-v1v2.py
new file mode 100755 (executable)
index 0000000..5dcb5c1
--- /dev/null
@@ -0,0 +1,24 @@
+#! /usr/bin/env python
+
+
+import sys, os
+from filetypes import is_v1, is_v2
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_no_v1v2(arg, dirname, names):
+   if dirname == '.': return
+
+   for filename in names:
+      full_path = os.path.join(dirname, filename)
+      if not is_v1(full_path) and not is_v2(full_path):
+         print filename
+
+
+os.path.walk(start_dir, find_no_v1v2, None)
diff --git a/audio/mp3/find-no3.py b/audio/mp3/find-no3.py
new file mode 100755 (executable)
index 0000000..bf52aa0
--- /dev/null
@@ -0,0 +1,26 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_no3(arg, dirname, names):
+   if dirname == '.': return
+
+   has_mp3 = 0
+   for filename in names:
+      if filename.endswith(".mp3"):
+         has_mp3 = 1
+         break
+   if not has_mp3:
+      print dirname
+
+
+os.path.walk(start_dir, find_no3, None)
diff --git a/audio/mp3/find-nolist-no3.py b/audio/mp3/find-nolist-no3.py
new file mode 100755 (executable)
index 0000000..547554f
--- /dev/null
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_nolist(arg, dirname, names):
+   if dirname == '.': return
+
+   has_mp3 = 0
+   for filename in names:
+      if filename.endswith(".mp3"):
+         has_mp3 = 1
+         break
+
+   if not has_mp3:
+      return
+
+   for filename in ("play.list", "list.m3u", "playlist.m3u", "PlayList.m3u"):
+      if filename in names: return
+
+   print dirname
+
+
+os.path.walk(start_dir, find_nolist, None)
diff --git a/audio/mp3/find-v1.py b/audio/mp3/find-v1.py
new file mode 100755 (executable)
index 0000000..05ee642
--- /dev/null
@@ -0,0 +1,23 @@
+#! /usr/bin/env python
+
+
+import sys, os
+from filetypes import is_v1
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_v1(arg, dirname, names):
+   if dirname == '.': return
+
+   for filename in names:
+      if is_v1(os.path.join(dirname, filename)):
+         print filename
+
+
+os.path.walk(start_dir, find_v1, None)
diff --git a/audio/mp3/find-v1v2.py b/audio/mp3/find-v1v2.py
new file mode 100755 (executable)
index 0000000..dbac59f
--- /dev/null
@@ -0,0 +1,24 @@
+#! /usr/bin/env python
+
+
+import sys, os
+from filetypes import is_v1, is_v2
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_v1v2(arg, dirname, names):
+   if dirname == '.': return
+
+   for filename in names:
+      full_path = os.path.join(dirname, filename)
+      if is_v1(full_path) and is_v2(full_path):
+         print filename
+
+
+os.path.walk(start_dir, find_v1v2, None)
diff --git a/audio/mp3/find-v2.py b/audio/mp3/find-v2.py
new file mode 100755 (executable)
index 0000000..d5322c7
--- /dev/null
@@ -0,0 +1,23 @@
+#! /usr/bin/env python
+
+
+import sys, os
+from filetypes import is_v2
+
+if len(sys.argv) == 1:
+   start_dir = '.'
+elif len(sys.argv) == 2:
+   start_dir = sys.argv[1]
+else:
+   sys.exit("Usage: %s [start_dir]" % sys.argv[0])
+
+
+def find_v1(arg, dirname, names):
+   if dirname == '.': return
+
+   for filename in names:
+      if is_v2(os.path.join(dirname, filename)):
+         print filename
+
+
+os.path.walk(start_dir, find_v1, None)
diff --git a/audio/mp3/id3images.py b/audio/mp3/id3images.py
new file mode 100755 (executable)
index 0000000..6792ee0
--- /dev/null
@@ -0,0 +1,51 @@
+#! /usr/bin/env python
+
+import sys
+args = sys.argv[1:]
+
+import eyeD3
+from eyeD3.tag import Mp3AudioFile
+
+
+def id3tag_recode(value):
+    try:
+        return value.encode(dst_encoding)
+    except UnicodeEncodeError:
+        return value.encode('latin1')
+
+def printFrame(title, frame):
+    if frame:
+        print '%s: %s' % (title, frame)
+
+def printFramesList(title, frames):
+    frames = [frame for frame in frames if frame]
+    if frames:
+        print '%s: %s' % (title, ', '.join(frames))
+
+def printTrack(title, frame):
+    if frame:
+        track, total = frame
+        if total and track:
+            print '%s: %d (of %d)' % (title, track, total)
+        elif track:
+            print '%s: %d' % (title, track)
+        elif total:
+            print '%s: UNKNOWN of %d' % (title, total)
+
+for filename in args:
+    print "File:", filename
+    mp3_file = Mp3AudioFile(filename)
+
+    id3tag = mp3_file.getTag()
+    if not id3tag:
+        sys.exit()
+
+    for version in eyeD3.ID3_V2, eyeD3.ID3_V1:
+        id3tag = eyeD3.Tag()
+        if not id3tag.link(filename, version):
+            continue
+
+        images = id3tag.getImages()
+        if images:
+            for image in images:
+                image.writeFile()
diff --git a/audio/mp3/id3info.py b/audio/mp3/id3info.py
new file mode 100755 (executable)
index 0000000..5332fbd
--- /dev/null
@@ -0,0 +1,99 @@
+#! /usr/bin/env python
+
+import sys
+from getopt import getopt, GetoptError
+
+import eyeD3
+from eyeD3.tag import Mp3AudioFile
+
+
+def usage(msg):
+    pname = sys.argv[0]
+    sys.stderr.write("%s: %s\n" % (pname, msg))
+    sys.stderr.write("Usage: %s file.mp3...\n" % pname)
+    sys.stderr.write("Usage: %s [-t encoding|--to-encoding=encoding] file.mp3...\n" % pname)
+    sys.exit(1)
+
+try:
+    optlist, args = getopt(sys.argv[1:], "t:", ["to-encoding="])
+except GetoptError:
+   usage("invalid option")
+
+
+dst_encoding = None
+
+for _opt, _arg in optlist:
+    if _opt in ('-t', '--to-encoding'):
+        dst_encoding = _arg
+try:
+   del _opt, _arg
+except NameError:
+   pass
+
+if not args:
+   usage("too few arguments")
+
+if not dst_encoding:
+    from m_lib.defenc import default_encoding
+    dst_encoding = default_encoding
+
+
+def id3tag_recode(value):
+    try:
+        return value.encode(dst_encoding)
+    except UnicodeEncodeError:
+        return value.encode('latin1')
+
+def printFrame(title, frame):
+    if frame:
+        print '%s: %s' % (title, frame)
+
+def printFramesList(title, frames):
+    frames = [frame for frame in frames if frame]
+    if frames:
+        print '%s: %s' % (title, ', '.join(frames))
+
+def printTrack(title, frame):
+    if frame:
+        track, total = frame
+        if total and track:
+            print '%s: %d (of %d)' % (title, track, total)
+        elif track:
+            print '%s: %d' % (title, track)
+        elif total:
+            print '%s: UNKNOWN of %d' % (title, total)
+
+for filename in args:
+    print "File:", filename
+    mp3_file = Mp3AudioFile(filename)
+    print "Bitrate:", mp3_file.getBitRateString()
+    print "Duration:", mp3_file.getPlayTimeString(), 's'
+
+    id3tag = mp3_file.getTag()
+    if not id3tag:
+        sys.exit()
+
+    for version in eyeD3.ID3_V2, eyeD3.ID3_V1:
+        id3tag = eyeD3.Tag()
+        if not id3tag.link(filename, version):
+            continue
+
+        print '-----'
+        printFrame("id3tag version", id3tag.getVersionStr())
+        printFrame("Artist", id3tag_recode(id3tag.getArtist()))
+        printFrame("Album", id3tag_recode(id3tag.getAlbum()))
+        printFrame("Title", id3tag_recode(id3tag.getTitle()))
+        dates = id3tag.getDate()
+        if dates:
+            printFramesList("Date", [date.getDate() for date in dates])
+        try:
+            printFrame("Genre", id3tag.getGenre().getName())
+        except: # Unknown id3tag or no id3tag at all
+            pass
+        printTrack("Track num", id3tag.getTrackNum())
+        printFramesList("Disc num", [str(n) for n in id3tag.getDiscNum() if n])
+        printFramesList("Comments", [id3tag_recode(frame.comment) for frame in id3tag.getComments() if frame])
+        printFramesList("Lyrics", [frame.description for frame in id3tag.getLyrics()])
+        if id3tag.getImages():
+            print "Has images"
+        printFramesList("URLs", [frame.url for frame in id3tag.getURLs()])
diff --git a/audio/mp3/id3v1-to-v2.py b/audio/mp3/id3v1-to-v2.py
new file mode 100755 (executable)
index 0000000..022f64c
--- /dev/null
@@ -0,0 +1,15 @@
+#! /usr/bin/env python
+
+import sys
+from os import utime
+from os.path import getmtime
+import eyeD3
+
+for filename in sys.argv[1:]:
+   mtime = getmtime(filename)
+   id3tag = eyeD3.Tag()
+   id3tag.link(filename, eyeD3.ID3_V1)
+
+   id3tag.setVersion(eyeD3.ID3_V2)
+   id3tag.update()
+   utime(filename, (mtime, mtime))
diff --git a/audio/mp3/id3v2-to-v1.py b/audio/mp3/id3v2-to-v1.py
new file mode 100755 (executable)
index 0000000..1a47ed6
--- /dev/null
@@ -0,0 +1,15 @@
+#! /usr/bin/env python
+
+import sys
+from os import utime
+from os.path import getmtime
+import eyeD3
+
+for filename in sys.argv[1:]:
+   mtime = getmtime(filename)
+   id3tag = eyeD3.Tag()
+   id3tag.link(filename, eyeD3.ID3_V2)
+
+   id3tag.setVersion(eyeD3.ID3_V1)
+   id3tag.update()
+   utime(filename, (mtime, mtime))
diff --git a/audio/mp3/lame.sh b/audio/mp3/lame.sh
new file mode 100755 (executable)
index 0000000..b342ce7
--- /dev/null
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+
+if [ "$1" = "" ]; then
+   echo "Usage: $0 1.wav [2.wav...]"
+   exit 1
+fi
+
+for wav in "$@"; do
+   name=`basename "$wav" .wav`
+   lame --vbr-new -V 0 -b 96 -B 160 "$wav" "$name".mp3
+done
diff --git a/audio/mp3/list-id3v2-frames.py b/audio/mp3/list-id3v2-frames.py
new file mode 100755 (executable)
index 0000000..926f5f3
--- /dev/null
@@ -0,0 +1,23 @@
+#! /usr/bin/env python
+
+import sys
+import eyeD3
+from eyeD3.frames import id3EncodingToString
+
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+for file in sys.argv[1:]:
+   print "File:", file
+   tag = eyeD3.Tag()
+   tag.link(file)
+   for frame in tag.frames:
+      print str(frame)
+      if hasattr(frame, "text"):
+         text = frame.text
+      elif hasattr(frame, "comment"):
+         text = frame.comment
+      else:
+         text = ''
+      print text.encode(id3EncodingToString(frame.encoding))
+   print
diff --git a/audio/mp3/name2tag.py b/audio/mp3/name2tag.py
new file mode 100755 (executable)
index 0000000..950721c
--- /dev/null
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+
+import sys
+import eyeD3
+from eyeD3.frames import UTF_8_ENCODING
+
+from os import utime
+from os.path import getmtime, splitext, basename
+
+import re
+mp3_file = re.compile("^([0-9]+ *- *)(.+)$")
+
+filenames = sys.argv[1:]
+for filename in filenames:
+   name = splitext(basename(filename))[0]
+   mtime = getmtime(filename)
+
+   id3tag = eyeD3.Tag()
+   id3tag.link(filename)
+
+   match = mp3_file.match(name)
+   if match:
+      name = match.group(2)
+
+   id3tag.setVersion(eyeD3.ID3_V2)
+   id3tag.setTextEncoding(UTF_8_ENCODING)
+
+   id3tag.setTitle(name)
+   print id3tag.getTitle()
+
+   id3tag.update()
+   utime(filename, (mtime, mtime))
diff --git a/audio/mp3/not-mp3s.sh b/audio/mp3/not-mp3s.sh
new file mode 100755 (executable)
index 0000000..739c17c
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+exec find . -type f \
+   \! -name \*.mp3 \! -name PlayList.m3u \! -name *.jpg \! -name *.txt \
+>file.list
diff --git a/audio/mp3/recode-id3.py b/audio/mp3/recode-id3.py
new file mode 100755 (executable)
index 0000000..a0aebee
--- /dev/null
@@ -0,0 +1,91 @@
+#! /usr/bin/env python
+
+import sys
+from os import utime
+from os.path import getmtime
+from getopt import getopt, GetoptError
+
+import eyeD3
+from eyeD3.frames import id3EncodingToString, \
+    LATIN1_ENCODING, UTF_16_ENCODING, UTF_16BE_ENCODING, UTF_8_ENCODING
+from m_lib.opstring import recode
+
+
+def usage(msg):
+    pname = sys.argv[0]
+    sys.stderr.write("%s: %s\n" % (pname, msg))
+    sys.stderr.write("Usage: %s [-f encoding|--from-encoding=encoding|-t encoding|--to-encoding=encoding] file.mp3...\n" % pname)
+    sys.exit(1)
+
+try:
+    optlist, args = getopt(sys.argv[1:], "f:t:",
+        ["from-encoding=", "to-encoding="]
+    )
+except GetoptError:
+    usage("invalid option")
+
+
+src_encoding = None
+dst_encoding = None
+
+for _opt, _arg in optlist:
+    if _opt in ('-f', '--from-encoding'):
+        src_encoding = _arg
+    elif _opt in ('-t', '--to-encoding'):
+        dst_encoding = _arg
+try:
+    del _opt, _arg
+except NameError:
+    pass
+
+if not args:
+    usage("too few arguments")
+
+if not dst_encoding:
+    from m_lib.defenc import default_encoding
+    dst_encoding = default_encoding
+
+
+def id3tag_set(frame, attr, src_encoding, dst_encoding):
+    value = getattr(frame, attr)
+    if frame.encoding == LATIN1_ENCODING:
+        value = value.encode('latin1').decode(src_encoding).encode(dst_encoding).decode('latin1')
+        setattr(frame, attr, value)
+    elif frame.encoding in (UTF_16_ENCODING, UTF_16BE_ENCODING, UTF_8_ENCODING):
+        #value = value.encode(dst_encoding).decode('latin1')
+        #frame.encoding = LATIN1_ENCODING
+        pass
+    else:
+        raise ValueError('Unknown encoding "%s"' % id3EncodingToString(frame.encoding))
+
+for filename in args:
+    mtime = getmtime(filename)
+    for version in eyeD3.ID3_V2, eyeD3.ID3_V1:
+        id3tag = eyeD3.Tag()
+        if not id3tag.link(filename, version):
+            continue
+
+        if not src_encoding:
+            src_encoding = id3EncodingToString(id3tag.encoding)
+
+        for frame in id3tag.frames:
+            if hasattr(frame, "text"):
+                id3tag_set(frame, "text", src_encoding, dst_encoding)
+            elif hasattr(frame, "comment"):
+                id3tag_set(frame, "comment", src_encoding, dst_encoding)
+
+        title_frame = id3tag.getTitle()
+        if title_frame:
+            try:
+                print title_frame
+            except UnicodeEncodeError:
+                print title_frame.encode('latin1')
+        else:
+            print filename
+
+        if id3tag.getVersion() == eyeD3.ID3_V2_2:
+            version = eyeD3.ID3_DEFAULT_VERSION
+        else:
+            version = eyeD3.ID3_CURRENT_VERSION
+        id3tag.update(version=version)
+    utime(filename, (mtime, mtime))
diff --git a/audio/mp3/recode-tags-list.sh b/audio/mp3/recode-tags-list.sh
new file mode 100755 (executable)
index 0000000..89ae0f1
--- /dev/null
@@ -0,0 +1,34 @@
+#! /bin/sh
+
+
+if [ "$2" = "koi2win" ]; then
+   direction="$2"
+elif [ "$2" = "win2koi" ]; then
+   direction="$2"
+elif [ "$2" = "koi2utf" ]; then
+   direction="$2"
+elif [ "$2" = "koi2utf8" ]; then
+   direction=koi2utf
+elif [ "$2" = "win2utf" ]; then
+   direction="$2"
+elif [ "$2" = "win2utf8" ]; then
+   direction=win2utf
+else
+   echo "Usage: $0 playlist koi2win|win2koi|koi2utf|win2utf"
+   exit 1
+fi
+
+if [ "`wc -c \"$1\" | awk '{print $1}'`" -ge 10000 ]; then
+   echo "The file \`$1' is too big, probably not a playlist but mp3?"
+   exit 2
+fi
+
+PATH=$HOME/lib/audio/mp3:$PATH
+umask 022
+
+recode-tags.sh . $direction || exit 1
+#if [ "$direction" = "koi2win" ]; then
+#   exec towin "$1"
+#elif [ "$direction" = "win2koi" ]; then
+#   exec fromwin "$1"
+#fi
diff --git a/audio/mp3/recode-tags-recursive.sh b/audio/mp3/recode-tags-recursive.sh
new file mode 100755 (executable)
index 0000000..d534b8b
--- /dev/null
@@ -0,0 +1,34 @@
+#! /bin/sh
+
+if [ "$1" = "koi2win" ]; then
+   direction="$1"
+elif [ "$1" = "win2koi" ]; then
+   direction="$1"
+elif [ "$1" = "koi2utf" ]; then
+   direction="$1"
+elif [ "$1" = "koi2utf8" ]; then
+   direction=koi2utf
+elif [ "$1" = "win2utf" ]; then
+   direction="$1"
+elif [ "$1" = "win2utf8" ]; then
+   direction=win2utf
+else
+   echo "Usage: $0 koi2win|win2koi|koi2utf|win2utf"
+   exit 1
+fi
+
+PATH=$HOME/lib/audio/mp3:$PATH
+umask 022
+
+if [ "$2" ]; then
+   cd "$2" || exit 1 # or just do it in current directory
+fi
+start_dir="`pwd`"
+
+find . -name PlayList.m3u -print |
+while read path; do
+   dir="`dirname \"$path\"`"
+   cd "$dir" || exit 1
+   recode-tags-list.sh PlayList.m3u $direction
+   cd "$start_dir" || exit 1
+done
diff --git a/audio/mp3/recode-tags.sh b/audio/mp3/recode-tags.sh
new file mode 100755 (executable)
index 0000000..28c5d8d
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh
+
+
+if [ "$2" = "koi2win" ]; then
+   direction="$2"
+elif [ "$2" = "win2koi" ]; then
+   direction="$2"
+elif [ "$2" = "koi2utf" ]; then
+   direction="$2"
+elif [ "$2" = "koi2utf8" ]; then
+   direction=koi2utf
+elif [ "$2" = "win2utf" ]; then
+   direction="$2"
+elif [ "$2" = "win2utf8" ]; then
+   direction=win2utf
+else
+   echo "Usage: $0 playlist koi2win|win2koi|koi2utf|win2utf"
+   exit 1
+fi
+
+cd "$1" || exit 1
+
+PATH=$HOME/lib/audio/mp3:$PATH
+umask 022
+
+if [ "$direction" = "koi2win" ]; then
+   enc_from=koi8-r
+   enc_to=cp1251
+elif [ "$direction" = "win2koi" ]; then
+   enc_from=cp1251
+   enc_to=koi8-r
+elif [ "$direction" = "koi2utf" ]; then
+   enc_from=koi8-r
+   enc_to=utf-8
+elif [ "$direction" = "win2utf" ]; then
+   enc_from=cp1251
+   enc_to=utf-8
+fi
+
+exec xargs -r -d\\n recode-id3.py -f $enc_from -t $enc_to < PlayList.m3u
diff --git a/audio/mp3/remove-tag.py b/audio/mp3/remove-tag.py
new file mode 100755 (executable)
index 0000000..c326654
--- /dev/null
@@ -0,0 +1,62 @@
+#! /usr/bin/env python
+
+import sys
+
+def usage(msg):
+   sys.stderr.write("remove-tag.py: %s\n" % msg)
+   sys.stderr.write("Usage: remove-tag.py -[12] filename\n")
+   sys.exit(1)
+
+from getopt import getopt, GetoptError
+try:
+   optlist, args = getopt(sys.argv[1:], "12", ["id3v1", "id3v2"]
+   )
+except GetoptError:
+   usage("invalid option")
+
+write_id3v1 = True
+write_id3v2 = True
+
+for _opt, _arg in optlist:
+   if _opt == "-1":
+      write_id3v1 = False
+   elif _opt == "--id3v1":
+      write_id3v1 = False
+   elif _opt == "-2":
+      write_id3v2 = False
+   elif _opt == "--id3v2":
+      write_id3v2 = False
+try:
+   del _opt, _arg
+except NameError:
+   pass
+
+if args:
+   if len(args) > 1:
+      usage("too many arguments")
+
+   filename = args[0]
+
+else:
+   usage("too few arguments")
+
+
+from os import utime
+from os.path import getmtime
+mtime = getmtime(filename)
+
+import eyeD3
+
+versions = []
+if not write_id3v2:
+   versions.append(eyeD3.ID3_V2)
+if not write_id3v1:
+   versions.append(eyeD3.ID3_V1)
+
+for version in versions:
+   id3tag = eyeD3.Tag()
+   id3tag.link(filename, version)
+   id3tag.setVersion(version)
+
+   id3tag.remove()
+utime(filename, (mtime, mtime))
diff --git a/audio/mp3/tag.py b/audio/mp3/tag.py
new file mode 100755 (executable)
index 0000000..569eaec
--- /dev/null
@@ -0,0 +1,104 @@
+#! /usr/bin/env python
+
+import sys
+
+def usage(msg):
+   pname = sys.argv[0]
+   sys.stderr.write("%s: %s\n" % (pname, msg))
+   sys.stderr.write("Usage: %s [-[12][-+]] [-a artist] [-l album] [-g genre] [-n track] [-N total_tracks] [-t title] [-y year] filename\n" % pname)
+   sys.exit(1)
+
+from getopt import getopt, GetoptError
+try:
+   optlist, args = getopt(sys.argv[1:], "1:2:a:g:l:n:N:t:y:",
+      ["id3v1=", "id3v2=", "artist=", "album=", "genre=", "track=", "tracks=",
+         "title=", "year="]
+   )
+except GetoptError:
+   usage("invalid option")
+
+write_id3v1 = True
+write_id3v2 = True
+
+artist = None
+album = None
+genre = None
+track = None
+tracks = None
+title = None
+year = None
+
+for _opt, _arg in optlist:
+   if _opt == "-1":
+      if _arg == '-':
+         write_id3v1 = False
+   elif _opt == "--id3v1":
+      if _arg.lower() in ("no", "off"):
+         write_id3v1 = False
+   elif _opt == "-2":
+      if _arg == "-":
+         write_id3v2 = False
+   elif _opt == "--id3v2":
+      if _arg.lower() in ("no", "off"):
+         write_id3v2 = False
+   elif _opt in ("-a", "--artist"):
+      artist = _arg
+   elif _opt in ("-l", "--album"):
+      album = _arg
+   elif _opt in ("-g", "--genre"):
+      genre = _arg
+   elif _opt in ("-n", "--track"):
+      try:
+         track = int(_arg)
+      except ValueError:
+         track = None
+   elif _opt in ("-N", "--tracks"):
+      try:
+         tracks = int(_arg)
+      except ValueError:
+         tracks = None
+   elif _opt in ("-t", "--title"):
+      title = _arg
+   elif _opt in ("-y", "--year"):
+      year = _arg
+try:
+   del _opt, _arg
+except NameError:
+   pass
+
+if args:
+   if len(args) > 1:
+      usage("too many arguments")
+
+   filename = args[0]
+
+else:
+   usage("too few arguments")
+
+
+from os import utime
+from os.path import getmtime
+mtime = getmtime(filename)
+
+import eyeD3
+
+versions = []
+if write_id3v2:
+   versions.append(eyeD3.ID3_V2)
+if write_id3v1:
+   versions.append(eyeD3.ID3_V1)
+
+for version in versions:
+   id3tag = eyeD3.Tag()
+   id3tag.link(filename, version)
+   id3tag.setVersion(version)
+
+   if album: id3tag.setAlbum(unicode(album, "latin1"))
+   if artist: id3tag.setArtist(unicode(artist, "latin1"))
+   if track or tracks: id3tag.setTrackNum((track, tracks))
+   if title: id3tag.setTitle(unicode(title, "latin1"))
+   if genre: id3tag.setGenre(genre)
+   if year: id3tag.setDate(year)
+
+   id3tag.update()
+utime(filename, (mtime, mtime))
diff --git a/audio/mp3/tag2name.py b/audio/mp3/tag2name.py
new file mode 100755 (executable)
index 0000000..60aed7a
--- /dev/null
@@ -0,0 +1,19 @@
+#! /usr/bin/env python
+
+import sys, os
+import eyeD3
+from eyeD3.frames import TITLE_FID, id3EncodingToString
+from m_lib.defenc import default_encoding
+
+def id3tag_recode(value):
+    try:
+        return value.encode(default_encoding)
+    except UnicodeEncodeError:
+        return value.encode('latin1')
+
+files = sys.argv[1:]
+for i, filename  in enumerate(files):
+    id3tag = eyeD3.Tag()
+    id3tag.link(filename)
+    title = id3tag_recode(id3tag.getTitle())
+    os.rename(filename, '%d - %s.mp3' % (i+1, title))
diff --git a/audio/mp3/upgrade-id3tag.py b/audio/mp3/upgrade-id3tag.py
new file mode 100755 (executable)
index 0000000..b0e3fc0
--- /dev/null
@@ -0,0 +1,25 @@
+#! /usr/bin/env python
+
+import sys
+import eyeD3
+from eyeD3.frames import TITLE_FID, id3EncodingToString
+
+from os import utime
+from os.path import getmtime
+
+for filename in sys.argv[1:]:
+   mtime = getmtime(filename)
+   id3tag = eyeD3.Tag()
+   id3tag.link(filename)
+
+   title_frames = id3tag.frames[TITLE_FID]
+   if title_frames:
+      title_frame = title_frames[0]
+      print title_frame.text.encode(id3EncodingToString(title_frame.encoding))
+   else:
+      print filename
+
+   id3tag.setVersion(eyeD3.ID3_V2)
+
+   id3tag.update()
+   utime(filename, (mtime, mtime))
diff --git a/audio/ogg/playlist2tags.sh b/audio/ogg/playlist2tags.sh
new file mode 100755 (executable)
index 0000000..7c48768
--- /dev/null
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+if [ "$1" = "" ]; then
+   echo "Usage: $0 playlist"
+   exit 1
+fi
+
+PATH=$HOME/lib/audio/ogg:$PATH
+umask 022
+
+playlist="$1"
+shift
+
+i=1
+while read line; do
+   filename="`printf 'track_%02d.ogg' $i`"
+   tag.py -t "$line" -n $i "$@" "$filename" || exit 1
+   newid="`printf '%02d' $i`"
+   mv "$filename" "$newid-$line".ogg || exit 1
+   i="`expr $i + 1`"
+done < "$playlist"
diff --git a/audio/ogg/tag.py b/audio/ogg/tag.py
new file mode 100755 (executable)
index 0000000..f49fbe1
--- /dev/null
@@ -0,0 +1,81 @@
+#! /usr/bin/env python
+
+import sys
+
+def usage(msg):
+   sys.stderr.write("tag.py: %s\n" % msg)
+   sys.stderr.write("Usage: tag.py [-a artist] [-l album] [-g genre] [-n track] [-t title] [-y year] [-c charset] filename\n")
+   sys.exit(1)
+
+from getopt import getopt, GetoptError
+try:
+   optlist, args = getopt(sys.argv[1:], "a:g:l:n:t:y:c:",
+      ["artist=", "album=", "genre=", "track=", "title=", "year=", "charset="]
+   )
+except GetoptError:
+   usage("iinvalid option")
+
+artist = None
+album = None
+genre = None
+track = None
+title = None
+year = None
+charset = "ascii"
+
+for _opt, _arg in optlist:
+   if _opt in ("-a", "--artist"):
+      artist = _arg
+   elif _opt in ("-l", "--album"):
+      album = _arg
+   elif _opt in ("-g", "--genre"):
+      from ID3 import ID3
+      if _arg in ID3.genres:
+         genre = _arg
+      else:
+         raise ValueError, "unknown genre `%s'" % _arg
+   elif _opt in ("-n", "--track"):
+      try:
+         track = int(_arg)
+      except ValueError:
+         track = None
+   elif _opt in ("-t", "--title"):
+      title = _arg
+   elif _opt in ("-y", "--year"):
+      year = _arg
+   elif _opt in ("-c", "--charset"):
+      charset = _arg
+try:
+   del _opt, _arg
+except NameError:
+   pass
+
+if args:
+   if len(args) > 1:
+      usage("too many arguments")
+
+   filename = args[0]
+
+else:
+   usage("too few arguments")
+
+
+from os import utime
+from os.path import getmtime
+mtime = getmtime(filename)
+
+import ogg.vorbis
+vf = ogg.vorbis.VorbisFile(filename)
+
+tag = vf.comment()
+tag.clear()
+
+if album: tag.add_tag('ALBUM', album.decode(charset).encode('utf-8'))
+if artist: tag.add_tag('ARTIST', artist.decode(charset).encode('utf-8'))
+if track: tag.add_tag('TRACKNUMBER', str(track))
+if title: tag.add_tag('TITLE', title.decode(charset).encode('utf-8'))
+if genre: tag.add_tag('GENRE', genre)
+if year: tag.add_tag('DATE', year)
+
+tag.write_to(filename)
+utime(filename, (mtime, mtime))
diff --git a/audio/pa-bt b/audio/pa-bt
new file mode 100755 (executable)
index 0000000..69fb71f
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+"$HOME"/lib/audio/pa-kill
+sleep 1
+pulseaudio -L "module-bluetooth-device address="$1" sink_name=btheadset profile=a2dp" -D &&
+
+echo "\
+set-default-sink btheadset
+set-default-source btheadset.monitor
+set-sink-volume btheadset 45858
+" | pacmd &&
+
+echo 0 > ~/.pulse/mute &&
+echo 45858 > ~/.pulse/volume
diff --git a/audio/pa-bt-BT3030 b/audio/pa-bt-BT3030
new file mode 100755 (executable)
index 0000000..823ed77
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+exec "$HOME"/lib/audio/pa-bt 00:23:78:11:D6:4B
diff --git a/audio/pa-bt-Backbeat903 b/audio/pa-bt-Backbeat903
new file mode 100755 (executable)
index 0000000..2c1915c
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+exec "$HOME"/lib/audio/pa-bt 00:1C:EF:7C:81:D6
diff --git a/audio/pa-kill b/audio/pa-kill
new file mode 100755 (executable)
index 0000000..d9ca529
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+if pulseaudio --check; then
+   exec pulseaudio -k
+fi
diff --git a/audio/pa-mic-off b/audio/pa-mic-off
new file mode 100755 (executable)
index 0000000..4d4ac7e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+     pactl set-source-mute alsa_input.pci-0000_00_1b.0.analog-stereo 1 &&
+exec pactl set-card-profile 0 output:analog-stereo
diff --git a/audio/pa-mic-on b/audio/pa-mic-on
new file mode 100755 (executable)
index 0000000..f4e3f35
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+     pactl set-card-profile 0 output:analog-stereo+input:analog-stereo &&
+exec pactl set-source-mute alsa_input.pci-0000_00_1b.0.analog-stereo 0
diff --git a/audio/pa-speaker b/audio/pa-speaker
new file mode 100755 (executable)
index 0000000..bc8b7b9
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+default_sink=`cat "$HOME"/.pulse/default`
+
+"$HOME"/lib/audio/pa-kill
+sleep 1
+pulseaudio -D &&
+echo "\
+set-default-sink "$default_sink"
+set-default-source "`echo $default_sink | sed s/output/input/`"
+set-sink-mute "$default_sink" 0
+set-sink-volume "$default_sink" 32767
+" | pacmd
diff --git a/audio/pa-toggle-mute b/audio/pa-toggle-mute
new file mode 100755 (executable)
index 0000000..743b953
--- /dev/null
@@ -0,0 +1,18 @@
+#! /usr/bin/env bash
+# From http://crunchbanglinux.org/forums/topic/11392/pulseaudio-volume-control-with-media-keys/
+
+MUTE=`cat ~/.pulse/mute`
+test "$MUTE" = "1"
+RETURN=$?
+if [[ $RETURN -eq 0 ]]
+then
+   "$HOME"/lib/audio/pa-volume unmute
+   echo "0" > ~/.pulse/mute
+   exit
+fi
+if [[ $RETURN -eq 1 ]]
+then
+   "$HOME"/lib/audio/pa-volume mute
+   echo "1" > ~/.pulse/mute
+   exit
+fi
diff --git a/audio/pa-volume b/audio/pa-volume
new file mode 100755 (executable)
index 0000000..8210dd1
--- /dev/null
@@ -0,0 +1,30 @@
+#! /usr/bin/env bash
+# From http://crunchbanglinux.org/forums/topic/11392/pulseaudio-volume-control-with-media-keys/
+
+declare -i CURVOL=`cat ~/.pulse/volume` #Reads in the current volume
+default_sink=`cat ~/.pulse/default`
+
+if [[ $1 == "increase" ]]
+then
+   CURVOL=$(($CURVOL + 1310)) #1310 is 2% of the total volume (65535), you can change this to suit your needs.
+fi
+if [[ $1 == "decrease" ]]
+then
+   CURVOL=$(($CURVOL - 1310))
+fi
+if [[ $1 == "mute" ]]
+then
+   pactl set-sink-mute "$default_sink" 1
+   exit
+fi
+if [[ $1 == "unmute" ]]
+then
+   pactl set-sink-mute "$default_sink" 0
+   exit
+fi
+if [[ $CURVOL -ge 0 && $CURVOL -le 65540 ]] # Check to see if the volume is a valid number (65540 was needed in this case because of how I rounded the increment)
+then
+   pactl set-sink-volume "$default_sink" $CURVOL
+   echo $CURVOL > ~/.pulse/volume # Write the new volume to disk to be read the next time the script is run.
+   exit
+fi
diff --git a/audio/players/action b/audio/players/action
new file mode 100755 (executable)
index 0000000..d8bbd15
--- /dev/null
@@ -0,0 +1,41 @@
+#! /bin/sh
+
+action="$1"
+
+if pgrep smplayer >/dev/null; then
+   if [ "$action" = prev ]; then
+      exec smplayer -send-action play_prev
+   elif [ "$action" = next ]; then
+      exec smplayer -send-action play_next
+   elif [ "$action" = pause ]; then
+      exec smplayer -send-action play_or_pause
+   elif [ "$action" = stop ]; then
+      exec smplayer -send-action stop
+   fi
+
+elif pgrep deadbeef >/dev/null; then
+   if [ "$action" = prev ]; then
+      exec deadbeef --prev
+   elif [ "$action" = next ]; then
+      exec deadbeef --next
+   elif [ "$action" = pause ]; then
+      exec deadbeef --toggle-pause
+   elif [ "$action" = stop ]; then
+      exec deadbeef --stop
+   fi
+
+elif pgrep audacious >/dev/null; then
+   if [ "$action" = prev ]; then
+      exec audacious --rew
+   elif [ "$action" = next ]; then
+      exec audacious --fwd
+   elif [ "$action" = pause ]; then
+      exec audacious --play-pause
+   elif [ "$action" = stop ]; then
+      exec audacious --stop
+   fi
+
+else
+   echo "Cannot find an audioplayer" >&2
+   exit 1
+fi
diff --git a/audio/players/audacious-title b/audio/players/audacious-title
new file mode 100644 (file)
index 0000000..ca8676f
--- /dev/null
@@ -0,0 +1 @@
+${?title:${title} [}${?artist:${artist}}${?album: - ${album}}${?title:]}${(empty)?title: / ${file-name}}
diff --git a/audio/playlist2name.py b/audio/playlist2name.py
new file mode 100755 (executable)
index 0000000..1ec4835
--- /dev/null
@@ -0,0 +1,17 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
+playlist = file(sys.argv[1], 'r')
+
+for filename in playlist:
+   filename = filename.strip()
+   if not os.path.exists(filename):
+      filename_lower = filename.lower()
+      if os.path.exists(filename_lower):
+         print "Fixing", filename
+         os.rename(filename_lower, filename)
diff --git a/audio/playlist2name.sh b/audio/playlist2name.sh
new file mode 100755 (executable)
index 0000000..4ef4182
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+PATH=$HOME/lib/audio:$PATH
+umask 022
+
+if [ "$1" ]; then
+   cd "$1" || exit 1 # or just do it in current directory
+fi
+start_dir="`pwd`"
+
+find . -type d -print |
+while read dir; do
+   cd "$dir" || exit 1
+   [ -f PlayList.m3u ] && playlist2name.py PlayList.m3u
+   cd "$start_dir" || exit 1
+done
diff --git a/audio/rename-list.py b/audio/rename-list.py
new file mode 100755 (executable)
index 0000000..fa8741f
--- /dev/null
@@ -0,0 +1,13 @@
+#! /usr/bin/env python
+
+
+import sys, os
+
+play_list = open(sys.argv[1], 'r')
+rename_list = open(sys.argv[2], 'r')
+
+
+for orig_file in play_list:
+   orig_file = orig_file.strip()
+   new_file = rename_list.readline().strip()
+   os.rename(orig_file, "../" + new_file)
diff --git a/audio/rename_xx b/audio/rename_xx
new file mode 100755 (executable)
index 0000000..1a245c1
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+from="$1"
+to="$2"
+shift 2
+
+for filename in "$@"; do
+   newname="`echo \"$filename\" | sed s/\"$from\"/\"$to\"/g`"
+   [ "$filename" \!= "$newname" ] && mv "$filename" "$newname"
+done
diff --git a/audio/rip b/audio/rip
new file mode 100755 (executable)
index 0000000..a0dc974
--- /dev/null
+++ b/audio/rip
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+if [ "$1" ]; then
+   device="$1"
+   shift
+else
+   device="/dev/cdrom"
+fi
+
+mkdir cdrip && cd cdrip || exit 1
+
+cdparanoia -d "$device" -B &&
+exec $HOME/lib/audio/mjack "$device" "$@"
diff --git a/audio/shuffle-playlist.py b/audio/shuffle-playlist.py
new file mode 100755 (executable)
index 0000000..3957b62
--- /dev/null
@@ -0,0 +1,18 @@
+#! /usr/bin/env python
+
+import sys
+import random
+
+infile_name = sys.argv[1]
+outfile_name = sys.argv[2]
+
+infile = open(infile_name, 'rU')
+lines = infile.readlines()
+infile.close()
+
+random.shuffle(lines)
+
+outfile = open(outfile_name, 'w')
+for line in lines:
+    outfile.write(line)
+outfile.close()
diff --git a/audio/toggle-mute b/audio/toggle-mute
new file mode 100755 (executable)
index 0000000..6206772
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+if pulseaudio --check; then
+   exec "$HOME"/lib/audio/pa-toggle-mute
+else
+   exec "$HOME"/lib/audio/amixer-toggle-mute
+fi
diff --git a/audio/volume b/audio/volume
new file mode 100755 (executable)
index 0000000..1a2fa50
--- /dev/null
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+if pulseaudio --check; then
+   if [ "$1" = increase ]; then
+      vol=increase
+   elif [ "$1" = decrease ]; then
+      vol=decrease
+   elif [ "$1" = INCREASE ]; then
+      vol=increase
+      "$HOME"/lib/audio/pa-volume "$vol"
+   elif [ "$1" = DECREASE ]; then
+      vol=decrease
+      "$HOME"/lib/audio/pa-volume "$vol"
+   else
+      echo "Usage: $0 [increase|decrease|INCREASE|DECREASE]" >&2
+      exit 1
+   fi
+   exec "$HOME"/lib/audio/pa-volume "$vol"
+else
+   exec "$HOME"/lib/audio/amixer-volume "$@"
+fi
diff --git a/cdr-dvdrw-tools/.config b/cdr-dvdrw-tools/.config
new file mode 100644 (file)
index 0000000..58764bb
--- /dev/null
@@ -0,0 +1,43 @@
+if echo "$PATH" | grep -vq "phd/lib/cdr-dvdrw-tools"; then
+   PATH="$HOME/lib/cdr-dvdrw-tools:$PATH"
+fi
+
+cd_image_iso="$HOME/tmp/cd-image.iso"
+source_dir="$HOME/tmp/cdrw"
+work_dir="$HOME/tmp/cdrom"
+
+dev_cdrom=/dev/cdrom
+dev_cdrw=/dev/cdrw
+dev_scsi=/dev/hda
+dev_sg=/dev/hda
+
+fs_cdrom=/media/cdrom0
+fs_cdrw=/media/cdrom0
+fs_mnt=/mnt
+
+eject_cdrom=cdrom
+eject_cdrw=cdrw
+
+cdrw_speed=24
+dvdrw_speed=4
+
+if [ "$CD_IMAGE_ISO" ]; then
+   cd_image_iso="$CD_IMAGE_ISO"
+fi
+
+if [ "$CD_SOURCE_DIR" ]; then
+   source_dir="$CD_SOURCE_DIR"
+fi
+
+if [ "$CD_WORK_DIR" ]; then
+   work_dir="$CD_WORK_DIR"
+fi
+
+if [ "$CDR_SPEED" ]; then
+   cdrw_speed="$CDR_SPEED"
+fi
+
+die() {
+   echo "$@"
+   exit 1
+}
diff --git a/cdr-dvdrw-tools/blank b/cdr-dvdrw-tools/blank
new file mode 100755 (executable)
index 0000000..a6b9e4e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec blank.sh fast -eject
diff --git a/cdr-dvdrw-tools/blank+burn b/cdr-dvdrw-tools/blank+burn
new file mode 100755 (executable)
index 0000000..489bca9
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+. .config
+blank.sh &&
+exec cdrec-data -tao gracetime=0 -eject
diff --git a/cdr-dvdrw-tools/blank+burn+diff b/cdr-dvdrw-tools/blank+burn+diff
new file mode 100755 (executable)
index 0000000..f595c40
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+. .config
+
+blank.sh && cdrec-data -tao gracetime=0 &&
+eject "$eject_cdrw" && wait-cdrom &&
+exec diff-cdrom
diff --git a/cdr-dvdrw-tools/blank+burn+diff-rw b/cdr-dvdrw-tools/blank+burn+diff-rw
new file mode 100755 (executable)
index 0000000..ac73d2b
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+. .config
+
+blank.sh &&
+cdrec-data -tao gracetime=0 &&
+exec diff-cdrw
diff --git a/cdr-dvdrw-tools/blank+burn-audio b/cdr-dvdrw-tools/blank+burn-audio
new file mode 100755 (executable)
index 0000000..f6f564b
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 mp3list"
+   exit 1
+fi
+
+. .config
+
+exec burn-audio "$1" blank
diff --git a/cdr-dvdrw-tools/blank+overburn b/cdr-dvdrw-tools/blank+overburn
new file mode 100755 (executable)
index 0000000..6a6f912
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+. .config
+blank.sh &&
+exec overburn
diff --git a/cdr-dvdrw-tools/blank+overburn+diff b/cdr-dvdrw-tools/blank+overburn+diff
new file mode 100755 (executable)
index 0000000..675d4c8
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+. .config
+
+blank.sh && cdrec-data gracetime=0 -overburn -dao &&
+eject "$eject_cdrw" && wait-cdrom &&
+exec diff-cdrom
diff --git a/cdr-dvdrw-tools/blank+overburn+diff-rw b/cdr-dvdrw-tools/blank+overburn+diff-rw
new file mode 100755 (executable)
index 0000000..f4190b3
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+. .config
+
+blank.sh &&
+cdrec-data gracetime=0 -overburn -dao &&
+exec diff-cdrw
diff --git a/cdr-dvdrw-tools/blank-all b/cdr-dvdrw-tools/blank-all
new file mode 100755 (executable)
index 0000000..070e3ee
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec blank.sh all -eject
diff --git a/cdr-dvdrw-tools/blank.sh b/cdr-dvdrw-tools/blank.sh
new file mode 100755 (executable)
index 0000000..3ebc2ed
--- /dev/null
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   type=fast
+else
+   type="$1"
+   shift
+fi
+
+. .config
+exec wodim -v speed="$cdrw_speed" "$@" blank="$type" dev="$dev_scsi"
diff --git a/cdr-dvdrw-tools/burn b/cdr-dvdrw-tools/burn
new file mode 100755 (executable)
index 0000000..305fa0e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec cdrec-data -tao -eject
diff --git a/cdr-dvdrw-tools/burn+diff b/cdr-dvdrw-tools/burn+diff
new file mode 100755 (executable)
index 0000000..18473a7
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+. .config
+
+cdrec-data -tao gracetime=8 &&
+eject "$eject_cdrw" && wait-cdrom &&
+exec diff-cdrom
diff --git a/cdr-dvdrw-tools/burn+diff-rw b/cdr-dvdrw-tools/burn+diff-rw
new file mode 100755 (executable)
index 0000000..674b5d5
--- /dev/null
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+. .config
+
+cdrec-data -tao gracetime=8 &&
+exec diff-cdrw
diff --git a/cdr-dvdrw-tools/burn-audio b/cdr-dvdrw-tools/burn-audio
new file mode 100755 (executable)
index 0000000..6a2fd40
--- /dev/null
@@ -0,0 +1,23 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 track_list [blank]"
+   exit 1
+fi
+
+track_list="$1"
+
+
+if [ -z "$2" ]; then
+   blank=""
+elif [ "$2" = "blank" ]; then
+   blank="blank=fast"
+else
+   blank="blank=$2"
+fi
+
+
+. .config
+
+eval do-list.py "$track_list" wodim -v speed="$cdrw_speed" -eject $blank dev="$dev_scsi" -pad -dao -audio &&
+exec do-list.py "$track_list" rm "$track_list"
diff --git a/cdr-dvdrw-tools/burn-multi b/cdr-dvdrw-tools/burn-multi
new file mode 100755 (executable)
index 0000000..0ca05d9
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wodim -v speed="$cdrw_speed" dev="$dev_scsi" -tao -multi -data "$cd_image_iso"
diff --git a/cdr-dvdrw-tools/burn-test b/cdr-dvdrw-tools/burn-test
new file mode 100755 (executable)
index 0000000..bb7d62c
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec cdrec-data -dummy -tao -eject
diff --git a/cdr-dvdrw-tools/cdr-complete b/cdr-dvdrw-tools/cdr-complete
new file mode 100755 (executable)
index 0000000..e09a23f
--- /dev/null
@@ -0,0 +1,68 @@
+#! /bin/sh
+
+. .config
+
+label=""
+prog=burn+diff
+setattrs=NO
+
+COPY=NO
+MOVE=NO
+DELETE=NO
+
+while getopts l:p:cmrs opt; do
+   case $opt in
+      l) label="$OPTARG" ;;
+      p) prog="$OPTARG" ;;
+      c) COPY=YES ;;
+      m) MOVE=YES ;;
+      r) DELETE=YES ;;
+      s) setattrs=YES ;;
+   esac
+done
+shift `expr $OPTIND - 1`
+
+source="$1"
+
+if [ "$2" -o \( "$source" -a $COPY = NO -a $MOVE = NO \) -o \( $COPY = YES -a $MOVE = YES \) ]; then
+   echo "Usage: $0 [-l label] [-p program] [-s] [-c|-m] [source]"
+   exit 1
+fi
+
+if [ "$source" ]; then
+   if [ -f "$source" ]; then
+      mkdir -p "$source_dir" || exit 1
+   elif [ -d "$source" ]; then
+      [ "$label" = "" ] && label="`basename \"$source\"`"
+   else
+      echo "$0 can only write files or directories"
+      exit 1
+   fi
+   if [ $COPY = YES ]; then
+      if [ -f "$source" ]; then
+         cp -p "$source" "$source_dir"
+      else
+         cpdir "$source" "$source_dir"
+      fi
+   elif [ $MOVE = YES ]; then
+      mv "$source" "$source_dir"
+   fi || exit 1
+fi
+
+if [ $setattrs = YES ]; then
+   "$HOME"/lib/audio/setattrs.sh "$source_dir"
+fi
+
+if [ -z "$label" ]; then
+   label="`guess_label.py`"
+fi
+
+if [ "$label" ]; then
+   mk-image "$label"
+else
+   mk-image
+fi && ls-image && $prog && rm "$cd_image_iso" || exit 1
+
+if [ $DELETE = YES ]; then
+   exec rm -r "$source_dir"
+fi
diff --git a/cdr-dvdrw-tools/cdr-overburn b/cdr-dvdrw-tools/cdr-overburn
new file mode 100755 (executable)
index 0000000..c54b1e9
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+exec cdr-complete -p overburn+diff "$@"
diff --git a/cdr-dvdrw-tools/cdrec-data b/cdr-dvdrw-tools/cdrec-data
new file mode 100755 (executable)
index 0000000..f6b0dbd
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wodim -v speed="$cdrw_speed" "$@" dev="$dev_scsi" -data "$cd_image_iso"
diff --git a/cdr-dvdrw-tools/cdrkit/dvdrec-data b/cdr-dvdrw-tools/cdrkit/dvdrec-data
new file mode 100755 (executable)
index 0000000..550ca4f
--- /dev/null
@@ -0,0 +1,23 @@
+#! /bin/sh
+
+# "Usage $0 [label]"
+
+. .config
+
+label="$1"
+shift
+
+if [ -z "$label" ]; then
+   label="`guess_label.py`"
+fi
+
+if [ -z "$label" ]; then
+   echo -n "Enter DVD label: "
+   read label
+fi
+
+cdblocks=`genisoimage -print-size -quiet -allow-leading-dots -allow-lowercase -allow-multidot -relaxed-filenames -r -J -input-charset koi8-r -joliet-long -V "$label" "$source_dir"`
+genisoimage -allow-leading-dots -allow-lowercase -allow-multidot \
+   -relaxed-filenames -r -J -input-charset koi8-r -joliet-long \
+   -V "$label" "$source_dir" |
+wodim -speed="$dvdrw_speed" -sao dev="$dev_cdrw" tsize="$cdblocks"s -data -
diff --git a/cdr-dvdrw-tools/cdrkit/dvdrw-iso b/cdr-dvdrw-tools/cdrkit/dvdrw-iso
new file mode 100755 (executable)
index 0000000..5be29f2
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+. .config
+
+if [ -z "$1" ]; then
+   echo "Usage $0 dvd-image.iso"
+   exit 1
+fi
+
+exec wodim -v -speed="$dvdrw_speed" -eject dev="$dev_cdrw" -data "$1"
diff --git a/cdr-dvdrw-tools/cdrkit/format-dvd b/cdr-dvdrw-tools/cdrkit/format-dvd
new file mode 100755 (executable)
index 0000000..b5ead7d
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wodim -v -format speed="$dvdrw_speed" dev="$dev_cdrw"
diff --git a/cdr-dvdrw-tools/cdrkit/zero-dvd b/cdr-dvdrw-tools/cdrkit/zero-dvd
new file mode 100755 (executable)
index 0000000..402440e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wodim -v -speed="$dvdrw_speed" -eject dev="$dev_cdrw" tsize=4400m -data /dev/zero
diff --git a/cdr-dvdrw-tools/cdrw-complete b/cdr-dvdrw-tools/cdrw-complete
new file mode 100755 (executable)
index 0000000..f260deb
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+exec cdr-complete -p blank+burn+diff-rw "$@"
diff --git a/cdr-dvdrw-tools/cdrw-iso b/cdr-dvdrw-tools/cdrw-iso
new file mode 100755 (executable)
index 0000000..5369832
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+. .config
+
+if [ -z "$1" ]; then
+   echo "Usage $0 cd-image.iso"
+   exit 1
+fi
+
+exec wodim -v speed="$cdrw_speed" -eject dev="$dev_scsi" -data "$1"
diff --git a/cdr-dvdrw-tools/cdrw-overburn b/cdr-dvdrw-tools/cdrw-overburn
new file mode 100755 (executable)
index 0000000..b671642
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+exec cdr-complete -p blank+overburn+diff-rw "$@"
diff --git a/cdr-dvdrw-tools/clone-cd b/cdr-dvdrw-tools/clone-cd
new file mode 100755 (executable)
index 0000000..b146af6
--- /dev/null
@@ -0,0 +1,105 @@
+#! /bin/sh
+
+. .config
+
+[ -f "$cd_image_iso" ] && die "$cd_image_iso found, remove it first"
+[ -d "$source_dir" ] && die "$source_dir found, remove it first"
+
+
+while getopts bdl:Ow opt; do
+   case $opt in
+      b ) blank=blank ;;
+      d ) dvd=dvd ;;
+      l ) label="$OPTARG" ;;
+      O ) over=over ;;
+      w ) cdrw=cdrw ;;
+   esac
+done
+shift `expr $OPTIND - 1`
+
+
+if [ -z "$cdrw" ]; then
+   device="$dev_cdrom"
+   fs="$fs_cdrom"
+   eject="$eject_cdrom"
+else
+   device="$dev_cdrw"
+   fs="$fs_cdrw"
+   eject="$eject_cdrw"
+fi
+
+wait-cd "$device"
+
+if [ -z "$label" ]; then
+   label="`get_label \"$device\"`"
+   if [ -z "$label" ]; then
+      echo -n "Enter label: "
+      read label
+   fi
+fi
+
+
+echo "Reading source disk, please wait..."
+
+mount "$fs" || die "Cannot mount the source disk"
+cpdir "$fs" "$work_dir" || die "Cannot copy the source disk"
+eject "$eject"
+
+chmod -R u+w "$work_dir"
+mv "$work_dir" "$source_dir"
+
+
+echo ""
+
+if [ -z "$dvd" ]; then
+   mk-image "$label" || die "Cannot make new disk image"
+   ls-image
+fi
+
+echo ""
+
+
+if [ -z "$dvd" ]; then
+   until wodim dev="$dev_scsi" -atip >/dev/null 2>&1; do
+      echo "Insert blank disk into CD/DVD-Burner and press Enter..."
+      read
+   done
+   if [ "$blank" = blank ]; then
+      blank+"$over"burn
+   else
+      "$over"burn
+   fi || die "Error burning disk"
+
+else
+
+   echo "Insert blank disk into CD/DVD-Burner and press Enter..."
+   read
+   dvdrec-data "$label" || die "Error burning disk"
+fi
+
+echo ""
+
+if [ -z "$cdrw" ]; then
+   echo "Insert newly written disk into CD/DVD-ROM and press Enter..."
+   read
+fi
+
+echo "Comparing, please wait..."
+echo ""
+
+
+mount "$fs" || die "Cannot mount the disk"
+cd "$source_dir"
+
+if diff -r --speed-large-files . "$fs"; then
+   echo "The disk has been successfully copied!"
+   echo ""
+else
+   exit 1
+fi
+
+eject "$eject" &
+if [ -z "$dvd" ]; then
+   rm -r "$cd_image_iso"
+fi
+exec rm -r "$source_dir"
diff --git a/cdr-dvdrw-tools/clone-cd-overburn b/cdr-dvdrw-tools/clone-cd-overburn
new file mode 100755 (executable)
index 0000000..55659c2
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -O
diff --git a/cdr-dvdrw-tools/clone-cd-rw b/cdr-dvdrw-tools/clone-cd-rw
new file mode 100755 (executable)
index 0000000..3bf4204
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -w
diff --git a/cdr-dvdrw-tools/clone-cd-rw-overburn b/cdr-dvdrw-tools/clone-cd-rw-overburn
new file mode 100755 (executable)
index 0000000..73912f9
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -Ow
diff --git a/cdr-dvdrw-tools/clone-cdrw b/cdr-dvdrw-tools/clone-cdrw
new file mode 100755 (executable)
index 0000000..58b43f7
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -b
diff --git a/cdr-dvdrw-tools/clone-cdrw-overburn b/cdr-dvdrw-tools/clone-cdrw-overburn
new file mode 100755 (executable)
index 0000000..bec9246
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -bO
diff --git a/cdr-dvdrw-tools/clone-cdrw-rw b/cdr-dvdrw-tools/clone-cdrw-rw
new file mode 100755 (executable)
index 0000000..89c94b8
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -bw
diff --git a/cdr-dvdrw-tools/clone-cdrw-rw-overburn b/cdr-dvdrw-tools/clone-cdrw-rw-overburn
new file mode 100755 (executable)
index 0000000..1f936c8
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -bOw
diff --git a/cdr-dvdrw-tools/clone-dvd-rw b/cdr-dvdrw-tools/clone-dvd-rw
new file mode 100755 (executable)
index 0000000..4e5bf8f
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec clone-cd -l "$1" -dw
diff --git a/cdr-dvdrw-tools/diff-cd b/cdr-dvdrw-tools/diff-cd
new file mode 100755 (executable)
index 0000000..59bd0dd
--- /dev/null
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+. .config
+
+cd "$source_dir" || die "Cannot chdir to the source directory"
+mount "$1" || die "Cannot mount CD"
+echo Diffing `pwd` and "$1"
+diff -rq --speed-large-files . "$1"
+res=$?
+eject "$2" &
+exit $res
diff --git a/cdr-dvdrw-tools/diff-cdrom b/cdr-dvdrw-tools/diff-cdrom
new file mode 100755 (executable)
index 0000000..445718d
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec diff-cd "$fs_cdrom" "$eject_cdrom"
diff --git a/cdr-dvdrw-tools/diff-cdrw b/cdr-dvdrw-tools/diff-cdrw
new file mode 100755 (executable)
index 0000000..bf8d10c
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec diff-cd "$fs_cdrw" "$eject_cdrw"
diff --git a/cdr-dvdrw-tools/diff-image b/cdr-dvdrw-tools/diff-image
new file mode 100755 (executable)
index 0000000..7af0396
--- /dev/null
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+. .config
+
+mount "$fs_cdrom" || die "Cannot mount CD"
+mount-loopback || die "Cannot mount disk image"
+echo Diffing "$fs_mnt" and "$fs_cdrom"
+diff -rq --speed-large-files "$fs_mnt" "$fs_cdrom"
+res=$?
+sudo umount "$fs_mnt" &
+eject "$eject_cdrom" &
+exit $res
diff --git a/cdr-dvdrw-tools/dvd+rw-tools/dvdrec-data b/cdr-dvdrw-tools/dvd+rw-tools/dvdrec-data
new file mode 100755 (executable)
index 0000000..dc3f541
--- /dev/null
@@ -0,0 +1,22 @@
+#! /bin/sh
+
+# "Usage $0 [label]"
+
+. .config
+
+label="$1"
+shift
+
+if [ -z "$label" ]; then
+   label="`guess_label.py`"
+fi
+
+if [ -z "$label" ]; then
+   echo -n "Enter DVD label: "
+   read label
+fi
+
+exec growisofs -speed="$dvdrw_speed" -Z "$dev_cdrw" \
+   -allow-leading-dots -allow-lowercase -allow-multidot \
+   -relaxed-filenames -r -J -input-charset koi8-r -joliet-long \
+   -V "$label" "$source_dir"
diff --git a/cdr-dvdrw-tools/dvd+rw-tools/dvdrw-iso b/cdr-dvdrw-tools/dvd+rw-tools/dvdrw-iso
new file mode 100755 (executable)
index 0000000..a450804
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+. .config
+
+if [ -z "$1" ]; then
+   echo "Usage $0 dvd-image.iso"
+   exit 1
+fi
+
+exec growisofs -speed="$dvdrw_speed" -Z "$dev_cdrw"="$1"
diff --git a/cdr-dvdrw-tools/dvd+rw-tools/format-dvd b/cdr-dvdrw-tools/dvd+rw-tools/format-dvd
new file mode 100755 (executable)
index 0000000..ed1fb33
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec dvd+rw-format $@ "$dev_cdrw"
diff --git a/cdr-dvdrw-tools/dvd+rw-tools/zero-dvd b/cdr-dvdrw-tools/dvd+rw-tools/zero-dvd
new file mode 100755 (executable)
index 0000000..f5d04c4
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec growisofs -speed="$dvdrw_speed" -Z "$dev_cdrw"=/dev/zero
diff --git a/cdr-dvdrw-tools/dvdr-complete b/cdr-dvdrw-tools/dvdr-complete
new file mode 100755 (executable)
index 0000000..36cbeca
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+. .config
+dvdrec-data "$@" &&
+exec diff-cdrom
diff --git a/cdr-dvdrw-tools/dvdrec-data b/cdr-dvdrw-tools/dvdrec-data
new file mode 120000 (symlink)
index 0000000..7119ad3
--- /dev/null
@@ -0,0 +1 @@
+dvd+rw-tools/dvdrec-data
\ No newline at end of file
diff --git a/cdr-dvdrw-tools/dvdrw b/cdr-dvdrw-tools/dvdrw
new file mode 100755 (executable)
index 0000000..13c37bd
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+. .config
+dvdrec-data "$@" &&
+exec eject "$eject_cdrw"
diff --git a/cdr-dvdrw-tools/dvdrw-boot b/cdr-dvdrw-tools/dvdrw-boot
new file mode 100755 (executable)
index 0000000..ab7eee0
--- /dev/null
@@ -0,0 +1,29 @@
+#! /bin/sh
+
+# "Usage $0 label boot.img..."
+
+if [ -z "$1" ]; then
+   echo -n "Enter CD label: "
+   read label
+else
+   label="$1"
+   shift
+fi
+
+if [ -z "$1" ]; then
+   echo -n "Enter boot image filename: "
+   read boot_img
+else
+   boot_img="$1"
+fi
+shift
+
+alt_boot=''
+if [ "$@" ]; then
+   for b in "$@"; do
+      alt_boot="$alt_boot -eltorito-alt-boot -b $b"
+   done
+fi
+
+. .config
+exec dvdrw "$label" -c _boot -b "$boot_img" $alt_boot
diff --git a/cdr-dvdrw-tools/dvdrw-iso b/cdr-dvdrw-tools/dvdrw-iso
new file mode 120000 (symlink)
index 0000000..958f9f8
--- /dev/null
@@ -0,0 +1 @@
+dvd+rw-tools/dvdrw-iso
\ No newline at end of file
diff --git a/cdr-dvdrw-tools/format-dvd b/cdr-dvdrw-tools/format-dvd
new file mode 120000 (symlink)
index 0000000..1234c78
--- /dev/null
@@ -0,0 +1 @@
+dvd+rw-tools/format-dvd
\ No newline at end of file
diff --git a/cdr-dvdrw-tools/get-cd b/cdr-dvdrw-tools/get-cd
new file mode 100755 (executable)
index 0000000..da9e26d
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec get-fs "$fs_cdrom" "$eject_cdrom"
diff --git a/cdr-dvdrw-tools/get-cdrw b/cdr-dvdrw-tools/get-cdrw
new file mode 100755 (executable)
index 0000000..2f437ab
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec get-fs "$fs_cdrw" "$eject_cdrw"
diff --git a/cdr-dvdrw-tools/get-cdtext b/cdr-dvdrw-tools/get-cdtext
new file mode 100755 (executable)
index 0000000..7f72573
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wodim -vv -toc dev="$dev_sg"
diff --git a/cdr-dvdrw-tools/get-fs b/cdr-dvdrw-tools/get-fs
new file mode 100755 (executable)
index 0000000..abeee2a
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+. .config
+
+mount "$1" || die "Cannot mount the source CD"
+cp -a "$1" "$work_dir" || die "Cannot copy the source CD"
+eject "$2" &
+
+chmod -R u+w "$work_dir"
+exec mv "$work_dir" "$source_dir"
diff --git a/cdr-dvdrw-tools/get-iso b/cdr-dvdrw-tools/get-iso
new file mode 100755 (executable)
index 0000000..9b4004b
--- /dev/null
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+. .config
+
+exec dd if="$1" of="$cd_image_iso" bs=102400
+#exec readom dev="$1" f="$cd_image_iso"
diff --git a/cdr-dvdrw-tools/get-iso-cd b/cdr-dvdrw-tools/get-iso-cd
new file mode 100755 (executable)
index 0000000..037e40e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec get-iso "$dev_cdrom"
diff --git a/cdr-dvdrw-tools/get-iso-cdrw b/cdr-dvdrw-tools/get-iso-cdrw
new file mode 100755 (executable)
index 0000000..04da014
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec get-iso "$dev_cdrw"
diff --git a/cdr-dvdrw-tools/get_label b/cdr-dvdrw-tools/get_label
new file mode 100755 (executable)
index 0000000..0200cf7
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+isoinfo -i "$1" -d | grep "Volume id: " | cut -c 12-
diff --git a/cdr-dvdrw-tools/guess_label.py b/cdr-dvdrw-tools/guess_label.py
new file mode 100755 (executable)
index 0000000..221b01f
--- /dev/null
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+
+import sys, os
+
+helper_pipe = os.popen("guess_label.sh", 'r')
+line = helper_pipe.read()
+helper_pipe.close()
+
+source_dir = line.strip()
+os.chdir(source_dir)
+
+entries = os.listdir('.')
+files = filter(os.path.isfile, entries)
+
+if not files:
+   files = filter(os.path.isdir, entries)
+   if len(files) == 0:
+      sys.exit("Cannot find any file in `%s'" % source_dir)
+   if len(files) > 1:
+      sys.exit("Too many directories in `%s'" % source_dir)
+
+if len(files) > 1:
+   sys.exit("Too many files in `%s'" % source_dir)
+
+filename = os.path.basename(files[0])
+filename = os.path.splitext(filename)[0]
+filename = filename.replace('_', ' ')
+
+if len(filename) <= 32:
+   print filename
+else:
+   sys.exit("The label `%s' is too long: %d (max 32)" % (filename, len(filename)))
diff --git a/cdr-dvdrw-tools/guess_label.sh b/cdr-dvdrw-tools/guess_label.sh
new file mode 100755 (executable)
index 0000000..55ef109
--- /dev/null
@@ -0,0 +1,3 @@
+#! /bin/sh
+. .config
+echo "$source_dir"
diff --git a/cdr-dvdrw-tools/ls-cdrom b/cdr-dvdrw-tools/ls-cdrom
new file mode 100755 (executable)
index 0000000..5f68e7c
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec ls-iso "$dev_cdrom"
diff --git a/cdr-dvdrw-tools/ls-cdrw b/cdr-dvdrw-tools/ls-cdrw
new file mode 100755 (executable)
index 0000000..01c8412
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec ls-iso "$dev_cdrw"
diff --git a/cdr-dvdrw-tools/ls-image b/cdr-dvdrw-tools/ls-image
new file mode 100755 (executable)
index 0000000..9949351
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec ls-iso "$cd_image_iso"
diff --git a/cdr-dvdrw-tools/ls-iso b/cdr-dvdrw-tools/ls-iso
new file mode 100755 (executable)
index 0000000..409897f
--- /dev/null
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+. .config
+
+if [ -z "$PAGER" ]; then
+   PAGER=more
+fi
+
+(    isoinfo -i "$1" -d &&
+exec isoinfo -i "$1" -R -l) | $PAGER
diff --git a/cdr-dvdrw-tools/mk-audio b/cdr-dvdrw-tools/mk-audio
new file mode 100755 (executable)
index 0000000..98c0be9
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 mp3list [blank]"
+   exit 1
+fi
+
+result_list=_result_$$.list
+
+. .config
+
+eval mp3-to-wavs "$1" "$result_list" &&
+eval burn-audio "$result_list" "$2" &&
+exec rm "$1"
diff --git a/cdr-dvdrw-tools/mk-image b/cdr-dvdrw-tools/mk-image
new file mode 100755 (executable)
index 0000000..ae2a6fc
--- /dev/null
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+. .config
+
+[ -f "$cd_image_iso" ] && die "$cd_image_iso found, remove it first"
+[ -d "$source_dir" ] || die "$source_dir not found, create it first"
+
+
+if [ -z "$1" ]; then
+   echo -n "Enter CD label: "
+   read label
+else
+   label="$1"
+fi
+shift
+
+
+exec genisoimage \
+   -allow-leading-dots -allow-lowercase -allow-multidot \
+   -relaxed-filenames -r -J -input-charset koi8-r -joliet-long \
+   -V "$label" -o "$cd_image_iso" "$source_dir"
diff --git a/cdr-dvdrw-tools/mk-image-boot b/cdr-dvdrw-tools/mk-image-boot
new file mode 100755 (executable)
index 0000000..927d2d6
--- /dev/null
@@ -0,0 +1,28 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo -n "Enter CD label: "
+   read label
+else
+   label="$1"
+   shift
+fi
+
+if [ -z "$1" ]; then
+   echo -n "Enter boot image filename: "
+   read boot_img
+else
+   boot_img="$1"
+   shift
+fi
+
+alt_boot=''
+if [ "$@" ]; then
+   for b in $@; do
+      alt_boot="$alt_boot -eltorito-alt-boot -b $b"
+   done
+fi
+
+. .config
+
+exec mk-image "$label" -c _boot -b "$boot_img" $alt_boot
diff --git a/cdr-dvdrw-tools/mk-image-multi b/cdr-dvdrw-tools/mk-image-multi
new file mode 100755 (executable)
index 0000000..c72c59e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec mk-image "$1" -C `wodim dev="$dev_scsi" -msinfo` -M "$dev_cdrw"
diff --git a/cdr-dvdrw-tools/mount-loopback b/cdr-dvdrw-tools/mount-loopback
new file mode 100755 (executable)
index 0000000..dd2a1a5
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec sudo mount -t iso9660 -o ro,loop,nodev,noexec,nosuid,mode=0644 "$cd_image_iso" "$fs_mnt"
diff --git a/cdr-dvdrw-tools/mp3-to-wavs b/cdr-dvdrw-tools/mp3-to-wavs
new file mode 100755 (executable)
index 0000000..52f2e81
--- /dev/null
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 mp3list [result]"
+   exit 1
+fi
+
+mp3list="$1"
+
+if [ -z "$2" ]; then
+   result_list=_result_$$.list
+else
+   result_list="$2"
+fi
+
+cp /dev/null "$result_list"
+
+. .config
+
+while read f; do
+   mp3base="`basename \"$f\" .mp3`"
+   result_file="$source_dir/$mp3base".wav
+   echo "$result_file" >>"$result_list"
+   mpg321 -s "$f" | sox -t raw -r 44100 -s -w -c 2 - "$result_file"
+done < "$mp3list"
diff --git a/cdr-dvdrw-tools/overburn b/cdr-dvdrw-tools/overburn
new file mode 100755 (executable)
index 0000000..129ad09
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec cdrec-data -overburn -dao -eject
diff --git a/cdr-dvdrw-tools/overburn+diff b/cdr-dvdrw-tools/overburn+diff
new file mode 100755 (executable)
index 0000000..58934ed
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+. .config
+
+cdrec-data -overburn -dao &&
+eject "$eject_cdrw" && wait-cdrom &&
+exec diff-cdrom
diff --git a/cdr-dvdrw-tools/overburn+diff-rw b/cdr-dvdrw-tools/overburn+diff-rw
new file mode 100755 (executable)
index 0000000..57d6ff4
--- /dev/null
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+. .config
+
+cdrec-data -overburn -dao &&
+exec diff-cdrw
diff --git a/cdr-dvdrw-tools/overburn-test b/cdr-dvdrw-tools/overburn-test
new file mode 100755 (executable)
index 0000000..c550d1e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec cdrec-data -overburn -dao -dummy -eject
diff --git a/cdr-dvdrw-tools/scan b/cdr-dvdrw-tools/scan
new file mode 100755 (executable)
index 0000000..26872ca
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wodim -scanbus
diff --git a/cdr-dvdrw-tools/search-image.py b/cdr-dvdrw-tools/search-image.py
new file mode 100755 (executable)
index 0000000..fc6551d
--- /dev/null
@@ -0,0 +1,34 @@
+#! /usr/bin/env python
+
+
+import sys, os, mmap
+
+
+filename = sys.argv[1]
+infile = open(filename, 'r')
+mem = mmap.mmap(infile.fileno(), os.path.getsize(filename), access=mmap.ACCESS_READ)
+
+
+search = "TAG"
+start = 0
+
+
+while True:
+   pos = mem.find(search, start)
+   if pos == -1: break
+
+   print pos
+
+   if pos < 3836029:
+      raise ValueError, "pos %d is too low, must be at least 3836029" % pos
+
+   start = pos + 1
+
+   mem.seek(pos - 3836029)
+   header = mem[:5]
+
+   print repr(header)
+
+
+mem.close()
+infile.close()
diff --git a/cdr-dvdrw-tools/test-cdrom b/cdr-dvdrw-tools/test-cdrom
new file mode 100755 (executable)
index 0000000..cb22c2e
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec test-disk "$dev_cdrom"
diff --git a/cdr-dvdrw-tools/test-cdrw b/cdr-dvdrw-tools/test-cdrw
new file mode 100755 (executable)
index 0000000..e91e6ea
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec test-disk "$dev_cdrw"
diff --git a/cdr-dvdrw-tools/test-disk b/cdr-dvdrw-tools/test-disk
new file mode 100755 (executable)
index 0000000..5454cd4
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+dd if="$1" of=/dev/null bs=102400 && echo Ok.
diff --git a/cdr-dvdrw-tools/wait-cd b/cdr-dvdrw-tools/wait-cd
new file mode 100755 (executable)
index 0000000..c4fe27b
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+. .config
+
+until isoinfo -i "$1" -d >/dev/null 2>&1; do
+   echo "Insert CD into CD-ROM and press Enter..."
+   read
+done
diff --git a/cdr-dvdrw-tools/wait-cdrom b/cdr-dvdrw-tools/wait-cdrom
new file mode 100755 (executable)
index 0000000..2693479
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wait-cd "$dev_cdrom"
diff --git a/cdr-dvdrw-tools/wait-cdrw b/cdr-dvdrw-tools/wait-cdrw
new file mode 100755 (executable)
index 0000000..561960b
--- /dev/null
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+. .config
+exec wait-cd "$dev_cdrw"
diff --git a/cdr-dvdrw-tools/zero-dvd b/cdr-dvdrw-tools/zero-dvd
new file mode 120000 (symlink)
index 0000000..acce882
--- /dev/null
@@ -0,0 +1 @@
+dvd+rw-tools/zero-dvd
\ No newline at end of file
diff --git a/readme.txt b/readme.txt
new file mode 100644 (file)
index 0000000..e6a528e
--- /dev/null
@@ -0,0 +1,117 @@
+A number of scripts that I am writing and using to work with CD/DVD
+writers, audio and video files, tv-tuners. Public domain.
+
+
+Subdirectories:
+
+   audio - scripts for manipulating ogg/mp3 files.
+   cdr-dvdrw-tools - scripts for cdrtools and growisofs.
+   video - scripts for manipulating video files.
+
+
+audio
+-----
+
+   Shell and python scripts for manipulating audio (ogg/mp3) files and tags.
+
+setattrs.sh - set normal attributes (files rw-r--r--, directories
+   rwxr-xr-x) after reading from a CD.
+find-nolist.py - find directories without a playlist.
+find-no3.py - find directories without mp3 files.
+find-nolist-no3.py - ... without both.
+mk_list.py - make a playlist for a directory.
+mk_list_recursive.py - make playlists in all subdirectories.
+mk_list_recursive.sh - make playlists in all subdirectories.
+fix-list-names.py - recursively rename all playlists to PlayList.m3u.
+recode_names.py - recode filenames from one encoding to another.
+recode-names-recursive.py - recode directories and filenames recursively.
+recode-id3v2.py - recode ID3 tags from one encoding to another.
+id3v1-to-v2.py - recode ID3 tags from version 1 to version 2.
+tag2name.py - get an ID3 tag and rename the file according to its tag.
+name2tag.py - make an ID3 tag according to the filename.
+recode-tags.sh - recode ID3 tags for listed files.
+recode-tags-list.sh - recode ID3 tags according to playlist and recode the
+   very playlist.
+recode-tags-recursive.sh - recode ID3 tags playlists recursively.
+find-v1.py - find mp3 files with ID3v1 tags.
+find-v2.py - find mp3 files with ID3v2 tags.
+find-v1v2.py - find mp3 files with ID3v1 and ID3v2 tags.
+find-no-v1v2.py - find mp3 files without ID3 tags.
+playlist2name.py, playlist2name.sh - test (using the playlist) if the
+   filename is in wrong case (copied from DOS partition) and fix the
+   filename according to the playlist.
+
+
+cdr-dvdrw-tools
+---------------
+
+   Here is a number of shell and python scripts to guide cdrtools and
+growisofs CD-R[W] and DVD-/+R[W] recording software - scripts for making
+(bootable) ISO images, burning and cloning disks, and testing the results.
+
+.config - config file
+ls-iso, ls-image, ls-cdrom, ls-cdrw - list files in an ISO image, or on CD
+   in the CD-ROM or CD-RW drive.
+get-iso, get-iso-cd, get-iso-cdrw, get-fs, get-cd, get-cdrw - get an ISO
+   image or files from CD.
+test-disk, test-cdrom, test-cdrw - test the CD by copying its ISO image to
+   /dev/null.
+mk-image - make an ISO image.
+mk-image.py - if there is just one source file (usually AVI) - strip
+   extension to make the label.
+mk-image-boot - make bootable ISO image (El Torito).
+scan - scan the bus to find SCSI drives.
+cdrec-data, burn-test, burn, blank.sh, blank, blank-all, blank+burn,
+   overburn-test, overburn, blank+overburn - burn a CD in all modes.
+clone-cd, clone-cdrw, clone-cd-rw, clone-cdrw-rw - clone a CD/DVD into a
+   CD-R, CD-RW, DVD+RW; clone-cd recognizes options:
+      -b - blank disk
+      -d - burn DVD
+      -l label
+      -O - overburn
+      -w - CD-RW
+diff-image, diff-cd, diff-cdrom, diff-cdrw - compare the CD with source
+   directory.
+mp3-to-wavs - convert a list of mp3 files to wav files.
+burn-audio, blank+burn-audio - burn an audio disk.
+mk-audio - make an ISO image for an audio disk.
+mk-image-multi, burn-multi - burn multisession CD.
+burn+diff, blank+burn+diff, overburn+diff, blank+overburn+diff - burn and
+   diff :)
+cdr-complete, cdrw-complete, cdr-800 - complete run: move file(s) into the
+   source directory, normalize files and directories attributes, make an ISO
+   image and list it, burn, diff and cleanup! Options:
+      -l label - CD label; default is to ask
+      -p prog - program to run; default is burn+diff
+      -s - set normal attributes for files and directories.
+dvdrw, dvdrw-iso, blank-dvd, dvdr-complete, dvdrw-boot - scripts for
+   burning DVD-/+R[W] disks.
+
+   All programs recognize the following environment variables (via .config):
+
+CD_IMAGE_ISO=cd_image_iso
+CD_SOURCE_DIR=source_dir
+CD_WORK_DIR=work_dir
+CDR_SPEED=speed
+
+   Thus you may override parameters in .config.
+
+
+video
+-----
+
+Using mplayer/mencoder:
+m_catvideo - concatenate few video files into one.
+m_encode - 1 and 2-pass encoding using different codecs.
+m_fix-avi-index - fix an AVI index.
+m_recode2mp3 - recode an audio stream to mp3, leaving video stream intact.
+m_split-avi - split an AVI file in two.
+
+Using transcode:
+tc_calc_bitrate - estimate bitrate and audio volume scaling.
+tc_detectclipping - detect clipping.
+tc_encode - 1 and 2-pass encoding using different codecs;
+   the input is supposed to be a file or a directory with ripped VOB files.
+tc_extract_a1 - extract an additional audio track and merge it into the output.
+tc_encode_x264 - 1, 2, 3-pass encoding using x264 binary;
+   audio is converted to Ogg Vorbis; the resulting file is Matroska Video (.mkv).
diff --git a/video/avi_comments.txt b/video/avi_comments.txt
new file mode 100644 (file)
index 0000000..b93c7b4
--- /dev/null
@@ -0,0 +1,117 @@
+# INFO
+#
+# The AVI file format supports so-called tomb-stone data. It can be
+# used to write annotations into the AVI file.
+#
+# You can use this file as the argument to the transcode option
+# --avi_comments. When the file is read, empty lines and lines
+# starting with '#' are ignored. 
+# The syntax is: "TAG<space>STRING". The order of the tags does not
+# matter. If a tag has no string following it, it is ignored. That
+# means, you can use this file as input and only fill out the fields
+# you want.
+#
+# A very simple example is:
+#  ----------------snip----------------
+#  INAM My 1st Birthday
+#  ISBJ My first steps!
+#  IART My proud family
+#  ----------------snip----------------
+#
+# Keep in mind that there is no endless space in the AVI header,
+# most likely its around 1000 bytes.
+
+
+# INAM - Stores the title of the subject of the file, such as
+# "Seattle from Above."
+INAM
+
+# ISBJ - Describes the contents of the file, such as
+# "Aerial view of Seattle."
+ISBJ
+
+# Lists the artist of the original subject of the file;
+# for example, "Michaelangelo."
+IART
+
+# Records the copyright information for the file; for example,
+# "Copyright Encyclopedia International 1991." If there are multiple
+# copyrights, separate them by semicolon followed by a space.
+ICOP
+
+# Lists the name of the person or organization that commissioned
+# the subject of the file; for example "Pope Julian II."
+ICMS
+
+# Provides general comments about the file or the subject
+# of the file. If the comment is several sentences long, end each
+# sentence with a period. Do not include new-line characters.
+ICMT Codec: FFmpeg (DivX5)
+
+# Indicates where the subject of the file is archived
+IARL
+
+# Creation date. Specifies the date the subject of the file was created. List
+# dates in year-month-day format, padding one-digit months and days with
+# a zero on the left; for example, "1553-05-03" for May 3, 1553.
+ICRD
+
+# Describes whether an image has been cropped and, if so, how it
+# was cropped; for example, "lower-right corner."
+ICRP
+
+# Specifies the size of the original subject of the file; for
+# example, "8.5 in h, 11 in w."
+IDIM
+
+# Stores dots per inch setting of the digitizer used to
+# produce the file, such as "300."
+IDPI
+
+# Stores the of the engineer who worked on the file. If there are
+# multiple engineers, separate the names by a semicolon and a blank;
+# for example, "Smith, John; Adams, Joe."
+IENG
+
+# Describes the original work, such as "landscape,", "portrait,"
+# "still liefe," etc.
+IGNR
+
+# Provides a list of keywords that refer to the file or subject of the
+# file. Separate multiple keywords with a semicolon and a blank;
+# for example, "Seattle, aerial view; scenery."
+IKEY
+
+# ILGT - Describes the changes in the lightness settings on the digitizer
+# required to produce the file. Note that the format of this information
+# depends on the hardware used.
+ILGT
+
+# IMED - Decribes the original subject of the file, such as
+# "computer image," "drawing," "lithograph," and so on.
+IMED
+
+# IPLT - Specifies the number of colors requested when digitizing
+# an image, such as "256."
+IPLT
+
+# IPRD - Specifies the name of title the file was originally intended
+# for, such as "Encyclopedia of Pacific Northwest Geography."
+IPRD
+
+# ISHP - Identifies the change in sharpness for the digitizer
+# required to produce the file (the format depends on the hardware used).
+ISHP
+
+# ISRC - Identifies the name of the person or organization who
+# suplied the original subject of the file; for example, "Try Research."
+ISRC
+
+# ISRF - Identifies the original form of the material that was digitized,
+# such as "slide," "paper," "map," and so on. This is not necessarily
+# the same as IMED
+ISRF
+
+# ITCH - Identifies the technician who digitized the subject file;
+# for example, "Smith, John."
+ITCH
diff --git a/video/calc_bitrate b/video/calc_bitrate
new file mode 100755 (executable)
index 0000000..e680ac9
--- /dev/null
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+if [ -z "$2" ]; then
+   echo "Usage: $0 width height [fps [bpp]]"
+   exit 1
+fi
+
+width="$1"
+height="$2"
+if [ -z "$3" ]; then
+   fps=25
+else
+   fps="$3"
+fi
+if [ -z "$4" ]; then
+   bpp=0.15
+else
+   bpp="$4"
+fi
+
+echo bitrate = "$width * $height * $fps * $bpp / 1000" = `python -c "print $width * $height * $fps * $bpp / 1000"`
diff --git a/video/m_catvideo b/video/m_catvideo
new file mode 100755 (executable)
index 0000000..eaea31c
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 1.avi..."
+   exit 1
+fi
+
+mencoder -idx -ovc copy -oac copy -o output.avi "$@"
diff --git a/video/m_cropdetect b/video/m_cropdetect
new file mode 100755 (executable)
index 0000000..dfb4b0e
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input.avi..."
+   exit 1
+fi
+
+exec mplayer -vf cropdetect -vo null -nosound "$@"
diff --git a/video/m_encode b/video/m_encode
new file mode 100755 (executable)
index 0000000..5f91d4f
--- /dev/null
@@ -0,0 +1,126 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [aid=n] [acodec=s] [abitrate=n] [ascale=s] [pass=n] $0 [-mencoder_options] input.avi..."
+   exit 1
+fi
+
+if [ -z "$vcodec" ]; then
+   vcodec=lavc
+else
+   vcodec="$vcodec"
+fi
+
+if [ -z "$vbitrate" ]; then
+   vbitrate=1600
+else
+   vbitrate="$vbitrate"
+fi
+
+if [ -n "$vscale" ]; then
+   vscale="-vf scale=$vscale"
+fi
+
+if [ -z "$acodec" ]; then
+   acodec=mp3lame
+else
+   acodec="$acodec"
+fi
+
+if [ -z "$abitrate" ]; then
+   abitrate=256
+else
+   abitrate="$abitrate"
+fi
+
+if [ -n "$ascale" ]; then
+   ascale="-af volume=$ascale"
+fi
+
+if [ "$vcodec" = lavc ]; then
+   vopts="-lavcopts vcodec=mpeg4:vbitrate=$vbitrate:autoaspect"
+
+elif [ "$vcodec" = lavc-hq ]; then
+   vcodec=lavc
+   vopts="-lavcopts vcodec=mpeg4:vbitrate=$vbitrate:autoaspect:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo"
+
+elif [ "$vcodec" = lavc-vhq ]; then
+   vcodec=lavc
+   vopts="-lavcopts vcodec=mpeg4:vbitrate=$vbitrate:autoaspect:mbd=2:trell:v4mv:last_pred=3:dia=2:vmax_b_frames=2:vb_strategy=1:cmp=2:subcmp=2:precmp=2:mv0:cbp:predia=2:preme=2:qns=2"
+
+elif [ "$vcodec" = x264 ]; then
+   vopts="-x264encopts bitrate=$vbitrate"
+
+elif [ "$vcodec" = x264-hq ]; then
+   vcodec=x264
+   vopts="-x264encopts bitrate=$vbitrate:subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b"
+
+elif [ "$vcodec" = x264-vhq ]; then
+   vcodec=x264
+   vopts="-x264encopts bitrate=$vbitrate:subq=6:8x8dct:frameref=5:bframes=3:b_pyramid:weight_b:partitions=all:me=umh"
+
+elif [ "$vcodec" = xvid ]; then
+   vopts="-xvidencopts bitrate=$vbitrate"
+
+elif [ "$vcodec" = xvid-hq ]; then
+   vcodec=xvid
+   vopts="-xvidencopts bitrate=$vbitrate:chroma_opt:vhq=2:bvhq=1:quant_type=mpeg"
+
+elif [ "$vcodec" = xvid-vhq ]; then
+   vcodec=xvid
+   vopts="-xvidencopts bitrate=$vbitrate:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg"
+
+elif [ "$vcodec" = copy ]; then
+   vopts=""
+
+else
+   echo "Unknown video codec $vcodec; known codecs are {lavc,x264,xvid}[-[v]hq], copy" >&2
+   exit 1
+fi
+
+if [ "$acodec" = mp3lame ]; then
+   aopts="-lameopts cbr:br=$abitrate:q=0"
+elif [ "$acodec" = copy ]; then
+   aopts=""
+else
+   echo "Unknown audio codec $acodec; known codecs are mp3lame and copy" >&2
+   exit 1
+fi
+
+if [ "$aid" ]; then
+   aopts="$aopts -aid $aid"
+fi
+
+if [ -z "$pass" ]; then
+   pass=1
+else
+   pass="$pass"
+fi
+
+if [ "$vcodec" = lavc ]; then
+   vpass=vpass
+elif [ "$vcodec" = x264 ]; then
+   vpass=pass
+elif [ "$vcodec" = xvid ]; then
+   vpass=pass
+fi
+
+if [ "$pass" -eq 1 ]; then
+   exec mencoder -ovc "$vcodec" $vopts          $vscale -oac "$acodec" $aopts $ascale -o output.avi "$@"
+
+elif [ "$pass" -eq 2 ]; then
+
+        mencoder -ovc "$vcodec" $vopts:$vpass=1 $vscale -nosound                      -o /dev/null "$@" &&
+   exec mencoder -ovc "$vcodec" $vopts:$vpass=2 $vscale -oac "$acodec" $aopts $ascale -o output.avi "$@"
+
+elif [ "$pass" -eq 3 ]; then
+
+        mencoder -ovc "$vcodec" $vopts:$vpass=1 $vscale -nosound                      -o /dev/null "$@" &&
+        mencoder -ovc "$vcodec" $vopts:$vpass=3 $vscale -nosound                      -o /dev/null "$@" &&
+   exec mencoder -ovc "$vcodec" $vopts:$vpass=3 $vscale -oac "$acodec" $aopts $ascale -o output.avi "$@"
+                                       # pass=3 is not a typo!
+
+else
+   echo "Can only do 1, 2 or 3 passes." >&2
+   exit 1
+fi
diff --git a/video/m_encode_comments b/video/m_encode_comments
new file mode 100755 (executable)
index 0000000..71d7ae4
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 title [mencoder options]" >&2
+   exit 1
+fi
+
+title="$1"
+shift
+
+echo "$title" | iconv -f koi8-r -t utf-8 >avi_name.txt
+echo "Codec FFmpeg (DivX5)" >avi_comment.txt
+
+m_encode -info "name=$(cat avi_name.txt):comment=$(cat avi_comment.txt)" "$@" &&
+mv output.avi "$title".avi &&
+exec rm avi_name.txt avi_comment.txt divx2pass.log
diff --git a/video/m_encode_comments_a1 b/video/m_encode_comments_a1
new file mode 100755 (executable)
index 0000000..2b365fe
--- /dev/null
@@ -0,0 +1,23 @@
+#! /bin/sh
+
+if [ -z "$7" ]; then
+   echo "Usage: $0 title aid1 bitrate1 scale1 aid2 bitrate2 scale2 [menoder options]" >&2
+   exit 1
+fi
+
+title="$1"
+aid1="$2"
+bitrate1="$3"
+scale1="$4"
+aid2="$5"
+bitrate2="$6"
+scale2="$7"
+shift 7
+
+echo "INAM $title" | iconv -f koi8-r -t utf-8 >avi_comments.txt
+echo "ICMT Codec: FFmpeg (DivX5)" >>avi_comments.txt
+
+aid="$aid1" abitrate="$bitrate1" ascale="$scale1" m_encode "$@" &&
+m_extract_a1_comments "$aid2" -lameopts cbr:br=$bitrate2:q=0 -af volume="$scale2" "$@" &&
+mv output2.avi "$title".avi &&
+exec rm avi_comments.txt divx2pass.log a"$aid2".mp3 output.avi
diff --git a/video/m_encode_extract_a1 b/video/m_encode_extract_a1
new file mode 100755 (executable)
index 0000000..868dda6
--- /dev/null
@@ -0,0 +1,16 @@
+#! /bin/sh
+
+if [ -z "$4" ]; then
+   echo "Usage: $0 aid1 aid2 scale1 scale2 [options]"
+   exit 1
+fi
+
+aid1="$1"
+aid2="$2"
+scale1="$3"
+scale2="$4"
+shift 4
+
+aid="$aid1" ascale="$scale1" m_encode "$@" &&
+m_extract_a1 "$aid2" -af volume="$scale2" "$@" &&
+exec rm divx2pass.log output.avi
diff --git a/video/m_extract_a1 b/video/m_extract_a1
new file mode 100755 (executable)
index 0000000..c28080f
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 aid [options]"
+   exit 1
+fi
+
+aid="$1"
+shift
+
+mencoder -ovc copy -oac mp3lame -aid "$aid" -o _tmp.avi "$@" &&
+mplayer -dumpaudio -dumpfile a"$aid".mp3 _tmp.avi && rm _tmp.avi &&
+exec avimerge -o output2.avi -i output.avi -p a"$aid".mp3
diff --git a/video/m_extract_a1_comments b/video/m_extract_a1_comments
new file mode 100755 (executable)
index 0000000..20347b9
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 aid [options]"
+   exit 1
+fi
+
+aid="$1"
+shift
+
+mencoder -ovc copy -oac mp3lame -aid "$aid" -o _tmp.avi "$@" &&
+mplayer -dumpaudio -dumpfile a"$aid".mp3 _tmp.avi && rm _tmp.avi &&
+exec avimerge -o output2.avi -i output.avi -p a"$aid".mp3 -f avi_comments.txt
diff --git a/video/m_fix-avi-index b/video/m_fix-avi-index
new file mode 100755 (executable)
index 0000000..c01e92f
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input.avi"
+   exit 1
+fi
+
+
+# mencoder only copies ONE audiostream from the input;
+# I don't know how to overcome this.
+
+mencoder -idx "$1" -ovc copy -oac copy -o output.avi &&
+exec mv output.avi "$1"
diff --git a/video/m_read-vcd b/video/m_read-vcd
new file mode 100755 (executable)
index 0000000..68925a2
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 track"
+   exit 1
+fi
+
+exec mencoder -ovc copy -oac copy -o track"$1".mpeg vcd://"$1"
diff --git a/video/m_recode2mp3 b/video/m_recode2mp3
new file mode 100755 (executable)
index 0000000..9bf67cb
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input.avi [output.avi]"
+   exit 1
+fi
+
+if [ -z "$2" ]; then
+   output="`basename $1`"
+else
+   output="$2"
+fi
+
+exec mencoder -ovc copy -oac mp3lame "$1" -o "$output"
diff --git a/video/m_split-avi b/video/m_split-avi
new file mode 100755 (executable)
index 0000000..dade423
--- /dev/null
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+if [ -z "$3" ]; then
+   echo "Usage: $0 input.avi time1 time2"
+   exit 1
+fi
+
+mencoder -endpos "$2"  -ovc copy -oac copy -o 1.avi "$1" &&
+exec mencoder -ss "$3" -ovc copy -oac copy -o 2.avi "$1"
diff --git a/video/tc-fix-avi-index b/video/tc-fix-avi-index
new file mode 100755 (executable)
index 0000000..c3b7480
--- /dev/null
@@ -0,0 +1,15 @@
+#! /bin/sh
+
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input.avi"
+   exit 1
+fi
+
+
+# This call of transcode only copies ONE audiostream from the input;
+# if there are more - you need to extract them separately and merge
+# into the output. See tc_extract_a1 for an example.
+
+transcode -i "$1" -P3 -u 50 -o output.avi &&
+exec mv output.avi "$1"
diff --git a/video/tc_add-comments b/video/tc_add-comments
new file mode 100755 (executable)
index 0000000..b6ccf6f
--- /dev/null
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input.avi [title]"
+   exit 1
+fi
+
+input="$1"
+title="$2"
+
+if [ "$title" ]; then
+   echo "INAM $title" | iconv -f koi8-r -t utf-8 >avi_comments.txt
+   echo "ICMT Codec: FFmpeg (DivX5)" >>avi_comments.txt
+fi
+
+avimerge -i "$input" -f avi_comments.txt -o output.avi &&
+exec mv output.avi "$input"
diff --git a/video/tc_calc_bitrate b/video/tc_calc_bitrate
new file mode 100755 (executable)
index 0000000..2faec88
--- /dev/null
@@ -0,0 +1,29 @@
+#! /bin/sh
+
+TRACK=""
+
+while getopts a: opt; do
+   case $opt in
+      a) TRACK="-a $OPTARG" ;;
+   esac
+done
+shift `expr $OPTIND - 1`
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input_dir [type [codec]]"
+   exit 1
+elif [ -z "$2" ]; then
+   type=vob
+   codec=ac3
+elif [ -z "$3" ]; then
+   type="$2"
+   codec=ac3
+elif [ -z "$4" ]; then
+   type="$2"
+   codec="$3"
+else
+   echo "Usage: $0 input_dir type codec"
+   exit 1
+fi
+
+tccat -i "$1" | tcextract -t "$type" -x "$codec" $TRACK | tcdecode -x "$codec" | tcscan -x pcm
diff --git a/video/tc_detectclipping b/video/tc_detectclipping
new file mode 100755 (executable)
index 0000000..0d93e16
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input_dir"
+   exit 1
+fi
+
+exec transcode -i "$1" -y null,null -o /dev/null -J detectclipping
diff --git a/video/tc_encode b/video/tc_encode
new file mode 100755 (executable)
index 0000000..e5e39d5
--- /dev/null
@@ -0,0 +1,86 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [acodec=s] [abitrate=n] [ascale=s] [pass=n] $0 input.avi [-transcode_options]"
+   exit 1
+fi
+
+if [ -z "$vcodec" ]; then
+   vcodec=ffmpeg
+else
+   vcodec="$vcodec"
+fi
+
+if [ -z "$vbitrate" ]; then
+   vbitrate=1600
+else
+   vbitrate="$vbitrate"
+fi
+
+if [ -n "$vscale" ]; then
+   vscale="-Z $vscale"
+fi
+
+if [ -z "$acodec" ]; then
+   acodec=mp3
+else
+   acodec="$acodec"
+fi
+
+if [ -z "$abitrate" ]; then
+   abitrate=256
+else
+   abitrate="$abitrate"
+fi
+
+if [ -n "$ascale" ]; then
+   ascale="-s $ascale"
+fi
+
+if [ "$vcodec" = ffmpeg ]; then
+   tc_vcodec=ffmpeg
+   vopts="-F mpeg4"
+elif [ "$vcodec" = h264 ]; then
+   tc_vcodec=ffmpeg
+   vopts="-F h264"
+elif [ "$vcodec" = xvid ]; then
+   tc_vcodec=xvid
+   vopts=""
+elif [ "$vcodec" = copy ]; then
+   tc_vcodec=copy
+   vopts=""
+else
+   echo "Unknown video codec $vcodec; known codecs are ffmpeg, h264, xvid, copy" >&2
+   exit 1
+fi
+
+if [ "$acodec" = mp3 ]; then
+   aopts=""
+elif [ "$acodec" = copy ]; then
+   aopts=""
+else
+   echo "Unknown audio codec $acodec; known codecs are mp3 and copy" >&2
+   exit 1
+fi
+
+if [ -z "$pass" ]; then
+   pass=1
+else
+   pass="$pass"
+fi
+
+input="$1"
+shift
+
+if [ "$pass" -eq 1 ]; then
+   exec transcode -i "$input" -y $tc_vcodec      $vopts -u 50 -w "$vbitrate" -b "$abitrate"                  $vscale $ascale -o output.avi "$@"
+
+elif [ "$pass" -eq 2 ]; then
+
+        transcode -i "$input" -y $tc_vcodec,null $vopts -u 50 -w "$vbitrate" -b "$abitrate" -R1 -x auto,null $vscale         -o /dev/null  "$@" &&
+   exec transcode -i "$input" -y $tc_vcodec      $vopts -u 50 -w "$vbitrate" -b "$abitrate" -R2              $vscale $ascale -o output.avi "$@"
+
+else
+   echo "Can only do 1 or 2 pass." >&2
+   exit 1
+fi
diff --git a/video/tc_encode_comments b/video/tc_encode_comments
new file mode 100755 (executable)
index 0000000..a147caa
--- /dev/null
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+if [ -z "$2" ]; then
+   echo "Usage: $0 input title [transcode options]" >&2
+   exit 1
+fi
+
+input="$1"
+title="$2"
+shift 2
+
+echo "INAM $title" | iconv -f koi8-r -t utf-8 >avi_comments.txt
+echo "ICMT Codec: FFmpeg (DivX5)" >>avi_comments.txt
+
+tc_encode "$input" --avi_comments=avi_comments.txt "$@" &&
+mv output.avi "$title".avi &&
+exec rm avi_comments.txt divx4.log
diff --git a/video/tc_encode_comments_a1 b/video/tc_encode_comments_a1
new file mode 100755 (executable)
index 0000000..fdb6c10
--- /dev/null
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+if [ -z "$8" ]; then
+   echo "Usage: $0 input title aid1 bitrate1 scale1 aid2 bitrate2 scale2 [transcode options]" >&2
+   exit 1
+fi
+
+input="$1"
+title="$2"
+aid1="$3"
+bitrate1="$4"
+scale1="$5"
+aid2="$6"
+bitrate2="$7"
+scale2="$8"
+shift 8
+
+echo "INAM $title" | iconv -f koi8-r -t utf-8 >avi_comments.txt
+echo "ICMT Codec: FFmpeg (DivX5)" >>avi_comments.txt
+
+abitrate="$bitrate1" ascale="$scale1" tc_encode "$input" -a "$aid1" "$@" &&
+tc_extract_a1_comments "$input" "$aid2" -b "$bitrate2" -s "$scale2" &&
+mv output2.avi "$title".avi &&
+exec rm avi_comments.txt divx4.log a"$aid2".mp3 output.avi
diff --git a/video/tc_encode_extract_a1 b/video/tc_encode_extract_a1
new file mode 100755 (executable)
index 0000000..2d26ac8
--- /dev/null
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+if [ -z "$4" ]; then
+   echo "Usage: $0 input_dir aid scale1 scale2 [options]"
+   exit 1
+fi
+
+input="$1"
+aid="$2"
+scale1="$3"
+scale2="$4"
+shift 4
+
+ascale="$scale1" tc_encode "$input" -a 0 "$@" &&
+tc_extract_a1 "$input" "$aid" -s "$scale2" &&
+rm a1.avi divx4.log output.avi &&
+exec mv output2.avi "$input".avi
diff --git a/video/tc_encode_x264 b/video/tc_encode_x264
new file mode 100755 (executable)
index 0000000..c2c47b4
--- /dev/null
@@ -0,0 +1,78 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: [vcodec=s] [vbitrate=n] [vscale=s] [abitrate=n] [ascale=s] $0 input.avi"
+   exit 1
+fi
+
+if [ -z "$vcodec" ]; then
+   vcodec=x264
+else
+   vcodec="$vcodec"
+fi
+
+if [ -z "$vbitrate" ]; then
+   vbitrate=2200
+else
+   vbitrate="$vbitrate"
+fi
+
+if [ -n "$vscale" ]; then
+   vscale="-Z $vscale"
+fi
+
+if [ -z "$abitrate" ]; then
+   abitrate=320
+else
+   abitrate="$abitrate"
+fi
+
+if [ -n "$ascale" ]; then
+   ascale="-s $ascale"
+fi
+
+if [ "$vcodec" = x264 ]; then
+   vopts="--bitrate=$vbitrate"
+
+elif [ "$vcodec" = x264-hq ]; then
+   vopts="--bitrate=$vbitrate --8x8dct --ref=2 --bframes=3 --b-pyramid --weightb"
+
+elif [ "$vcodec" = x264-vhq ]; then
+   vopts="--bitrate=$vbitrate --8x8dct --ref=5 --bframes=3 --b-pyramid --weightb --partitions=all --me=umh"
+
+else
+   echo "Unknown video codec $vcodec; known codecs are x264[-[v]hq]" >&2
+   exit 1
+fi
+
+if [ -z "$pass" ]; then
+   pass=1
+else
+   pass="$pass"
+fi
+
+# Video
+transcode -i "$1" -x auto,null -y yuv4mpeg,null -k -u 50 $vscale $ascale -o _tmp.y4m || exit 1
+
+if [ "$pass" -eq 1 ]; then
+   x264 $vopts --progress -o _tmp.mkv           _tmp.y4m || exit 1
+
+elif [ "$pass" -eq 2 ]; then
+   x264 $vopts --progress -o /dev/null --pass=1 _tmp.y4m &&
+   x264 $vopts --progress -o _tmp.mkv  --pass=2 _tmp.y4m || exit 1
+
+elif [ "$pass" -eq 3 ]; then
+   x264 $vopts --progress -o /dev/null --pass=1 _tmp.y4m &&
+   x264 $vopts --progress -o /dev/null --pass=3 _tmp.y4m &&
+   x264 $vopts --progress -o _tmp.mkv  --pass=3 _tmp.y4m || exit 1
+                                       # pass=3 is not a typo!
+
+else
+   echo "Can only do 1, 2 or 3 passes." >&2
+   exit 1
+fi
+
+# Audio
+transcode -i "$1" -x null,auto -y null,ogg -g 0x0 -b "$abitrate" -m _tmp.ogg &&
+
+exec mkvmerge -o output.mkv -A _tmp.mkv _tmp.ogg
diff --git a/video/tc_extract_a1 b/video/tc_extract_a1
new file mode 100755 (executable)
index 0000000..669da00
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+if [ -z "$2" ]; then
+   echo "Usage: $0 input_dir aid [options]"
+   exit 1
+fi
+
+input="$1"
+aid="$2"
+shift 2
+
+transcode -i "$input" -x null,auto -g 0x0 -y null,ffmpeg -a "$aid" -m a"$aid".mp3 "$@" &&
+exec avimerge -o output2.avi -i output.avi -p a"$aid".mp3
diff --git a/video/tc_extract_a1_comments b/video/tc_extract_a1_comments
new file mode 100755 (executable)
index 0000000..5028aaa
--- /dev/null
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+if [ -z "$2" ]; then
+   echo "Usage: $0 input_dir aid [options]"
+   exit 1
+fi
+
+input="$1"
+aid="$2"
+shift 2
+
+transcode -i "$input" -x null,auto -g 0x0 -y null,ffmpeg -a "$aid" -m a"$aid".mp3 "$@" &&
+exec avimerge -o output2.avi -i output.avi -p a"$aid".mp3 -f avi_comments.txt
diff --git a/video/tc_split b/video/tc_split
new file mode 100755 (executable)
index 0000000..284abb8
--- /dev/null
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+if [ -z "$2" ]; then
+   echo "Usage: $0 input.avi size [comments]"
+   exit 1
+fi
+
+avisplit -i "$1" -s "$2" || exit 1
+
+if [ "$3" ]; then
+   comments_file="$3"
+fi
+
+i=0
+part="`printf '%04d' $i`"
+while [ -r "$1"-$part ]; do
+   i="`expr $i + 1`"
+   if [ "$comments_file" ]; then
+      avimerge -i "$1"-$part -f $comments_file -o CD$i.avi || exit 1
+      rm "$1"-"$part"
+   else
+      mv "$1"-$part CD$i.avi || exit 1
+   fi
+   part="`printf '%04d' $i`"
+done
diff --git a/video/tc_split-avi-size b/video/tc_split-avi-size
new file mode 100755 (executable)
index 0000000..e1d067f
--- /dev/null
@@ -0,0 +1,14 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 input.avi [size]"
+   exit 1
+fi
+
+if [ -z "$2" ]; then
+   size=700
+else
+   size="$2"
+fi
+
+exec avisplit -i "$1" -s "$size"
diff --git a/video/tc_split-avi-time b/video/tc_split-avi-time
new file mode 100755 (executable)
index 0000000..830075e
--- /dev/null
@@ -0,0 +1,23 @@
+#! /bin/sh
+
+if [ -z "$2" ]; then
+   echo "Usage: $0 input.avi time..."
+   exit 1
+fi
+
+input="$1"
+shift
+
+time=""
+start=0
+
+for t in "$@"; do
+   if [ "$start" = 0 ]; then
+      time="0-$t"
+   else
+      time="$time,$start-$t"
+   fi
+   start="$t"
+done
+
+exec avisplit -i "$input" -t "$time"
diff --git a/video/video b/video/video
new file mode 100644 (file)
index 0000000..09f5101
--- /dev/null
@@ -0,0 +1,7 @@
+if echo "$PATH" | grep -vq "video"; then
+   PATH=$HOME/lib/video:$PATH
+
+else
+
+   echo "video config has already been installed"
+fi