-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ee7d869
Showing
15 changed files
with
1,321 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Delegate.as v1.0.2 | ||
Copyright (c) 2005 Steve Webster | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
class Delegate { | ||
public static function create(target:Object, handler:Function):Function { | ||
// Get any extra arguments for handler | ||
var extraArgs:Array = arguments.slice(2); | ||
|
||
// Create delegate function | ||
var delegate:Function = function() : Void { | ||
// Get reference to self | ||
var self:Function = arguments.callee; | ||
|
||
// Augment arguments passed from broadcaster with additional args | ||
var fullArgs:Array = arguments.concat(self.extraArgs, [self]); | ||
|
||
// Call handler with arguments | ||
return self.handler.apply(self.target, fullArgs); | ||
}; | ||
|
||
// Pass in local references | ||
delegate.extraArgs = extraArgs; | ||
delegate.handler = handler; | ||
delegate.target = target; | ||
|
||
// Return the delegate function. | ||
return delegate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This software includes swfobject <http://code.google.com/p/swfobject/>: | ||
|
||
Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis | ||
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import flash.external.ExternalInterface; | ||
|
||
class MusicPlayer { | ||
private var urls : Array; | ||
private var sound : Sound; | ||
private var track : Number; | ||
private var status : Number; | ||
private var pausedOffset : Number; | ||
|
||
public static var STOPPED : Number = 0; | ||
public static var PLAYING : Number = 1; | ||
public static var PAUSED : Number = 2; | ||
|
||
public function MusicPlayer(urls : Array) { | ||
this.urls = urls; | ||
this.sound = new Sound(_root); | ||
|
||
this.sound.onSoundComplete = Delegate.create(this, this.onSoundComplete); | ||
} | ||
|
||
public function connectExternal() : Void { | ||
ExternalInterface.addCallback("play", this, this.play); | ||
ExternalInterface.addCallback("stop", this, this.stop); | ||
ExternalInterface.addCallback("pause", this, this.pause); | ||
|
||
ExternalInterface.addCallback("getStatus", this, function() : Void { return this.status }); | ||
ExternalInterface.addCallback("getTrack", this, function() : Void { return this.track }); | ||
|
||
ExternalInterface.addCallback("getPosition", this, function() : Void { return this.sound.position }); | ||
} | ||
|
||
public function play(number : Number) : Void { | ||
if (number == null && this.status == PAUSED) { | ||
this.sound.start(this.pausedOffset / 1000); | ||
} | ||
else { | ||
number = (number == null) ? 0 : number; | ||
|
||
// Reset the position on the sound object. | ||
this.sound.stop(); | ||
this.sound.start(0); | ||
this.sound.stop(); | ||
|
||
this.sound.loadSound(this.urls[number], true); | ||
|
||
this.track = number; | ||
} | ||
|
||
this.status = PLAYING; | ||
} | ||
|
||
public function stop() : Void { | ||
this.sound.stop(); | ||
|
||
this.track = undefined; | ||
this.status = STOPPED; | ||
} | ||
|
||
public function pause() : Void { | ||
this.pausedOffset = this.sound.position; | ||
|
||
this.sound.stop(); | ||
|
||
this.status = PAUSED; | ||
} | ||
|
||
private function onSoundComplete() : Void { | ||
// If there is another track, play it. | ||
var next_track : Number = this.track + 1; | ||
|
||
this.stop(); | ||
|
||
if (next_track < this.urls.length) | ||
this.play(next_track); | ||
} | ||
|
||
public static function main() : Void { | ||
if (_root.playlist == undefined) | ||
return; | ||
|
||
var playlist : XSPF = new XSPF(); | ||
|
||
playlist.onLoad = function () { | ||
var player : MusicPlayer = new MusicPlayer(this.tracks); | ||
player.connectExternal(); | ||
|
||
ExternalInterface.call("MusicPlayer_callback"); | ||
} | ||
|
||
playlist.load(_root.playlist); | ||
} | ||
|
||
public static function log(args : Object) : Void { | ||
ExternalInterface.call("console.log", args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
debug = ARGUMENTS.get('debug', 0) | ||
|
||
mtasc_options = ['-strict', '-header 0:0:0', '-version 8', '-main'] | ||
|
||
if debug: | ||
mtasc_options.append('-trace MusicPlayer.log') | ||
|
||
mtasc = Builder(action = "mtasc %s $SOURCE -swf $TARGET" % (' '.join(mtasc_options)), | ||
suffix = '.swf', | ||
src_suffix = '.as') | ||
|
||
env = Environment(BUILDERS = {'ActionScript': mtasc}) | ||
|
||
env.ActionScript(source = 'MusicPlayer', target = 'static/MusicPlayer') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* A XSPF parser. | ||
* | ||
* Exposes an ordered array of URLs. | ||
*/ | ||
|
||
class XSPF { | ||
public var tracks : Array; | ||
public var onLoad : Function; | ||
|
||
private var xml : XML; | ||
|
||
public function load(url : String) : Void { | ||
this.xml = new XML(); | ||
|
||
this.xml.ignoreWhite = true; | ||
this.xml.onLoad = Delegate.create(this, this.parse); | ||
|
||
this.xml.load(url); | ||
} | ||
|
||
private function parse(success : Boolean) : Void { | ||
if (!success) | ||
return; | ||
|
||
/* Load track URLs from trackList > track > location */ | ||
|
||
this.tracks = new Array(); | ||
|
||
var root : XMLNode = this.xml.firstChild; | ||
|
||
for (var node : XMLNode = root.firstChild; | ||
node != null; | ||
node = node.nextSibling) { | ||
if (node.nodeName != "trackList") | ||
continue; | ||
|
||
for (var track : XMLNode = node.firstChild; | ||
track != null; | ||
track = track.nextSibling) { | ||
if (track.nodeName != "track") | ||
continue; | ||
|
||
for (var track_meta : XMLNode = track.firstChild; | ||
track_meta != null; | ||
track_meta = track_meta.nextSibling) { | ||
if (track_meta.nodeName == "location") { | ||
this.tracks.push(track_meta.firstChild.nodeValue); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (this.tracks != undefined && this.onLoad != undefined) | ||
this.onLoad(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
|
||
import glob | ||
import os.path | ||
import sys | ||
import xml.etree.ElementTree as ET | ||
import urlparse | ||
|
||
import web | ||
import mutagen | ||
import mutagen.id3 | ||
import mutagen.easyid3 | ||
|
||
path = 'static/' | ||
|
||
files = sorted(glob.glob(os.path.join(path, '*.mp3'))) | ||
render = web.template.render('templates/') | ||
|
||
class TrackInfo: | ||
def __init__(self, filename): | ||
try: | ||
self.load(filename) | ||
except mutagen.id3.error: | ||
self.artist = "No Artist" | ||
self.title = "No Title" | ||
self.duration = "?:??" | ||
|
||
def load(self, filename): | ||
short_tags = full_tags = mutagen.File(filename) | ||
|
||
if isinstance(full_tags, mutagen.mp3.MP3): | ||
short_tags = mutagen.easyid3.EasyID3(filename) | ||
|
||
self.artist = short_tags['artist'][0] | ||
self.title = short_tags['title'][0] | ||
self.duration = "%u:%u" % (full_tags.info.length / 60, full_tags.info.length % 60) | ||
|
||
def tracklist(): | ||
for count, fn in enumerate(files): | ||
info = TrackInfo(fn) | ||
url = urlparse.urljoin(web.ctx.homedomain, web.net.urlquote(web.http.url(fn))) | ||
|
||
yield count, info, url | ||
|
||
class XSPF: | ||
def GET(self): | ||
web.header('Content-Type', 'application/xspf+xml') | ||
print render.xspf(tracklist()) | ||
|
||
class Index: | ||
def GET(self): | ||
xspf_url = urlparse.urljoin(web.ctx.homedomain, '/xspf') | ||
print render.index(xspf_url, tracklist()) | ||
|
||
if __name__ == '__main__': | ||
urls = ('/xspf', 'XSPF', | ||
'/', 'Index',) | ||
web.run(urls, locals()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name = 'moxie', | ||
version = '0.1', | ||
packages = find_packages(), | ||
|
||
install_requires = [ | ||
'web.py >= 0.23', | ||
'mutagen >= 1.11', | ||
], | ||
|
||
test_suite = 'nose.collector' | ||
) |
Binary file not shown.
Oops, something went wrong.