blog.humaneguitarist.org

discoveries in digital audio, music notation, and information encoding

Archive for the ‘Python’ tag

South Park Launcher: Python and VB editions

without comments

It seems that about a year ago, the creators of South Park started freely offering their episodes online at southparkstudios.com.

The move was made, in part, to offer a legal way for fans without television access or even televisions (that’s me!) to watch the show. As the creators stated, they got:

"really sick of having to download our own show illegally all the time.  So we gave ourselves a legal alternative."

This was great for me because I admittedly was downloading those shows as well. One of the other great things about it is the Random Episode link which, you guessed it, launches a random episode of the show.

The only thing that makes it less than perfect is that I can’t set it to repeatedly play more random episodes.

Until now.

I decided to sit down and write the most important code I may ever write: a program that leverages the Random Episode feature to launch successive random episodes of the great social commentary, courtesy of Matt and Trey.

Here’s the core of the code, from a Python perspective:

import sys, webbrowser, time

url = ‘http://www.southparkstudios.com/episodes/random.php’

i=1

while i <= 5:
      webbrowser.open(url)
      time.sleep(1440) # 1440 seconds = 24 minutes, the average length of an episode plus ads.
       i=i+1
sys.exit()

Basically this is a loop that keeps launching a episode every 24 minutes while the variable "i" is less than or equal to 5. After every episode, "i" grows by one so when "i" equals 6, the program shuts down. BTW: after the program starts, the user does have to manually initiate playback of the first episode, but the last 4 episodes play automatically.

Now, this works fine and I even embellished the code so that the user can select from 2 to 10 episodes to launch. But I was still thinking, "This would be great to share with my friends, but they aren’t going to run software from the command line!"

So I wrote a version using Microsoft’s Visual Studio Express, a free version of their software that allows one to create GUI applications with a mixture of visual tools and the Visual Basic language. It’s a really great tool that I hope to use more in the future although I do worry about the extra time required just to make software have a graphical interface.

Anyway, here’s a ZIP file that contains both the installer for the Windows version of South Park Launcher as well as the Python version for Windows and other platforms. Make sure to read the ReadMe.txt file first!

You assume all responsibility for use.

