From: Vahis on
On 2010-01-05, David Bolt <blacklist-me(a)davjam.org> wrote:
>>
>> So what you suggested yesterday is once again a working solution :)
>
> I try, or I'm very trying, depending on who you ask.

I think I'm trying hard but I hear I'm hardly trying...
>
>> Your one line does what I was able to do with three :)
>>
>> The only thing still missing is recursiveness.
>
> Here's another version of that script, but one that
> will work through multiple directories. Again, it's in PHP, and this
> time it properly capitalises the words in the file name:
>
> #!/usr/bin/php
><?php
> /*
> * this is designed to run as a shell script. don't run it via a web server
> */
>
> // build an array of paths to convert using either paths passed on the
> // command line, or create an array containing only the current directory
> //
> $paths=array(getcwd());
> if($argc>1) // if there's any paths passed
> $paths=array_slice($argv,1); // replace CWD with them
>
> $count=0;
>
> foreach($paths as $source_dir)
> {
> $files=array();
> exec("find '".$source_dir."' -type f -name '*.ogg'",$files);
>
> if($files===FALSE) // none found
> die("Nothing to convert.\n"); // so quit
>
> foreach($files as $file)
> {
>
> // skip unreadable files
> //
> if(!(is_readable($file)))
> continue;
>
> // change '_' to ' ' and upper-case the initial letter of all the words
> //
> $name=ucwords(str_replace("_"," ",basename($file,"ogg")));
>
> // construct the output filename
> //
> $output=dirname($file)."/".$name."mp3";
>
> // bit of feedback while doing the conversion
> // lets the user know the script hasn't crashed
> //
> printf("Converting %s\n",$file);
>
> // then get sox to do the conversion
> //
> passthru("sox '".$file."' '".$output."'",$ret_val);
>
> // if sox converts the file successfully
> //
> if(!$ret_val)
> {
> // unlink($file); // delete the original
> $count++;
> }
> }
> }
>
> // and finally say just how many files were really converted.
> //
> die("Converted ".$count." files\n");
> ?>

Nearly there :)

I get a this in the beginning:
PHP Warning: PHP Startup: mm_create(0,
/var/lib/php5/session_mm_cli1000) failed, err mm:core:
failed to open semaphore file (Permission denied) in Unknown on line 0

It starts its job though and seems to do it except that it can't handle
apostrophes in filenames:

sox FAIL formats: can't open input file `The': No such file or directory

sh: -c: line 0: syntax error near unexpected token `)'
sox FAIL formats: can't open input file `The': No such file or directory

Those are with files like Let's Fall In Love.ogg
Stormy Weather (Keeps Rainin' All The Time).ogg
Trav'lin' Light.ogg

Such files are left untouched.

Vahis
--
"Sunrise 9:23am (EET), sunset 3:28pm (EET) at Espoo, FI (6:04 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
5:22pm up 67 days 22:23, 12 users, load average: 1.24, 1.42, 1.72
From: David Bolt on
On Wednesday 06 Jan 2010 16:26, while playing with a tin of spray paint,
Vahis painted this mural:

> On 2010-01-05, David Bolt <blacklist-me(a)davjam.org> wrote:

These mods should fix a couple of issues:

>> if($files===FALSE) // none found
>> die("Nothing to convert.\n"); // so quit

Delete the above two lines, and replace them with:

if($files===FALSE) // none found
continue; // skip to next directory

>> passthru("sox '".$file."' '".$output."'",$ret_val);

and replace the above line with:

passthru("sox ".escapeshellarg($file)." ".escapeshellarg($output),$ret_val);


which escapes the variables so they can safely be passed to the shell.

> I get a this in the beginning:
> PHP Warning: PHP Startup: mm_create(0,
> /var/lib/php5/session_mm_cli1000) failed, err mm:core:
> failed to open semaphore file (Permission denied) in Unknown on line 0

Interesting. Don't know why it would be wanting to open a semaphore
file.

> It starts its job though and seems to do it except that it can't handle
> apostrophes in filenames:

Oops. Fix for that is above.


Regards,
David Bolt

--
Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s
openSUSE 11.0 32b | | openSUSE 11.2 32b |
openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11
From: Vahis on
On 2010-01-06, David Bolt <blacklist-me(a)davjam.org> wrote:
> On Wednesday 06 Jan 2010 16:26, while playing with a tin of spray paint,
> Vahis painted this mural:
>
>> On 2010-01-05, David Bolt <blacklist-me(a)davjam.org> wrote:
>
> These mods should fix a couple of issues:

I can't thank you enough, once again :)

It works perfectly now. Awesome!

You just like whip'em out from the hip, amazing :)

Vahis
--
"Sunrise 9:23am (EET), sunset 3:28pm (EET) at Espoo, FI (6:04 hours daylight)"
http://waxborg.servepics.com
Linux 2.6.25.20-0.5-default #1 SMP 2009-08-14 01:48:11 +0200 x86_64
9:01pm up 68 days 2:02, 12 users, load average: 2.29, 1.87, 1.66
From: David Bolt on
On Wednesday 06 Jan 2010 19:11, while playing with a tin of spray paint,
Vahis painted this mural:

> On 2010-01-06, David Bolt <blacklist-me(a)davjam.org> wrote:

>> These mods should fix a couple of issues:
>
> I can't thank you enough, once again :)

No problem.

> It works perfectly now. Awesome!
>
> You just like whip'em out from the hip, amazing :)

:-)


Regards,
David Bolt

--
Team Acorn: www.distributed.net OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s
openSUSE 11.0 32b | | | openSUSE 11.3M0 32b
openSUSE 11.0 64b | openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11
From: JT on
On 11/01/10 13:07, houghi wrote:
> Vahis wrote:
>
>> I also needed to convert a couple of hundred files,
>> in 16 sub directories from ogg to mp3.
>>
> I know the solution has already been done, but just for information. It
> is also possible to use `basename` to rename files.
>
> So what you could do (untested) is to first convert all files from *.ogg
> to *.ogg.mp3
> Then you can rename *.ogg.mp3 to *.mp3
> http://www.debian-administration.org/articles/150
> Instead of the `ls *.jpg` you use `find . -name "*.mp3"` in the
> examples.
>
> houghi
>
Although `ls *.jpg` gives a slightly different result than the mentioned
`find` command of course... :) But the meaning is clear.

And indeed `find` is not just better for cosmetic reasons (yeah I know,
matter of taste), but also prevents cmd-line buffers to overflow when a
lot of files exist.

--
Kind regards, JT