PDA

View Full Version : scripts to transcode playlists for use on portable media.



davegerke
2006-04-17, 21:01
HI all,

I have put a bit of time into trying to jam a few scripts together to develop a means of easily transcoding a playlist for use on portable media (flash mp3 player / cd mp3) from the slimserver web interface.

So far I have only been able to do this from the command line as my knowledge of both SB plugins and perl are more than limited.

To do this I had envisaged an additional TRANSCODE button to the right of the current playlist buttons (Save | Download | Clear | TRANSCODE)

Upon clicking the button the user is presented a popup window in which they can select the output format, bitrate and delivery method (zip, tar, iso) this window would also have some simple but nice javascript which would dynamically inform the user of the resulting size of the transcoded playlist given their selections so they can can make decisions based on the capacity of their device / CD. Once continuing the transcoding starts and once complete, the package is sent to the browser for download.

I get this far I have used a few scripts I have found around the woods, the most important being flac2mp3.pl written by the valued Squeeze contributor Pat Farrell.

Iíd also like to take this opportunity to apologise in advance for hacking some of these well written scripts to pieces (literally), as I mentioned earlier my perl programming skills are severely limited and heck, I was just trying to get things working.

Anyways, below are the files I have used and what they essentially do;

transcode.pl
basically gets the playlist and passes it to flac2mp3 via m3udo.pl

m3udo.pl
gets the playlist transcode.m3u (I couldnít find where the current playlist was stored) and lets us run flac2mp3.pl on each of the files in the playlist.

flac2mp3.pl
Actually handles the transcoding of formats. Iíve modded it a bit to pass metatags while encoding.

loadmp3.pl
attempts to estimate how large the transcoded files will be. - I think this will be simple enough to do with some JavaScript in the web interface.

Like I have mentioned above I donít really have the know-how to take this any further. Your comments / suggestions would be greatly appreciated.

Cheers,
Dave

Mark Lanctot
2006-04-18, 11:42
davegerke, despite the apparent lack of interest so far I think this is a fantastic idea.

I wish I could help but I only started learning perl and...I think I've stopped now. Just way too hard! I've learned BASIC, QBASIC, some VB, Pascal, FORTRAN and HP41C but perl is the only language that got the better of me.

Maybe I'm getting too old or maybe I'm not looking at the right tutorials.

Anyway, this would be great as I could get rid of my parallel MP3 library for my portable player.

I took a quick look at the flac2mp3 code and it looks like there's a way to modify the MP3 encoder arguments, which was my only request.

Fred
2006-04-18, 11:47
I wish I could help but I only started learning perl and...I think I've stopped now. Just way too hard! I've learned BASIC, QBASIC, some VB, Pascal, FORTRAN and HP41C but perl is the only language that got the better of me.

What's troubling you in particular? Most of the constructs are similar with all the above languages, for loop, variables, etc... I am not saying it is all of the same, just that I think there must be specific things holding you we could maybe help you master...

Fred

Mark Lanctot
2006-04-19, 11:07
What's troubling you in particular? Most of the constructs are similar with all the above languages, for loop, variables, etc... I am not saying it is all of the same, just that I think there must be specific things holding you we could maybe help you master...

Fred

1. The online tutorials I've seen really suck. They stop right after "hello world". You're on your own after that. I'm referring to http://perldoc.perl.org/perlintro.html. Perhaps there are better Perl tutorials out there?

2. I'm having a very hard time grasping user input concepts. I'm used to a command that causes a prompt for input, but it appears in Perl you have to open a file? This assumes the user must create it first? There are no examples/tutorials of this I've seen. It would be nice to prompt the user for a number, prompt for another, add the two together, then display the result, but I haven't seen how to do this.

3. I have yet to find an explanation of what all the code at the start of a program does. I see where you declare variables and there are references to CPAN modules but there are also references to other things that I haven't seen explained. For example, from the DateTime plugin:


use strict;

package Plugins::DateTime::Plugin;

use Slim::Control::Command;

use vars qw($VERSION);
$VERSION = substr(q$Revision: 1.5 $,10);

sub getDisplayName {
return 'PLUGIN_SCREENSAVER_DATETIME';
}

I understand 'use strict' (well, I understand what it's doing, but I don't understand why), the package code is a mystery, I don't understand the next few lines, then I see a subroutine declaration.

Unfortunately the Perl manual explains things in terms I don't understand either - it's like looking in a dictionary to find a word explained in other words you don't understand. For example, 'use':

http://perldoc.perl.org/functions/use.html


* use Module VERSION LIST

use module import

* use Module VERSION
* use Module LIST
* use Module
* use VERSION

Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to

BEGIN { require Module; import Module LIST; }

except that Module must be a bareword.

