[prev in list] [next in list] [prev in thread] [next in thread] 

List:       amarok
Subject:    Moodbar visualization script
From:       Thomas Perl <thp () perli ! net>
Date:       2007-09-29 13:47:37
Message-ID: 1191073657.4890.28.camel () macbook
[Download RAW message or body]

Hello!

I've written a tiny-and-dirty Python script that reads in a ".mood" file
from Amarok's moodbar and displays it on the screen using pygame.

Maybe it's useful to somebody or maybe you want to include it in the
moodbar source as example code for reading ".mood" files.

Thomas

["moodbar.py" (moodbar.py)]

#!/usr/bin/python
#
# moodbar.py -- Read and visualize "moodbar" files
# Copyright 2007 Thomas Perl <thp@perli.net>
# Initial version: 2007-09-29
#
# This program reads in ".mood" files that have been
# created with the "moodbar" utility from
#
#   http://amarok.kde.org/wiki/Moodbar
#
# The moodbar file is a simple binary file with 
# three bytes per frame: red, green and blue.
#

import sys
import os.path

import pygame
from pygame.locals import *

HEIGHT = 100
fn = sys.argv[-1]

if not os.path.exists( fn) or len(sys.argv) < 2:
    print 'Usage: moodbar.py my-audiofile.mood'
    sys.exit( -1)

def moodbar_from_file( fn):
    fp = open( fn, 'rb')
    result = []
    s = fp.read( 3)
    while s:
        result.append( ( ord( s[0]), ord( s[1]), ord( s[2])))
        s = fp.read( 3)
    fp.close()
    return result

bars = moodbar_from_file( fn)

pygame.init()

pygame.display.set_mode( (len(bars), HEIGHT))
pygame.display.set_caption('Moodbar: %s' % os.path.basename( fn))
screen = pygame.display.get_surface()

for x in range( len(bars)):
    pygame.draw.line( screen, bars[x], (x,0),(x,HEIGHT))

pygame.display.flip()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit( 0)



_______________________________________________
Amarok mailing list
Amarok@kde.org
https://mail.kde.org/mailman/listinfo/amarok


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic