Amarok - Tag filtering

June 7th, 2008

My current script tag script would list all the songs under one tag.  To extend this I added functionality to select multiple tags.  Selection multiple tags would show all the songs under all selected tags.  This works as a filter.  For example, I can show all my best songs, but then apply a filter to show all my best songs that are trance songs.  I can keep filtering by selecting more tags.

I managed to do this with 1 minor change to the sql statement and some php code.  The sql query simple selects songs under each tag.  The database has one song to lots of tags so I receive a table with lots of the same songs but with each of the tag labels.  If I find that a song has all the tags I want to filter I display that.  I do this by counting the number of tags I am searching and counting how many times the same song appears.  The song would appear the same number of times as tags I have chosen.  So if I have chosen 3 tags, the song will appear in the tag 3 times.  The table is sorted so the songs will appear one after another so I only have to check if the next song is the same is the previous.

Clicking the tag names on the page will add it to the list of chosen tags.  Clicking a tag already chosen removes it.  I added an X next to the chosen tags to represent “remove tag”.

Heres a picture of it working.

Posted in Software | No Comments »

I been playing around with the amarok sql database. Earlier I made a tag cloud to show popular tags increase in size. I have added to the script so that when clicking a tag it will display the songs that are currently tagged with the same tag.

Click for screenshot

In order to produce the list of tracks under a tag I had to use the following query.

select artist.name as artist, title as title, genre.name as genre,labels.name as label from labels, tags_labels, tags, artist, genre where labels.name=’$tagname’ and tags_labels.labelid=labels.id and tags.url=tags_labels.url and tags.artist=artist.id and tags.genre=genre.id;

Where $tagname is the name of the tag with underscores replaced with spaces.

Sorting

I have added some sorting to the script shown by the picture below

Click for screenshot

This is done by some easily expoitable php code.

$sort = “”;
if ($_GET[’sort’]) {
$sort = ” order by “;

$sort = $sort . $_GET[’sort’];
if ($_GET[’rev’] == “yes”) {
$sort = $sort . ” desc “;
}
}

This works by inserting the generated code to the end of my sql query:

…url=tags.url $sort;”);

I will add some security later to stop sql injection.

More Information

I added some statistics which can also be sorted.

Click for screenshot

To improve this, I am hoping to allow multiply tag selection. This will allow me to drill down the list of songs only showing songs under those particular tags.

Posted in Software | No Comments »

As Amarok is storing my music statistics and information in a Mysql database I thought I take advantage of this to write some small scripts.

Tag cloud, bigger text has more tagged songs

A simple sql query can grab the tag names and the total number of tracks labeled with it

select labels.name, count(labels.name) as total from tags_labels, labels where tags_labels.labelid = labels.id group by labels.name;

Then a simple loop is needed to output each label to the size determined by its total.

Related Artist Browser. Clicking a artist and related artists are displayed, clicking the artist from this page will show their related artists. Also a handy link to itunes or last.fm will be handy to have a listen to the band.

Two sql queries are required

SELECT id, name FROM artist where id=$artist_id

select suggestion,artist.id from related_artists, artist where related_artists.artist=’$artist’ and related_artists.suggestion=artist.name

The first gets me the current artist name and from an id value.  Then the second uses the name to grab the recommended artists.

More to come later.

Posted in Software | No Comments »

So, you got lots of music, you have more then one computer and you want to be able to listen to all your favorite music.  Well, I got lots of music and I am always adding to it, so copying all the music between my pc and laptop is not an option especially when my laptop has limited drive space.

Another problem I have is that I dual boot between Linux and Windows.  I have my music on a Linux partition and don’t what windows breaking my Linux partition (because somehow, Windows always manages to do so ^_^).

Solution

So I came up with a solution.   I would put all my music on a centrialised file server and share between my computers.

Amarok creates a database on my music with file locations and also statistics such as song rankings, recently added tracks, etc.  I wanted to share them.  Amarok allows you to do this by using a mysql database which can be run on the file server.

