Retrieved Items (aka ,,Caches’‘)

What is a Cache?

Basically every single bit of metadata returned from libglyr is a Cache. It is basically a result or it is sometimes referred to as an item. It encapsulates basic attributes like a bytearray of data, a checksum, an optional imageformat and some more.

What can I do with one?

Caches can be...

  • … committed to a local database (see next section)
  • … written to HD via it’s write() method.
  • … printed to stdout via print(), currently __repr__ is not implemented.

You can use the data property to get the actual metadata. This is always a bytestring, even with lyrics. You have to convert it to the desired encoding (e.g. utf-8) like this:

str(some_cache.data, 'utf-8')

Note

This might throw an UnicodeError on non-utf8 input, or imagedata. Use the Query-Property force_utf8 to only retrieve valid utf-8 textitems.

The data property is settable. Setting will also cause the size and checksum to be adjusted.

Note

Cache implements the __eq__ and __ne__ operator, which will compare only the data properties. This is meant to be a shortcut, since comparing data is usually the only thing you want to compare.

Reference

class plyr.Cache

A Cache is one result or item retrieved by libglyr

It encapsulates various properties like ,,data’‘, ,,checksum’’ or ,,image_format’’ and quite some more.

It can be instanciated directly, but there is no valid use to do so currently.

checksum

A 16 byte md5sum checksum in hexadecimal string-representation of the data field.

You usually should use update_checksum(), this is only if you already luckily have some correct checksum lying there by accident.

data

Actual data as bytestring. Also settable.

data_type

The type of data - this may differ from the get_type

duration

Duration in seconds, only filled for “tracklist”, otherwise 0.

image_format

The format of the image, might be one of:

[png, jpeg, gif, tiff]
is_cached

Did this item come from a local database?

is_image

A boolean. Set to true if this item contains image data.

print_cache()

Pretty print of the cache to stdout.

There is no __repr__ at the moment.

provider

The name of the provider where this items was retrieved from.

rating

The rating of this item, this is for you to set, libglyr will always set it to 0 by default. The only case where rating has a semantic meaning is for Database lookups:

If more than one item is requested, the items are returned sorted by the rating (highest rating first), and as second criteria by the timestamp, so the item with the highest rating, and the newest timestamp is always first.

This is useful to insert “dummies” to the db, in case some item was not found.

size

Size in bytes of data - this is not useful in Python, as you could do also:

len(mycache.data)

This attribute is not settable, since you could screw things up.

source_url

The URL where this items was retrieved from.

timestamp

If is_cached is True, a timestamp of the insertion sec.ms, otherwise 0.

update_checksum()

Update the checksum manually.

This should never be necessary in this wrapper though.

write()

Write item content (data) to a valid path.

Path :Must be a valid path.

Table Of Contents

Previous topic

Building Queries

Next topic

Looking up Providers

This Page