Now go repair them


In response to the previous post:
https://bohemian0wildebeest.wordpress.com/2010/11/08/cat-those-mpegs/
Which also belongs to its master:
https://bohemian0wildebeest.wordpress.com/2010/11/01/case-select-video-conversions/

We simply rebuild its index and everything will be fine from hereon after.
Do you copy?

#!/bin/bash
# Modified: Today by E.l.f.
#
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
#
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
#
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - mpg2aviloop.sh
#
## Source (inspired on): http://ffmpeg.org/ffmpeg-doc.html
## And: http://ubuntuforums.org/showthread.php?t=1037517
## Root check / Sanity check.  You decide.  >-)
## Just in case someone calls this script with sudo -s,
## or has cd'ed into his/her path.
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then
  echo -e $RED"Are you Insane!"
  echo -e $RED"Error: In order to use this script, one must NOT be $USER"
  echo -e $YELLOW"Exiting..."$ENDCOLOR
  exit 0
else
  echo ""
  echo -e $BLUE"    $USER may proceed."  
  echo -e $CYAN"    May peace be with you."$NC
fi
VAR="mpg-files.txt"
echo
echo "    What do you want to do?"
echo
echo "    Repair the indexes of the mp*g files"
echo "    located in the current working directory"
echo "    and then convert them into avi files afterwards?"
echo "    Or"
echo "    Repair them ALL, starting from this folder!?"
echo "    This is aka as a recursive function."
echo
echo -n "Enter either Current or Recursive: "
read answer
case "$answer" in
"Current" | "CURRENT" | "current" | "C" | "c")
## 2>/dev/null? Surpress errors not found messages. SE0
  ls *.mp{e,eg,g,4} 2>/dev/null | sort > $VAR # Collect the files in the current directory
  cat $VAR | while read line; do  # Loop read the filenames from the file
  INPUT=$(echo ${line}) # Grab the nxt new filename
  OUTPUT=${INPUT%.mp*} # Remove shortest match of characters between the '. ' and the '*' at end of string
  OUTPUT+=".avi" # Append new extension
  avidemux --nogui --rebuild-index --autoindex --force-alt-h264 --load "$INPUT" --save "$OUTPUT" --output-format AVI --quit 
  done
  ;;
"Recursive" | "RECURSIVE" | "recursive" | "R" | "r")
  ## For a recursive function; do
  ## Be careful though\!
  ## Collect the files from the top down to the last subfolder (if any\?).
  find -iname '*.mp*g' -exec ls "{}" 2>/dev/null \; | sort > $VAR
  ## This may take a LONG time, depending on the amount of files to process\!
  cat $VAR | while read line; do  # Loop read the filenames from the file
  INPUT=$(echo ${line}) # Grab the nxt new filename
  OUTPUT=${INPUT%.mp*} # Remove shortest match of characters between the '. ' and the '*' at end of string
  OUTPUT+=".avi" # Append new extension
  avidemux --nogui --rebuild-index --autoindex --force-alt-h264 --load "$INPUT" --save "$OUTPUT" --output-format AVI --quit 
  done
  ;;
*)
  echo "   Wrong answer!!!"
  echo "   Please rerun the script again?"
  echo "   Then: Either enter Current or Recursive." 
  echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
  echo "   Usage: Current|Recursive"
  echo
  exit 1
  ;;
esac
## Then...
if [ -f "$VAR" ] ; then \rm $VAR;fi # Remove the text file with the file names
  echo "    I'm sorry to bother you again, but...?"
  echo "    I need you to choose again. "
  echo "    Either to remove your old files."
  echo "    From the current directory."
  echo "    Or ALL of them!!!"
  echo "    Starting from within this directory."
  echo "    Don't worry choosing neither will simply make this script exit!"
  echo
  echo -n "Enter either Folder or All: "
  read Answer
## alias rm='rm -i' hence \rm because I know what I am doing\!  
case "$Answer" in
"Folder" | "FOLDER" | "folder" | "F" | "f")
## I SINCERELY hope that you have stashed your mp3's elsewhere!?
## Should be fine now. ; - )
  \rm *.mp{e,eg,g,4} 2>/dev/null
  \rm *.idx 2>/dev/null # We don't need those indexes anymore.
  ;;
"All" | "ALL" | "all" | "A" | "a")
## Make sure your mp3's (or any other file with extension: *.mp*) are elsewhere!?
  find -iname '*.mp*g' -exec \rm "{}" 2>/dev/null \;
  find -iname '*.idx' -exec \rm "{}"  2>/dev/null \; # We don't need those indexes anymore.
  ;;
*)
  echo 
  echo "   You wish to keep them?"
  echo "   Though they take up precious hard drive space?"
  echo "   Your wish is my command!"
  echo 
  echo "   Fwiw: For a manual removal!?"
  echo "   Either choose to run: "
## alias rm='rm -i' hence \rm because I know what I am doing\!
  echo "   \rm *.mp{e,eg,g,4}" ##should work?
  echo "   Or change this to either *.mp*g or *.mp4, if unsure?"
  echo "   For the current folder/directory."
  echo "   Or: "
  echo "   find -iname '*.mp*g' -exec \rm "{}" \;"
  echo "   For all of them!"
  echo 
  echo "   Usage: Folder|All"
  echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
  echo
  exit 1
  ;;
esac
exit 0

(Now go ) copy that!