It was pretty simple to set up and works quite well.  I can be playing my music on my PC.  The go to my laptop, open Amarok and start playing music on it.  They are using the same database so no need to rescan for new music and all my rankings is there.  Also, once Amarok is released for Windows, I will be able to play my music in there just like on my laptop.

Hardware

I built a server out of some old hardware and added several 500GB harddrives to make sure I don’t run out of space.  It also shares my videos and other files I need to share.

Shared Music Folder

Share your music over NFS or Samba.  I chose NFS for my linux systems as it is very easy to set up and mount.  However, I used Samba to share with my windows system.

Mysql Database

Create a new table and user.

CREATE TABLE amarok;

GRANT ALL ON amarok.* TO ‘amarok’@'%’ IDENTIFIED BY ‘amarok’;

Amarok

Open ~/.kde/share/config/amarokrc for editing and make sure you have the following.  This should stop your database exploding every time you open Amarok.

[Collection]

DatabaseEngine=1

DynamicCollection=false

In amarok, go to collection and choose to use a mysql databas. Fill in the form and press apply.

Then select the mounted nfs folder to be scanned.

Once it is all scanned and done, your ready to go.  On a good day it should work flawlessly.

New Media PC built

January 6th, 2008

I got my new pc I am going to use for file hosting. Mainly media files such as videos and music to be shared between my pc whether in windows or Linux and my laptop and future computers. Below is a painting of it.

The black one is the new one, the white one is my desktop PC. I thought I colour coordinate and also so I know which pc is which.

Well, the new pc is running mainly on old kit, just a new PSU, Case and some harddrives slapped in.

So its on a Athlon 64 3000+ with 2GB of ram. It has a old nvidia graphics card plugged in but not monitors attached, I only connect via ssh shell.

It does have 2TB of harddrive space to play with though. Enough for me for a bit.

It is running on Gentoo linux. A standard installion with a few services running such as ssh and cronjobs.

More on this later.

Ealier I had an idea of using media wiki to manage my dads window cleaning business.  At the moment, he needs a method of storing customers and displaying when he needs to wash their windows.

Mediawiki seems perfect for this, as it already allows pages to be created, edited and extensions to be made easily.

Creating Wiki

So, I installed php, mysql, apache onto my dads laptop running Gentoo Linux.  Created a simple media wiki site to host on his laptop.  This cannot be accessed from the outside world.

Customers

I made a template for customer.  This was a simple template where you insert the customer name and address.  The template will make the page look nice.

Customers are all stored on one page called “customers”.  It is simply, just the customers name as a wiki link.  So, to create a customer, simply just type [[customer name]].  The to edit the customer, click the link produced and fill in their details with a little help from the template.

This is a nice easy way of storing customers.  Also, all the history is saved and editing is quick and no hassle.

 Customers Extension

I then went onto writing an extension.  This extension works by looking for a magic word on the page, this notifies the page contains customers and that it should process the page.  It will process the page by finding all the customers and then processes them one by one.

For each customer, the script will look on that customers page and find if there is a heading for jobs.  If there isnt it knows this is a new customer.  The script will place next to the customer name on the customers page “new customer”.

If it finds this jobs heading, it will process the customer further.  It hopes to find a sub heading, which will be the last job done for that customer.  This sub heading is in the form of a date.  The script can get this date and work out how many days or weeks ago that date is.

The script will then place next to the customer how many days ago the last job was .  If it was over 4 weeks ago, it will place next to the customer that the customer is due for a clean.

More To Be Done

This proves that media wiki can be exploited to do some customer management without spending lots of time creating databases, writing code or buying software.  I still got some features to add such as reporting and improvements.  I will post more on this later.

Well, I currently making a game, kinda like a Sim city game. However I am not going to say too much about this game just yet.

