The script takes a list of files, i.e., a text file containing the absolute path to a file on each line (one per line), like this:

/path/to/file1/path/to/file2/path/to/file3...

The idea is the following: for each file in that list, you do some operations, and when the operations are finished, you delete the file from the list, so that the list only contains files that have not been processed so far. The rationale behind this is that this script will be applied to a huge number of files, and I want a way for the script to "resume" to where it was if it's stopped for some reason.

So far, this is what I've tried. It's for converting all my MP3s to OGG format (since it's a free standard, which MP3 is not).

The problem with this script is that for some reason it doesn't update list.txt at the end of the loop (i.e, getting rid of the filename it just finished processing). It does the conversion alright, but since the list isn't updated, I won't be able to "resume" it.

Ah, clever solution: 'tailing' the file from line 2 onwards. Thank you very much! Here's the completed script. Seems to be working correctly.

Code:

#!/bin/bash# This script converts all MP3s in the directory tree routed 'here'# to OGG vorbis format at 192kbps. It won't delete the original MP3s,# so that will have to be done manually after it has finished. The# script will generate its own list of file to process so that it can# be resumed at any later point if it is stopped.

# Generate a list of all MP3s in the directory tree, or use an already# existing one (when resuming).if [ ! -f "list.txt" ] ; then find . -iname "*.mp3" > list.txtfi

Good idea with the conversions. I had exactly ythe same thought quite awhile ago so I wrote this monster script to undertake the task. I didn't really use a list per se but instead just used whatever was passed on the command line. I like your idea of resuming though, there were quite a few times during converting a large number of files that the process would be interrupted and I would have to pick up where I left off. The way I worked around it though (as you will see in the script itself) was to simply check to see whether an ogg file with the same name as the source mp3 already existed and go from there. In comparison with your idea, it seems a little more flexible as it checks at runtime against the actual sources as opposed to a static list which may not represent changes. Anyway, here it is, it is rather long so be warned. Hopefully it may give you some inspiration...

Code:

#!/bin/bash

# SCRIPT NAME: mp3-ogg# FUNCTION: converts MPEG1 Layer III files to Ogg/Vorbis format# DEVELOPED BY - GD Lewis (rapskat@gmail.com)# CREATION DATE - Sat Oct 5 00:20:06 EDT 2002# REVISION NUMBER - 0.3# REVISION DATE - Mon Jun 15 18:04:04 EDT 2009# DEVELOPMENT ENVIRONMENT - Mepis Linux 8.0 2.6.27-1-mepis-smp #1 SMP PREEMPT i686 GNU bash 3.2.39(1)# COMMENTS - Big thanks to Jon Portnoy for helping me figure out the mkfifo thing.# NOTE - I opted for a direct pipe since using mkfifo was slow and added extra steps...sorry Jon :-(# This script was developed on a Linux system and only tested on other Linux systems.# In theory, it should be able to run on any system that can run bash shell scripts and has the necessary# programs installed, but I don't know for sure. Hell, I don't even know if it will work on most Linux systems!# If anyone tries it let me know how it turns out.## REVISION HISTORY## 0.1 - Conversion using mkfifo to create an intermediary .wav file# Used mpg321 and oggenc for decoding/encoding.## 0.2 - Replaced mkfifo with direct pipe, changed to mpg123.# Added...# - transfer id3tag data to ogg file using mp3info# - option to sort ogg files in subdirs based on id3 info# - option to specify location of encoded ogg files# - global defaults section# - removal of caps, spaces and punctuation from dirs and filenames# - check to see whether mp3 file has already been encoded# - help message# - check for programs needed# - option to specify quality of ogg encoding# - attempt best possible match of original encoding specs# - advisory about high encoding quality# - revision history# - about 10lbs since I started this project.## 0.3 - Improved error checking, cleaned up unnecessary program output, fixed problem with ID3 info being truncated# Added...# - recurse and replicate mode# - clean up routine for exit# - defaults for temp files and empty dir cleanup# - sig handling for interrupts# - automagic nose-picker# - additional comments throughout script## 0.4 - Added code for parallel processing

# =========================GLOBAL DEFAULTS =================# These variables hold the default values for the various options. The command# line option will override the default if specified. By modifying these values, you# can specify the default behavior and values for this script and save yourself some# typing, especially if you plan on using it alot. Certain options are mutually exclusive,# such as sort and r&r, so you might want to take that into consideration.

# This sets the default encoding quality to use for all ogg files# Value can be an integer from 1 to 10. If you set this to a value above 6,# then you might want to also suppress the high quality advisory with the# VERIFY option below.# This can also be specified at runtime with the -q | --quality <n> optionOGGQUAL=3

# This default sets the buffer size (in bytes) that mpg123 will use for mp3 playback.# If you are having issues during encoding or are getting skips or artifacts in the oggs,# then you can try raising or lowering this value and it may help. 200 bytes is equal to# about 1 second of playback. Keep in mind that higher values will seriously slow down# the encoding process and use more system resources. Persons with really slow/old# systems should probably leave this at 0.MP3BUFF=0

# This specifies the default output path to write the encoded ogg files. Leave# blank to default to the same directory as the source mp3 files.# TIP: It really is a good idea to have output files written to a separate# drive than the input files if at all possible as it greatly improves performance,# reliability and speed for encoding. Separate IDE channels are even better!# This can also be specified at runtime with the -o | --outdir <path> optionOUTDIR="/mnt/hdb2/tunez/oggz"

# Setting this default to 1 will always attempt to sort the encoded ogg files by the# ID3 tag data if it is present. Subdirs are created in the order genre/artist/album# All spaces, caps and punctuation are removed from directory names.# This option is ignored in Recurse and Replicate mode.# This can also be specified at runtime with the -s | --sort optionSORTOGG=0

# Setting this default to 0 will suppress the advisory about high quality encoding# If you know what you are doing and don't want to see it, then change this default.# This option is ignored in Recurse and Replicate mode.# This can also be specified at runtime by using the -n | --no-advise optionADVISE=1

# This is the global that determines what mode the script will run in. If set to 1,# it will automatically go into Recurse and Replicate mode. In R&R mode, the sub-# directory tree from the input path given will be replicated to the output path, and# all mp3 files found will be encoded to ogg and placed in the corresponding subdir# on the output path. Only directories and their subs that actually contain mp3 files will# be replicated. The only other cli options processed in this mode are --quality & --outdir.# If this default is set to 1 then you must specify the input path as the first parameter at# runtime or you will get an error. Any other options must come after this.# This can also be specified at runtime by using the -r | --recurse </path> option# This mode disregards the sort option and suppresses the advisory.REPLMODE=0

# Setting this to 1 will cause the script to attempt to remove any empty subdirectories# from the output path in the case that the script is interrupted. In Standard mode,# only empty subdirs from the output path are removed. In R&R Mode, subdirs created# will be recursed from the output path down and removed if empty.REMEMPTY=1

# This default specifies the path to write any temp files to. Usually /tmp is safe, but# you can change it if you would like temp files to be created elsewhere. Make sure# that you have read and write permissions to whatever path you specify.TMPDIR="$HOME/tmp"

# Very rarely, file will mess up and not properly identify a valid MP3 file as such# This causes the script to skip the file. Setting this default to 0 will disable the# builtin pre-verification for MP3 files and will pass all files through without checking# them first. This could have undesirable effects at runtime, so use with caution!# This can also be specified at runtime by using the -f | --force optionVERIFY=0

# Setting this default to 1 will cause the script to always delete the original mp3 files# after successfully encoding them to ogg. Be VERY careful with this!# This can also be specified at runtime by using the -k | --kill-src optionKILLMP3=0

# Setting this default to 1 will cause the script to normalize all source mp3 files# before encoding them to ogg using the defaults for normalization. This of course # depends on the presence of normalize on the system.NORM=1

# This variable will determine how many parrallel processes to spawn at a time, useful for# systems with multiple processors and/or coresCPU_PROC=2

# This is the default to determine what level to pick your nose at.# For a light dig, set it for 1 or 2. For an intermediate expedition,# you probably will want 3 or 4. For a full on excavation, 5 will do the trick.# Be careful setting this above five or you may have to take a trip to the ER.NOSE_DIG_LEVEL=3

# Warn about high encoding quality valuesprintAdvisory() { if [ "$ADVISE" -eq 1 ] ; then echo "" if [ "$1" -eq 0 ] ; then echo " HEADS UP!" echo " The level of encoding that you have specified ($2) will give you" echo " $LEVEL quality media, but also will result in very large files" echo " that will use more system resources for both storage and playback." echo " Unless you are a serious audiophile that demands this level of" echo " quality and you have a good system with plenty of resources," echo " I would suggest a lower value which would produce media" echo " that still sounds good and is much more manageable." echo "" verifyChoice "Do you really wish to encode at this level?" "Enter quality to encode at [1-10]" 0 else echo " WHOA THERE, PARDNER!" echo " You have chosen to delete all source mp3 files after they have" echo " been encoded to ogg before having a chance to verify that the" echo " encoded oggs are ok. Unless you have a backup of the source mp3" echo " files or have that much faith in this script, this might not be a" echo " wise thing to do." echo "" verifyChoice "Are you sure you want to delete the source files?" "Enter 0 if you don't or 1 if you do" 1 fi fi}

Who is online

Users browsing this forum: Google [Bot] and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum