The resources
package manages resources, which are minimally an association between the identifier and location for a downloadable article of media.
For instance, the song "Never Gonna Give You Up" by Rick Astley is accessible at the URL https://www.youtube.com/watch?v=dQw4w9WgXcQ
; the corresponding resource for this song would have an identifier that is some variation of Rick Astley - Never Gonna Give You Up
and the location of https://www.youtube.com/watch?v=dQw4w9WgXcQ
.
The strfmt library then formats identifiers to a consistent representation.
Continuing with Rick Astley and "Never Gonna Give You Up," the identifier for that song would be rick_astley-never_gonna_give_you_up
, and the location would still be https://www.youtube.com/watch?v=dQw4w9WgXcQ
.
Resources can optionally have attributes, which provide non-identifying information about the article of media.
In general, resources that have the same identifiers will have the same attributes, but this isn't always the case.
Attributes are important for determining variations between media with the same identifiers, and storing accompanying metadata.
A live version of "Never Gonna Give You Up" (such as https://www.youtube.com/watch?v=nsCIeklgp1M
) will also be rick_astley-never_gonna_give_you_up
, but will have an attribute like live
.
Since attributes play a similar role to identifiers by helping differentiate between media, the string representation of a resource is <identifier>-<attributes>
(e.g. rick_astley-never_gonna_give_you_up-live
).
Resources files are CSV files with one resource per record, with any one to three fields per record across the file. The first field is the location; if there is one field, then the identifier is also the location. If there are two fields, then the first field is the location, and the second field is the identifier. If there are three fields, then the first field is the location, the second field is the identifier, and the third field is the attributes.
A resource set is a collection of resources organized by identifier. Adding a resource to a resource set first adds the identifier if is not present, then adds the resource under the identifier. Removing an identifier from a resource set removes all resources with that identifier. Checking whether a resource set contains an identifier determines if any resources with that identifier are in the set. Getting identifiers in a resource set yields all identifiers. Getting resources in a resource set by identifier yields all resources with that identifier.