Skip to main content

Music Metedata - Territory-related tools

Project description

Music Metadata - Territories

Build Status Coverage Status GitHub PyPI

A simple library for dealing with territory hierarchies used in music metadata, currently primarily focused on CISAC TIS.

Conversion between TIS and ISO (DDEX!) territories will follow in the next release.

Classes

It has only two classes:

  • Territory - the territory, e.g. World, Europe, Croatia
  • TerritoryList - this class makes including and excluding territories simpler, it also splits territories down when needed

Territory manipulation

World excluding USA results in a minimal list of included territories:

from music_metadata.territories.territory import Territory
from music_metadata.territories.territory_list import TerritoryList

world = Territory.get('2136')
usa = Territory.get('US')

l = TerritoryList()
l.include(world)
l.exclude(usa)

for t in sorted(l, key=lambda x: x.name):
    print(f'{t.tis_n:0>4}', t.name)

Result:

2100 AFRICA
2106 ASIA
0124 CANADA
2113 CENTRAL AMERICA
2120 EUROPE
0484 MEXICO
2130 OCEANIA
2132 SOUTH AMERICA
2134 WEST INDIES

It is simple to list all the countries as well:

for t in sorted(l.countries, key=lambda x: x.name):
    print(f'{t.tis_a:0>4}', t.name)

Result:

AF AFGHANISTAN
AL ALBANIA
DZ ALGERIA
AD ANDORRA
AO ANGOLA
AG ANTIGUA AND BARBUDA
AR ARGENTINA
AM ARMENIA
AU AUSTRALIA
AT AUSTRIA
...

One can check if a country is finally included in the list:

usa in l
False

Share manipulation

Share calculations are also possible, by using a second argument to TerritoryList.include and TerritoryList.add. This second argument can be any objects that allows adding.

from music_metadata.territories.territory import Territory
from music_metadata.territories.territory_list import TerritoryList

world = Territory.get('2136')
usa = Territory.get('US')
canada = Territory.get('CA')

l = TerritoryList()
l.include(world, 25)
l.add(usa, 25)

So, we there is 25 for the whole world and additional 25 for the US. If we ask for values for the US and Canada:

l[usa], l[canada]

We get 50 for the US and 25 for Canada.

(50, 25)

Any numeric type will work out of the box, custom __add__ method might be required for complex objects. Here is an example for a list of numeric fields:

class Shares(list):
    def __add__(self, other):
        return Shares([self[i] + other[i] for i in range(len(self))])   

Testing and demo wrapper

You may test it online, no coding skills required: https://music-metadata.herokuapp.com/territories/

The code for the demo is here: https://github.com/musicmetadata/web-wrapper

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

music_metadata_territories-20.7.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

music_metadata_territories-20.7-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file music_metadata_territories-20.7.tar.gz.

File metadata

  • Download URL: music_metadata_territories-20.7.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

File hashes

Hashes for music_metadata_territories-20.7.tar.gz
Algorithm Hash digest
SHA256 065047026e28652b6f2cf7124e8cc0d130df94d55f1bb47b72db913e15f02e01
MD5 16a64209485fbcaef52d67904da8a42e
BLAKE2b-256 b426fa6d8d802cbf72a72e9f13171381079ecc118a9782adf78830c68db8d7bc

See more details on using hashes here.

File details

Details for the file music_metadata_territories-20.7-py3-none-any.whl.

File metadata

  • Download URL: music_metadata_territories-20.7-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

File hashes

Hashes for music_metadata_territories-20.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2996c6b6a5c8c0a42209057adc17b6d0d5135f508621882489fa8a37afe34c11
MD5 dbc7e00996dd24d8c3a74554c429317c
BLAKE2b-256 dee92cf3f15a1a05c848fd60d3bf4be2eeb0d4469237a237d733bc245da37775

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page