However, I thought I try something new in when developing this game. This game involves displaying objects on a 2d plain of land. The simplest way to store positions of objects is to create a 2d array where you set the variable at array[x][y]. Well thats ok, until you want to store lots of objects on a very large map.

When I say large, I only mean a map about 2000×2000 squares. However each square is 32×32. This give me 64000×64000 of space to work on. For my game, that would be in pixels. I didnt really want a 64000×64000 array so I took a different approach.

Creating a 2D HashMap

So, I though, hashmaps are great for storing data in, all you need to know is the key, and you can replace the data, grab data out of it and also it is only as big as required saving memory.

So, I created a class where it stores a hashmap. Now, the key for this hashmap is a Integer object, this will become the y coordinate of my plain. The object is another HashMap where its key is the x coordinate. So now, i can put in a object with X and Y coordinates.

To get a object out, you just ask for y in the first hashmap and x in the second that is returned by hashmap y.

Why This Method is Great

This is really handy way of storing my map, for this game at least. I can insert images at pixel accuracy and the size of my plain is not limited by a absolute integer (when my heap overflows). However, I maybe limited by the amount of objects I can put in it, so far I managed 2000×2000 without a problem and using default java heap size. An array has a finite size and also would waste space on unused blocks.

I could also add another dimension to be layers, so I can place objects on top of each other at the same location but I haven’t got round to needing that yet.

It is also to move objects, just remove from one list and insert it back into the other at the new location.

I have also coded my game to display a tunnel vision of my map. This will only display 30×30 blocks of the map. I can drag the map around but only the data visible is taken out. I don’t iterate through all my data.

Collision detection would also be quite simple to do, as I can query an area in the hashmap. I havent made it possible to find objects within a whole area though, so at the moment each possible location needs to be checked one by one. I will figure this problem out later, I don’t need collision detection accurate to the pixel yet.

The Code

Here is the code I am currently using! Do what you want with it.

import java.util.*;

public class PlainMap {

HashMap map;

public PlainMap() {
map = new HashMap();
}

public void put(Object object, int x, int y) {
Integer ix, iy;
ix = new Integer(x);
iy = new Integer(y);

HashMap xmap = (HashMap) map.get(ix);
if (xmap == null) {
xmap = new HashMap();
map.put(ix, xmap);
}
xmap.put(iy, object);
}

public Object get(int x, int y) {
Integer ix, iy;
ix = new Integer(x);
iy = new Integer(y);

HashMap xmap = (HashMap) map.get(ix);
if (xmap == null) return null;
return xmap.get(iy);
}

}

More to come later!

Posted in Software | No Comments »

So, my dad in need of a nice easy way of keeping track of his windows cleaning work.  Basically, he wants to store his customers in a electronic database that will tell him when jobs are due to be done.

Well, I could just download from 100s of window cleaning products available on the Internet but I do not want to pay for them and most only run on Windows.   I rather make my own.  I had the choice of making it in Java or php and storing everything in a nice sql database, but it seemed too time consuming and lots of pointless code to be written.

Well, it seems that mediawiki can already do almost everything I need for me!

So, this is what I propose to do.

Storing Customers

So, a good start in a database is to have customers, why not have a page on the wiki with a list of customers.  Just need the customers names and make these links.  So then each customer will become a page in the wiki.  This will allow details on each customer to be added.

Jobs

Each customer will have a history of when their windows had been cleaned.  This is a list of dates and also if they have paid or not.

A page to show jobs for the day or week will allow my client (dad) to see what needs to be done.  This would be calculated by finding all customers from the customers page, finding the last job done, then if that job has not been done recently it would be flagged to be done.  Also sorting by oldest first, to make sure they all get done and not get left behind.

Possible?

This seems very possible.  One or two simple scripts could be written to allow this to work perfectly.

I have released Embed News 1.0 extension for media wiki.   Check it out here.

Unreal Tournament 3

November 24th, 2007

I got unreal tournament 3 ^_^

Heres a photo!

Posted in Life | No Comments »