UPDATE, 03/14/2010: Looks like the South Park site now requires one to click the "play" button to start each and every episode, so South Park Launcher isn’t very useful anymore. :( Oh well. It was fun while it lasted.

Written by nitin

November 27th, 2009 at 9:12 am

MusicSQL: initial thoughts

with one comment

One of the nice things about an emerging standard, namely MusicXML, having a command center (Recordare LLC) is having a central place to learn about what’s new.

On Friday, I was looking at Recordare’s page of MusicXML related software for software that worked from the command line and noticed something new and really interesting: MusicSQL.

According the the Goodle Code page that hosts this project, MusicSQL is:

a system for conducting complex searches of symbolic music databases. The database can import and export MusicXML files. In the current version searches are constructed using a command line interface or through simple Python scripting tools.

Basically, at least as I understand it, MusicSQL is a Python program that sits on top of a MySQL database – now I really hope Oracle doesn’t kill MySQL if it buys Sun.

I was so excited to get MusicSQL working that I didn’t notate all the little problems I had along the way. The documentation for MusicSQL is very good and is written for Windows, Mac, and Linux (Ubuntu) users. But I’m inconceivably impatient, so I just mowed through the installation with little care for remembering what I was doing.

I do remember that I had to install Python 2.5, whereas I already have Python 2.6 installed – now I have both. I put/installed all the dependencies in my Python 2.5 directory just to compartmentalized everything – the exception being MySQL, which I installed wherever the default is.

So far, I only ran the first query in the documentation that uses "scientific" musical notation in the form Nx, where "N" is the alphabetical note name, say C, and "x" is an integer that denotes what octave the note is a member of. In other words, a C-Major scale would be "Cx Dx Ex Fx Gx Ax Bx Cx+1", something like "C5 D5 … B5 C6", etc. You can place an integer before the note name to denote its duration.

Running the query from the command line, I was really happy with the speed and the output of MusicSQL for the test query.

One problem I did have, though, is I kept getting errors for another great feature of MusicSQL. Basically, after you run your query, you can see a PDF of the results (i.e. the music excerpt pertaining to the query results). The PDF is made by Lilypond, a text-based notation software that produces – in my opinion – the absolute best looking engraving out there, that’s why I use it (and yes, it’s free).

Now Lilypond doesn’t natively read MusicXML, it uses its own encoding. So MusicSQL takes advantage of a Python script that comes with the Lilypond install called "xml2ly" that converts MusicXML to Lilypond format. I left a message on the project forum for MusicSQL, so I’m hoping I can figure out what I need to do to get the Lilypond outout of the query results to work. At any rate, I do wonder how effective it can be since the conversion from MusicXML to Lilypond can sometimes get ugly.

I wonder if an alternative solution is to use the command line options for the MuseScore notation software to generate a PDF of the query results. Musescore can also convert MusicXML to other graphics formats (PNG) and even audio (WAV, FLAC, OGG), so theoretically it could be leveraged to make audio files for the corresponding query results.

At any rate, I’m really looking forward to the future developments of MusicSQL.

And as for using MuseScore’s command line in conjunction with MusicXML and how it can add value to a web collection of MusicXML docs – there will be more to that later …

Written by nitin

November 15th, 2009 at 3:54 pm

an ID3 tag reporter: MyMusicReporter.py

with 2 comments

I usually try to post to this blog once a week on average. That forces me to try to learn something or learn about something during the week that I can post about.

Sometimes though I have to resort to things that I’ve been sitting on for a while, like this Python script I wrote called MyMusicReporter.

This program makes use of the id3reader module available here. In other words, the program won’t function without this module.

For those unfamiliar with Python, it supports the use of modules, which – as the name implies – is basically allowing the current Python program to take advantage of another, pre-existing Python program. At least that’s how I understand it for now …

Anyway, MyMusicReporter does the following:

  1. it asks you to point it to a root directory on your computer,
  2. it then finds all the MP3s in that folder and its subfolders,
  3. it makes an XML file in the same directory as MyMusicReporter called MyMusicReport.xml which contains the Title, Performer, Track #, Year, and relative file path for each MP3,
  4. it makes an XML stylesheet in the same directory as MyMusicReporter called MyMusicReport.xsl which makes MyMusicReport.xml look pretty in your web browser. 

Here’s an example of how the XML looks with my home-grown schema:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="MyMusicReport.xsl"?>

<MyMusicReport>
    <mp3>
        <title>R2-DVD2</title>
        <performer>Nitin Arora</performer>
        <track>1</track>
        <year>2008</year>
        <path>r2_dvd2.mp3</path>
    </mp3>

</MyMusicReport>

Anyway, here’s the source code for MyMusicReporter.py.

You assume all responsibility for use.

Written by nitin

October 17th, 2009 at 9:12 pm

Posted in XML, scripts

Tagged with , , ,

something completely different: MyFolderMaker.py

without comments

I haven’t hidden the fact that this blog exists, in part, as a resume builder. And I think that programming skills are a valuable asset in digital libraries. Frankly, LIS programs need to address this to keep their graduates competitive. But that’s another post altogether …

Anyway, at work yesterday (Friday) I made a little Windows .bat file that creates a folder named after every line in a given plain text file.

When I came home, I napped until nearly midnight and woke up in an odd, creative state: when I’m mostly mind and hardly any body. Whether I’m hardly anybody is a matter of opinion.

I decided to make a fancier version of the batch file using Python, which is named after Monty Python’s Flying Circus. In all seriousness, that’s a huge part of the reason I decided to start learning Python.

The program can do one of the following:

  1. Ask you to supply a path and then mimick the folder structure (all new folders are created inside a folder called "MyFolderListFolder" to prevent accidental messes).
  2. Read from a plain text file of yours called "MyFolderList.txt" and make folders named for each line in the text file (all new folders are created inside a folder called "MyFolderListFolder" to prevent accidental messes).

Subfolders can be made using this format (Unix/Linux users need to use forward slashes, Windows users can use either):

folder1

folder1\subfolder

folder2

  1. Take you to this page if you’d simply like to see the source code and learn more about it. Of course, .py files can be opened in a text editor so this is only really useful for the Windows .exe version I compiled with cx_Freeze.

The program has some error checking built in. For example, if your text file has blank rows or duplicates, it will alert you under most situations that there’s a problem you need to fix.

The source code link is below if anyone is interested … real programmers likely will – and should – laugh, but I’m still learning.

A text file of the program (i.e. source code) is available here.

You assume all responsibility for use.

Written by nitin

September 26th, 2009 at 2:34 pm

Posted in scripts

Tagged with , , , ,