Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return (entity-)type for collections #170

Merged
merged 3 commits into from
Jul 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions examples/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import musicbrainzngs
import getpass
from optparse import OptionParser
import sys

try:
user_input = raw_input
Expand All @@ -46,23 +47,60 @@ def show_collections():
result = musicbrainzngs.get_collections()
print('All collections for this user:')
for collection in result['collection-list']:
print('{name} by {editor} ({mbid})'.format(
name=collection['name'], editor=collection['editor'],
mbid=collection['id']
))
# entity-type only available starting with musicbrainzngs 0.6
if "entity-type" in collection:
print('"{name}" by {editor} ({cat}, {entity})\n\t{mbid}'.format(
name=collection['name'], editor=collection['editor'],
cat=collection['type'], entity=collection['entity-type'],
mbid=collection['id']
))
else:
print('"{name}" by {editor}\n\t{mbid}'.format(
name=collection['name'], editor=collection['editor'],
mbid=collection['id']
))

def show_collection(collection_id):
"""Show the list of releases in a given collection.
"""Show a given collection.
"""
result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
collection = result['collection']
release_list = collection['release-list']
try:
result = musicbrainzngs.get_releases_in_collection(
collection_id, limit=0)
collection = result['collection']
except musicbrainzngs.ResponseError:
# TODO
#result = musicbrainzngs.get_events_in_collection(
# collection_id, limit=0)
sys.exit("This is a collection of events which is not yet implemented")
# entity-type only available starting with musicbrainzngs 0.6
if "entity-type" in collection:
print('{mbid}\n"{name}" by {editor} ({cat}, {entity})'.format(
name=collection['name'], editor=collection['editor'],
cat=collection['type'], entity=collection['entity-type'],
mbid=collection['id']
))
else:
print('{mbid}\n"{name}" by {editor}'.format(
name=collection['name'], editor=collection['editor'],
mbid=collection['id']
))
print('')
# release count is only available starting with musicbrainzngs 0.5
if "release-count" in collection:
release_count = collection['release-count']
print('{} releases in {}:'.format(release_count, collection['name']))
else:
print('Releases in {}:'.format(collection['name']))
print('{} releases'.format(collection['release-count']))
if "event-count" in collection:
print('{} events'.format(collection['release-count']))
print('')

if "release-list" in collection:
show_releases(collection)
if "event-list" in collection:
pass # TODO

def show_releases(collection):
result = musicbrainzngs.get_releases_in_collection(collection_id, limit=25)
release_list = result['collection']['release-list']
print('Releases:')
releases_fetched = 0
while len(release_list) > 0:
print("")
Expand Down
3 changes: 2 additions & 1 deletion musicbrainzngs/mbxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ def parse_collection_list(cl):

def parse_collection(collection):
result = {}
attribs = ["id"]
attribs = ["id", "type", "entity-type"]
elements = ["name", "editor"]
# TODO: add event-list:
inner_els = {"release-list": parse_release_list}
result.update(parse_attributes(attribs, collection))
result.update(parse_elements(elements, inner_els, collection))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><collection entity-type="release" type="Release" id="0b15c97c-8eb8-4b4f-81c3-0eb24266a2ac"><name>My Collection</name><editor>JonnyJD</editor><release-list count="400"><release id="256b1535-83d8-4245-933b-7d1ed683cbc3"><title>Entities</title><status>Official</status><quality>normal</quality><packaging>Cardboard/Paper Sleeve</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992-10</date><country>DE</country><release-event-list count="1"><release-event><date>1992-10</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>4013859210366</barcode></release><release id="2df7deb7-604e-4861-8e42-79f570d4a22d"><title>German Mystic Sound Sampler, Volume III: Indie-Classics, Volume IV</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992-11-06</date><country>DE</country><release-event-list count="1"><release-event><date>1992-11-06</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>0718759100529</barcode></release><release id="3f831ec6-e8bb-35fa-b6a0-134dabf30b3f"><title>Boys Don’t Cry</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1986-04-29</date><country>DE</country><release-event-list count="1"><release-event><date>1986-04-29</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>042281501128</barcode></release><release id="5aa039be-d3b7-42e6-b805-d066867cb9dd"><title>Zillo Romantic Sound Sampler: Indie Classics, Volume III</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1991</date><country>DE</country><release-event-list count="1"><release-event><date>1991</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>718759100222</barcode></release><release id="63e0d752-5d05-4b16-9b11-02252ce7c599"><title>Bram Stoker's Dracula</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992-11-04</date><country>US</country><release-event-list count="1"><release-event><date>1992-11-04</date><area id="489ce91b-6658-3307-9877-795b68554c98"><name>United States</name><sort-name>United States</sort-name><iso-3166-1-code-list><iso-3166-1-code>US</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>074645316529</barcode></release><release id="7bf735e8-d0aa-35b7-8e05-e1487ed17976"><title>Black Sabbath</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1970</date><country>DE</country><release-event-list count="1"><release-event><date>1970</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode /></release><release id="91481687-d5f4-4d93-ab7a-f25204dc91be"><title>Follow the Blind</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1989</date><country>DE</country><release-event-list count="1"><release-event><date>1989</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list></release><release id="9c3da2f7-f11b-4d9e-a333-ce53038c267c"><title>Live! Exile on Valletta Street</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1991-09-13</date><country>DE</country><release-event-list count="1"><release-event><date>1991-09-13</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>731451117527</barcode></release><release id="a467cfea-68fb-4003-85a3-07ba5d19e0c7"><title>German Mystic Sound Sampler, Volume I: Indie-Classics, Volume I</title><status>Promotion</status><quality>normal</quality><text-representation><language>mul</language><script>Latn</script></text-representation><date>1991-05-17</date><country>DE</country><release-event-list count="1"><release-event><date>1991-05-17</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>4012170902028</barcode></release><release id="a4e06d7f-d0d9-429b-bde0-6ff63ddaa245"><title>Fixed</title><status>Official</status><quality>high</quality><packaging>Digipak</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992-12-07</date><country>US</country><release-event-list count="1"><release-event><date>1992-12-07</date><area id="489ce91b-6658-3307-9877-795b68554c98"><name>United States</name><sort-name>United States</sort-name><iso-3166-1-code-list><iso-3166-1-code>US</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>606949609320</barcode></release><release id="b57c17cd-ba06-4331-ba2e-6b7360925208"><title>Gothic Rock</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992</date><country>GB</country><release-event-list count="1"><release-event><date>1992</date><area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed"><name>United Kingdom</name><sort-name>United Kingdom</sort-name><iso-3166-1-code-list><iso-3166-1-code>GB</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>5013145203828</barcode></release><release id="b8337232-1233-4666-b048-c81aa853d4ce"><title>Burning From the Inside</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1988</date><country>GB</country><release-event-list count="1"><release-event><date>1988</date><area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed"><name>United Kingdom</name><sort-name>United Kingdom</sort-name><iso-3166-1-code-list><iso-3166-1-code>GB</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>5012093004525</barcode></release><release id="bce8246c-5ad0-4578-8a33-f15e49574760"><title>High</title><status>Official</status><quality>normal</quality><packaging>Digipak</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992-02-27</date><country>US</country><release-event-list count="1"><release-event><date>1992-02-27</date><area id="489ce91b-6658-3307-9877-795b68554c98"><name>United States</name><sort-name>United States</sort-name><iso-3166-1-code-list><iso-3166-1-code>US</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>075596643726</barcode></release><release id="c619795b-7426-4bb9-9957-d53c5ab1814b"><title>Methods of Silence</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1989-09-12</date><country>US</country><release-event-list count="1"><release-event><date>1989-09-12</date><area id="489ce91b-6658-3307-9877-795b68554c98"><name>United States</name><sort-name>United States</sort-name><iso-3166-1-code-list><iso-3166-1-code>US</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>075678200229</barcode></release><release id="cc3763b2-55e0-4718-a245-bf410020ef12"><title>Bouquet of Dreams</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1991-08-19</date><country>DE</country><release-event-list count="1"><release-event><date>1991-08-19</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>0718751108523</barcode></release><release id="cd59608e-d847-4391-a813-969ae10101e7"><title>German Mystic Sound Sampler, Volume II: Indie-Classics, Volume II</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1991</date><country>DE</country><release-event-list count="1"><release-event><date>1991</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>0718759100123</barcode></release><release id="d497b726-c646-4302-93e7-22ce52c3d49b"><title>Haus der Lüge</title><status>Official</status><quality>normal</quality><text-representation><language>deu</language><script>Latn</script></text-representation><date>1989</date><country>US</country><release-event-list count="1"><release-event><date>1989</date><area id="489ce91b-6658-3307-9877-795b68554c98"><name>United States</name><sort-name>United States</sort-name><iso-3166-1-code-list><iso-3166-1-code>US</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>023138007123</barcode></release><release id="dc4d63d7-af36-44e6-bab1-49362d389700"><title>Front by Front</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1992</date><country>US</country><release-event-list count="1"><release-event><date>1992</date><area id="489ce91b-6658-3307-9877-795b68554c98"><name>United States</name><sort-name>United States</sort-name><iso-3166-1-code-list><iso-3166-1-code>US</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>074645240626</barcode></release><release id="e0cac4b8-ea17-4c0e-83c0-5934b42e9b32"><title>I: Lieder der Arbeiterklasse &amp; Lieder aus dem spanischen Bürgerkrieg</title><status>Official</status><quality>normal</quality><text-representation><language>deu</language><script>Latn</script></text-representation><date>1989-05-02</date><country>DE</country><release-event-list count="1"><release-event><date>1989-05-02</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>4007198839876</barcode></release><release id="e4f8ec20-6cd3-4f46-a773-b6272b6051fe"><title>Monarchie und Alltag</title><status>Official</status><quality>normal</quality><text-representation><language>deu</language><script>Latn</script></text-representation><date>1980</date><country>DE</country><release-event-list count="1"><release-event><date>1980</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list></release><release id="e8086bec-de5d-3ca3-bfae-c48a1dc672f2"><title>Methods of Silence</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1989-06-05</date><country>DE</country><release-event-list count="1"><release-event><date>1989-06-05</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>042283961326</barcode></release><release id="ed2a7e38-1125-4b19-be16-2ddccff0cdb0"><title>Basically Sad</title><status>Official</status><quality>normal</quality><packaging>Jewel Case</packaging><text-representation><language>eng</language><script>Latn</script></text-representation><date>1986</date><country>DE</country><release-event-list count="1"><release-event><date>1986</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>042283508224</barcode></release><release id="eed4a1ee-7043-4013-916c-81821a48dd4f"><title>Electro Revenge</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1991</date><country>SE</country><release-event-list count="1"><release-event><date>1991</date><area id="23d10872-f5ae-3f0c-bf55-332788a16ecb"><name>Sweden</name><sort-name>Sweden</sort-name><iso-3166-1-code-list><iso-3166-1-code>SE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list><barcode>7391946035014</barcode></release><release id="f49e85de-5cda-4981-ba59-49b27e628e6f"><title>Gold und Liebe</title><status>Official</status><quality>normal</quality><text-representation><language>deu</language><script>Latn</script></text-representation><date>1981-11</date><country>DE</country><release-event-list count="1"><release-event><date>1981-11</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list></release><release id="fec34d45-457a-4d21-81c9-21e48bbe3511"><title>Flags of Revolution</title><status>Official</status><quality>normal</quality><text-representation><language>eng</language><script>Latn</script></text-representation><date>1990</date><country>DE</country><release-event-list count="1"><release-event><date>1990</date><area id="85752fda-13c4-31a3-bee5-0e5cb1f51dad"><name>Germany</name><sort-name>Germany</sort-name><iso-3166-1-code-list><iso-3166-1-code>DE</iso-3166-1-code></iso-3166-1-code-list></area></release-event></release-event-list></release></release-list></collection></metadata>
Loading