← Back to team overview

pytagsfs team mailing list archive

Re: pytagsfs image support

 

Hi Rey,

On Fri, Nov 05, 2010 at 03:47:02PM +0100, Rey Cyril wrote:
> 1) Could you confirm that the metastores is the interface with file we would
> sort.  
> And so, we can activate metastore with option "pytagsfs -o  metastores=..."

Right.

A MetaStore implements metadata reading and writing.  So to add support for a
new media file format or tag format, you implement a new MetaStore.  If you read
metastore/__init__.py you may find that the docstrings there are helpful
(although they could probably be improved).

> 2) What is the purpose and how do you use "path.py" and  "testline.py"
> metastore ?

PathMetaStore provides support for treating path segments as metadata:

* %f and %{filename}
* %p and %{parent}
* %e and %{extension}

These "tags" are read-only.

TestLineMetaStore is for automated testing only.  DO NOT USE IT WITH MEDIA
FILES.

It implements a simple bogus tagging scheme where a text file that looks like
this:

--------------------------------------------------------------------------------
foo
bar
baz
--------------------------------------------------------------------------------

Would have "tags" like this:

a: foo
b: bar
c: baz

It's not useful except for testing.  You probably never want to use it.  Maybe I
should move it to the tests directory.

> 3) Could you confirm that the "get" method is used to read keywords from
> file given in path 

Right, "get" returns a Values instance.  The Values class is defined in
pytagsfs.values.  It is a subclass of dict, and you can mostly treat Values
instances like dicts.

Values instances have keys that map to format string keys.  The values are lists
of tag values for the given key.

For example, consider an MP3 file "foo/bar.mp3" with artist "Abba" and title
"Dancing Queen".

PathMetaStore.get would return a values instance that looks like this:

  Values({
    'f': ['bar.mp3'],
    'filename': ['bar.mp3'],
    'p': ['foo'],
    'parent': ['foo'],
    'e': ['mp3'],
    'extension': ['mp3'],
  })

MutagenFileMetaStore.get would return a Values instance that looks like this:

  Values({
    'a': ['Abba'],
    'artist': ['Abba'],
    't': ['Dancing Queen'],
    'title': ['Dancing Queen'],
  })

Note that your values instance must specify all keys, even though some are
effectively duplicates.  We use lists for values because tags can have multiple
values with some tag formats (e.g. ID3 supports this).

> 4) Could you confirm that the "set" method is used to write keywords within
> file given by path

Right, "set" should expect a Values instance.  It should pull new tag values
from the Values instance and apply them to the file identified by the path
argument.

The return value of "set" is a list of keys.  The intention is that the keys in
this list will not be passed to subsequent MetaStores.  In other words, it's a
way of indicating that the MetaStore implementation "owns" those keys.

Looking through the code, I think that MutagenFileMetaStore and MaildirMetaStore
are both a bit broken with regard to the return value of "set".  Sorry about
that, I'll see if I can get them fixed.

But for now, let me provide an example of the correct behavior.

Let's say you have a MetaStore that handles a metadata key "foo".  Your "get"
method returns a Values instance that looks like this:

  Values({'foo': 'bar'})

Suppose I pass a Values instance that looks like this to your "set"
implementation:

  Values({'foo': 'baz', 'qux': 'quxx'})

You would apply the new 'foo' tag value to the file and return a list:

  ['foo']

So the return value indicates the keys that your MetaStore handles.  This is how
you prevent other MetaStores from also applying your keys.

You silently ignore the 'qux' key.  Some other MetaStore might handle it.

If your MetaStore provides read-only tags, you should raise UnsettableKeyError
when you get a request to set it.  See PathMetaStore for an example.

> 5) What is the type and organization of variable "values" in get and set :
> list, tulp or dict ? 

It is a Values instance whose keys correspond with format string keys and whose
values are lists of metadata values for those keys (as in my examples above).

> 6) Is there other method than "get" and "set" which must be programmed ?

No, "get" and "set" are all that is required.

MutagenFileMetaStore has some other methods, but those are just implemented to
support the pytags utility, which is hard-coded to only use
MutagenFileMetaStore.  It would be nice to rework this at some point to make the
pytags utility use any MetaStore; that might mean augmenting the MetaStore API.

> 7) How and where the format string is managed ? Are substitution sequence
> also defined in metastore ?  

The format string support is implemented in pytagsfs.subspat.  But to add new
format string keys, you only need to implement a MetaStore with "get" and "set"
methods.  Mapping your MetaStore keys into format strings is handled
automatically.

Hope this helps.

Thanks,
Forest
-- 
Forest Bond
http://www.alittletooquiet.net
http://www.pytagsfs.org

Attachment: signature.asc
Description: Digital signature


References