there's an awful lot of Carter the Unstoppable Sex Machine in that datastore there.
P-P-P-Pick up our PENGUIN-POWERED Pi PIPER of Python
Turning the Raspberry Pi into a music player is old hat, but turning it into a personalised DJ is slightly more difficult if a lot more interesting. The Raspberry Pi, an ARM-powered £20 computer sold as the educationalists' dream, is finding its place as a media player in many tech-aware homes, but installing media player XBMC …
-
-
-
-
Monday 26th November 2012 12:34 GMT Bill Ray
Re: Carter...
The system is happily playing back from a NAS right now, in fact I keep the application there too so I can modify it without having to touch the 'Pi.
The server is mounted by a script executed during boot (sudo update-rc.d myScript defaults), which goes on to run the app itself.
Didn't make it to the gig, much as I'd have loved to.
Bill.
-
-
-
-
Monday 26th November 2012 10:35 GMT Charlie Clark
Welcome on board!
Thanks for sharing the code - you might want to put it up on Bitbucket, Github so that we can, er, "fix it", for you.
Code is good for a start - it gets something done - but you'll have to get out of the habit of using "global" variables as that is very much frowned upon. Add in support for dispatching, string-templating and you're almost done. Well, there is more but then there always is!
-
Monday 26th November 2012 11:13 GMT Anonymous Coward
Re: Welcome on board!
Yes, never use global variables, even when you need them. Find some modern pattern like "singleton" that gives you all the pros and cons of global variables but without the cocktail-party-stopping embarrassment of daring to use a language facility that the ivory tower guys think is "harmful".
You should certainly never use globals just for convenience in a smallish application. Write applications as if they are libraries. Extra work up front *always* pays off in the end.
</sarcasm>
-
Monday 26th November 2012 11:30 GMT Charlie Clark
Re: Welcome on board!
If Bill didn't want any code review he wouldn't have posted his code.
See post lower down for why global variables are generally not required. The keyword is there so you can use it when you need to but it really is something that you very, very rarely need in Python and has extensive side-effects that you generally don't want. Pointing that out has nothing to do with ivory towers.
FWIW I don't think singletons would be needed here - something for which there isn't a keyword because you don't need them. Moving the functions into the controller class would provide mutable instance variables safely isolated from immutable module constants.
-
-
-
-
-
Monday 26th November 2012 15:09 GMT Anonymous Coward
Re: Top Notch
My vote: Raspberry Pi hacking should become part of the Special Projects Bureau's scope.
My current favorite Pi idea (I know some people were looking into it but haven't heard if there has been any success yet) if using one as a web and/or mobile app IR blaster to control all the random kit in your entertainment center. AFAICT, it can do this with just the board... the only challenge seems to be software. Given the meager requirements of that function, it seems like it could coexist with the 'DJ' role described here if not the OpenElec XBMC distro.
Future projects: Logic and control board for GAGA?
-
Monday 26th November 2012 10:52 GMT Naufana
Looks neat, but a couple of things...
- You only need a "global" declaration when you intend to assign to a global variable (and that variable is not mutable, like a list, dictionary, or some custom object).
- Using "urlparse" to decode the URL may be a good idea (especially for "setTrack.cmd" and __substitute).
- If you're not going to use a template language, at least use a library like lxml to generate correct, well-formed XHTML (your expression will also be much clearer using lxml's builder syntax).
You could also probably simplify it a little by using cherrypy (or similar) to handle the HTTP server, and separate your jukebox logic into another class (and get rid of all those globals in the process).
Good luck!
-
-
-
Monday 26th November 2012 16:22 GMT Frumious Bandersnatch
Re: Sound quality?
I ordered a couple of Pi's for my brothers' xmas presents. I got to talking about it with one of them and it turns out he already had Pi and was trying to get it to work as a jukebox. He'd run into the same problem with poor quality audio output over the 3.5mm jack. HDMI audio output is perfect, but it would mean buying another cable and converter or of having an amp that accepts HDMI input. I did a bit of research and it turns out that this is a known problem with the headphone jack. There have been some things done on the software/driver side to improve the quality a little bit (basically eliminate nasty crackles and pops when audio output starts/stops). I didn't read any more about it, but it seems that overclocking might be one way to improve the situation (the CPU has to do a lot of the work that a dedicated sound chip should do). I was also curious as to whether buying the MPEG-2 codec license would improve the situation (isn't MP3 a sub-standard within MPEG-2?)
I guess I should really be looking for those answers over on the Pi forums, but I thought I'd just throw out those ideas here in the hopes that maybe someone knows whether they work or not.
Also, thumbs up for the article. I like reading about the Pi here.
-
-
Monday 26th November 2012 13:20 GMT Tim Parker
path separators
"the code had to be altered to change the path separator"
The Python 'os' and 'os.path' module have abstractions for things like the path separator, which means that you shouldn't need to change anything once you've coded it up to use the right variables - although generally you shouldn't need to get even that low-level as there are a wealth of helper functions to split, join and otherwise manipulate path names. It's a very useful module to get to know even, or perhaps especially, when you're starting out.
HTH
-
Monday 26th November 2012 19:31 GMT Anonymous Coward
Pi–oneers
My first Pi arrived at the weekend, so I'm looking forward to joining this happy band of tinkerers —just as soon as I think of a suitably fun project to start on.
However:
"...The Raspberry Pi, an ARM-powered £20 computer..."
...I'm sure we'd all love to hear where you can p-p-p-ick up a Pi for twenty quid. It's currently £25,95 + £4,95 P&P [total: £30,87] from RS and £27,21 + £5,95 P&p [total £33,61] from Farnell.
-
Tuesday 27th November 2012 10:48 GMT Tim Parker
Re: Pi–oneers
"I'm sure we'd all love to hear where you can p-p-p-ick up a Pi for twenty quid."
The Model A is $25 (compared to $35 for the B) plus local taxes... and ex VAT the new Model B is only £ 21.60 from RS and about a pound more from Farnell, so it's not that far out to be fair (but perhaps a teeny bit misleading).
-
Tuesday 27th November 2012 19:07 GMT Anonymous Coward
Re: Pi–oneers
Ah, but therein lies the rub.
Unless you're a business, you have to stump up the VAT and aren't able to claim it back. And, given that the target market for the Pi is the amateur tinkerer not commercial enterprise, the VAT-inclusive price is the price most people will end up paying. Also, as far as I am aware, both RS Components and Farnell are mail order only retailers. Therefore the P&P costs are also unavoidable*. So, whilst in theory the Pi might cost just over £20, in practice most people will not be able to secure one for under £30.
[*P&P charges are a complete rip-off. Posted out in a jiffy bag, standard post. It must cost the suppliers under a quid to send them out, yet both charge around a fiver P&P]
-
Wednesday 28th November 2012 11:53 GMT Tim Parker
Re: Pi–oneers
"Ah, but therein lies the rub.
Unless you're a business, you have to stump up the VAT and aren't able to claim it back"
Partly true - one of the bigger markets the Pi is aimed at is the educational one, much of which would be able to claim back the VAT (as I understand it anyway, but i'm not in that sector - section 33B of the VAT Act 1994 seems to have the legal basis for this, and there are other allowances).
"Also, as far as I am aware, both RS Components and Farnell are mail order only retailers."
RS, certainly, used to run a counter service but i've not used that for years...and it would mean them adding a 'Collect from trade counter' option for them on the website when checking out - looks like that's not the way they've got the ordering set up for the Pi however. Might be worth asking them.
"[*P&P charges are a complete rip-off. Posted out in a jiffy bag, standard post. It must cost the suppliers under a quid to send them out, yet both charge around a fiver P&P]"
Totally agree.
-
-
-
-
Monday 26th November 2012 20:38 GMT JB
Very interesting article, even if i struggled to understand most of it.
I love my Pi and have been enjoying learning new stuff like using ssh, and reacquainting myself with the command line and programming, but get very frustrated at my lack of ability in learning Python. I was a keen hobbyist programmer back in the 80s and 90s, using BASIC, Pascal and some C++, and looking back at some of the surviving scripts I'm amazed at some of the stuff I did. I'm finding that python tutorials are either "print "Hello World!" at the interpreter prompt", or a full-blown in-depth essay where it's assumed you know what stuff like libraries and classes are. I wish there was something for us ex-hobbyist programmers to get us up to date...or they put GOTO into Python! :)
Please keep the articles coming...immersion is one way to learn!