VERSION may be either a numeric argument such as 5.006, which will be compared to $] , or a literal of the form v5.6.1, which will be compared to $^V (aka $PERL_VERSION. A fatal error is produced if VERSION is greater than the version of the current Perl interpreter; Perl will not attempt to parse the rest of the file. Compare with require, which can do a similar check at run time.

WTF?

The entire manual is like this.

4. The CPAN modules are both helpful and hurtful, if you know what I mean. It doesn't help teaching the language to just say "don't bother learning this, CPAN module blah blah does this for you". I can understand why professional coders would like not having to reinvent the wheel, but for rank amateurs like me it makes learning the language harder.

5. I haven't dealt with a programming language that was as tightly integrated into web/HTML as Perl is. This introduces a whole lot of new concepts.

I'm definitely willing to give Perl a go: the old brain dendrites need a workout. It would be great if there were a Perl beginners forum here oriented towards SlimServer. Most of the Perl forums out there seem to be too advanced.

davegerke, sorry to hijack your thread, I'd be pleased to take it to PM or start a new thread if anyone feels that would be helpful.

stinkingpig
2006-04-19, 11:35
On 4/19/06, Mark Lanctot <
Mark.Lanctot.26iwun1145470201 (AT) no-mx (DOT) forums.slimdevices.com> wrote:
>
> ...
>
1. The online tutorials I've seen really suck. They stop right after
> "hello world". You're on your own after that. I'm referring to
> http://perldoc.perl.org/perlintro.html. Perhaps there are better Perl
> tutorials out there?


Yes, but the best thing is to read code and ask specific questions mailing
lists (Activestate hosts some great ones). Reading code comes with one
caveat though -- Slimserver and its CPAN and plugins is a huge and ugly
beast to learn a new language on. Read some simple scripts first. The
O'Reilly Perl books are fairly useful to get started with understanding the
structure of the language, but I've had problems with out-of-date
information in them.

jack@felix:~> du -h --summarize /usr/local/slimserver/ --exclude
/usr/local/slimserver/.slimserversql.db
35M /usr/local/slimserver/


2. I'm having a very hard time grasping user input concepts. I'm used
> to a command that causes a prompt for input, but it appears in Perl you
> have to open a file? This assumes the user must create it first?
> There are no examples/tutorials of this I've seen. It would be nice to
> prompt the user for a number, prompt for another, add the two together,
> then display the result, but I haven't seen how to do this.


Remember Perl came from Unix, where everything is a file -- you just open
STDIN.

http://www.wellho.net/resources/ex.php4?item=p103/greeting is the second
link on a google search for "perl user input".


3. I have yet to find an explanation of what all the code at the start
> of a program does. I see where you declare variables and there are
> references to CPAN modules but there are also references to other
> things that I haven't seen explained. For example, from the DateTime
> plugin:
>
>
> Code:
> --------------------
> use strict; # Try to prevent the programmer from shooting their
> own foot
>
> package Plugins::DateTime::Plugin; # I am providing a package, and this
> is the name.
>
> use Slim::Control::Command; # I depend on another package, and this is
> the name.
>
> use vars qw($VERSION); # I'm going to
> publish a package-level variable
> $VERSION = substr(q$Revision: 1.5 $,10); # This is the version
>
> sub getDisplayName {
> return 'PLUGIN_SCREENSAVER_DATETIME'; # If asked for my display
> name, I'll tell them this.
> }
> --------------------
>
>
> I understand 'use strict' (well, I understand what it's doing, but I
> don't understand why), the package code is a mystery, I don't
> understand the next few lines, then I see a subroutine declaration.


This is why I'm saying Slimserver is a tough place to get started. Google or
mailing list for a specific problem is better than reading the official
documentation.


> 4. The CPAN modules are both helpful and hurtful, if you know what I
> mean. It doesn't help teaching the language to just say "don't bother
> learning this, CPAN module blah blah does this for you". I can
> understand why professional coders would like not having to reinvent
> the wheel, but for rank amateurs like me it makes learning the language
> harder.


I agree, particularly when writing scripts for redistribution, or dealing
with a CPAN module that was totally rewritten since the documentation that
you're reading :) I try to avoid CPAN and stick to the included modules.

5. I haven't dealt with a programming language that was as tightly
> integrated into web/HTML as Perl is. This introduces a whole lot of
> new concepts.


Slimserver is exacerbating what you're seeing, as it runs entirely within a
web environment. Maybe it would be easier to write a skeleton of what you
want as a command line app?

I'm definitely willing to give Perl a go: the old brain dendrites need
> a workout. It would be great if there were a Perl beginners forum here
> oriented towards SlimServer. Most of the Perl forums out there seem to
> be too advanced.


I agree, I haven't been able to devote the time required to learn my way
around Slimserver either and would like to see an easier ramp into it.


--
"We both said I really love you, the Shriners loaned us cars, we raced up
and down the sidewalk twenty thousand million times." They Might Be Giants

ceejay
2006-04-19, 11:44
Marc

try http://www.oreilly.com/catalog/learnperl4/ ... its not made me an expert but I can at least read most of the damn stuff now...

Ceejay

Mark Lanctot
2006-04-19, 11:57
Remember Perl came from Unix, where everything is a file -- you just open
STDIN.

http://www.wellho.net/resources/ex.php4?item=p103/greeting is the second
link on a google search for "perl user input".


Whoops, just naturally assumed it would be in http://perldoc.perl.org/perlintro.html as it seems to be the definitive resource, and was disappointed when it wasn't.

Guys: I appreciate the help very much, but let's stop hijacking davegerke's thread as I think a plugin like this would be fantastic and I'd like to see work continue on it. If I need to I'll start a "Perl beginners Q&A thread". Thanks. :-)