Re: First attempt at (follow along) bash script, critical assessment please

2022-07-24 Thread Russell Coker via luv-main
# the following should not be line wrapped
MP3S:=$(shell for n in *.ogg ; do echo $$n | sed -e s/^/mp3\\// -e s/ogg$$/
mp3/ ; done)

all: $(MP3S)

mp3/%.mp3: %.ogg
avconv -i $< -map 0:a -c:a copy $@
ffmpeg -i $< $(OPTS) $@


You could do that in a Makefile like the above, that means you can add new ogg 
files to your collection at any time and not have to regenerate everything.

On Sunday, 24 July 2022 17:18:42 AEST Andrew Greig via luv-main wrote:
> Hi,
> 
> I am trying to populate a drive with music and I have encountered some 
> folders of .ogg files and I wish to convert them to .mp3
> 
> I am following along with a description of the process found here 
> https://linuxconfig.org/how-to-batch-convert-music-files-with-ffmpeg
> 
> Does this look right, please?
> 
> #! bin/bash
> 
> #Script to convert a directory of .ogg files to .mp3 files
> 
> 
> #srcExt=$1   .ogg
> #destExt=$2  .mp3
> #
> #srcDir=$3   `/Music/
> #destDir=$4  `/Music/
> 
> #opts=$5
> 
> #for filename in "$srcDir"/*.$srcExt; do
> 
> #done
> 
> 
> #! /bin/bash
> 
> srcExt=$1
> destExt=$2
> 
> srcDir=$3
> destDir=$4
> 
> opts=$5
> 
> for filename in "$srcDir"/*.$srcExt; do
> 
>  basePath=${filename%.*}
>  baseName=${basePath##*/}
> 
>  ffmpeg -i "$filename" $opts "$destDir"/"$baseName"."$destExt"
> 
> done
> 
> echo "Conversion from ${srcExt} to ${destExt} complete!"
> 
> 
> Many thanks
> 
> Andrew
> 
> 
> ___
> luv-main mailing list -- luv-main@luv.asn.au
> To unsubscribe send an email to luv-main-le...@luv.asn.au


-- 
My Main Blog http://etbe.coker.com.au/
My Documents Bloghttp://doc.coker.com.au/

___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: First attempt at (follow along) bash script, critical assessment please

2022-07-24 Thread Rodney Brown via luv-main
David's suggestion on using echo is good for checking scripts before 
letting them loose.


There's shellcheck (lint tool for shell scripts) available for Debian, 
Fedora etc ... which I should remember to use more often.


Filenames with spaces in them will give problems, maybe check you don't 
have any and or check the file exists before you try to process it.


Test the exit status of ffmeg & show the offending file if it's non-zero


On 24/7/22 17:18, Andrew Greig via luv-main wrote:

Hi,

I am trying to populate a drive with music and I have encountered some 
folders of .ogg files and I wish to convert them to .mp3


I am following along with a description of the process found here 
https://linuxconfig.org/how-to-batch-convert-music-files-with-ffmpeg




for filename in "$srcDir"/*.$srcExt; do

    basePath=${filename%.*}
    baseName=${basePath##*/}

    ffmpeg -i "$filename" $opts "$destDir"/"$baseName"."$destExt"

done


___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: First attempt at (follow along) bash script, critical assessment please

2022-07-24 Thread David via luv-main
On Sun, 24 Jul 2022 at 17:19, Andrew Greig via luv-main
 wrote:

> Hi,
>
> I am trying to populate a drive with music and I have encountered some
> folders of .ogg files and I wish to convert them to .mp3
>
> I am following along with a description of the process found here
> https://linuxconfig.org/how-to-batch-convert-music-files-with-ffmpeg
>
> Does this look right, please?

Hi,

One way to test if this script does what you want would be
to temporarily change this line:

>  ffmpeg -i "$filename" $opts "$destDir"/"$baseName"."$destExt"

by adding 'echo' to the front of it, thus:

  echo ffmpeg -i "$filename" $opts "$destDir"/"$baseName"."$destExt"

And then run the script and visually confirm the commands it echoes
are what you want it to run.

Another useful test is to paste the entire script into the site
  https://www.shellcheck.net/
and read whatever advice it provides.

Most shell scripting guides contain bad advice. This is a good
one:
  http://mywiki.wooledge.org/BashGuide
  http://mywiki.wooledge.org/BashFAQ
___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


First attempt at (follow along) bash script, critical assessment please

2022-07-24 Thread Andrew Greig via luv-main

Hi,

I am trying to populate a drive with music and I have encountered some 
folders of .ogg files and I wish to convert them to .mp3


I am following along with a description of the process found here 
https://linuxconfig.org/how-to-batch-convert-music-files-with-ffmpeg


Does this look right, please?

#! bin/bash

#Script to convert a directory of .ogg files to .mp3 files


#srcExt=$1   .ogg
#destExt=$2  .mp3
#
#srcDir=$3   `/Music/
#destDir=$4  `/Music/

#opts=$5

#for filename in "$srcDir"/*.$srcExt; do

#done


#! /bin/bash

srcExt=$1
destExt=$2

srcDir=$3
destDir=$4

opts=$5

for filename in "$srcDir"/*.$srcExt; do

    basePath=${filename%.*}
    baseName=${basePath##*/}

    ffmpeg -i "$filename" $opts "$destDir"/"$baseName"."$destExt"

done

echo "Conversion from ${srcExt} to ${destExt} complete!"


Many thanks

Andrew


___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au