Skip to content

jphastings/dmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

READ ME FIRST

This project is now defunkt! Chendo has made a superlative successor to this gem, dmap-ng (github.com/chendo/dmap-ng) - you should be using that!

dmap

WHOA THERE!

This is very unfinished work. Feel free to use or expand, but expect some changes.

I’m planning on building a Ruby library to parse and create DMAP bytestrings. Primarily in order to create a DAAP server in ruby, though if anyone has other interesting uses that would require changes to this code please don’t hesitate to get in touch!

What is dmap?

DMAP are a method of storing a variety of objects in a bytestring, its used all over the shot by Apple in iTunes, iPhoto and probably many other places. You can read up a little on the wikipedia (en.wikipedia.org/wiki/Digital_Audio_Access_Protocol) or read about the daap protocol (tapjam.net/daap/) to get the gist of it.

There’s a big ol’ list of the tags that are known on the deleet.de website (www.deleet.de/projekte/daap/?ContentCodes) but there are undoubtedly many more (I remember from an old project that similar file structure is used for QuickTime’s mov containers and even for the mp4 container, so there may well be more there too). If you find any useful resources please get in touch!

Examples!

We all love examples, so here’s an example of how to use this module:

require 'dmap'

# You can load from any IO source:
d = DMAP::Element(open("your_dmap"))
p d
# => <MINM: "I'm a string!">

# Or write out what you want in code:
d = DMAP::Element.new("msrv",[DMAP::Element.new('minm',"I'm a string!")])
p d
# => <MSRV: [<MINM: "I'm a string!">]>

# All DMAP elements act like their Ruby counterparts
# (I've ballsed this up a little, functions taking blocks are playing up):
d.push(DMAP::Element.new('asdm'))

# They can also be pre-populated with data of an appropriate type
d.push(DMAP::Element.new('astm',123))

p d
# => <MSRV: [<MINM: "I'm a string!">, <ASDM: Fri Nov 06 11:18:29 +0000 2009>, <ASTM: 123>]>

# Ooh! And there's more, if you're parsing a DMAP and it's very large, this
# library plays nice and only parses the bits you need so far:

d = DMAP::Element(open(“your_array-like_dmap”))

p d
# => <MSRV: Some unparsed DMAP elements>

# Calling any method of the array that requires knowledge of its contents # will automagically parse what’s required, or you can call it explicitly:

d.parse_dmap
p d
# => <MSRV: [<MINM: "I'm a string!">,<MSRV: Some unparsed DMAP elements>]>
# Or, if you'd rather not have to worry you can just tell arrays to parse immediately:
DMAP::Array.parse_immediately = true
# Just remember you have to do this before you start any parsing in order for it to have an effect

If you want to allow parsing of more tags, you’re probably not going to want to go there right now (I’m likely to change the way this works) but if you just specify a new constant in the DMAP module, who’s name is the 4-byte code, set it to an array like [:string, ‘domain.app.name’].

The first item there specifies what datatype it is, but you will need to have a function called DMAP::Element#parse_your_datatype - you’ll get the idea if you look into the code. You will also need to extend the real class used to store your value so that it has a #to_dmap function. Again, go poke around the code.

About

To parse and create DMAP bytestrings in Ruby!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages