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

Add release options #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions discogs_cli/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@
},
'master': {
'args': '1',
'opts': '',
'opts': ''
},
'release': {
'args': '1',
'opts': '',
'opts': [
'--exclude (personnel|tracklist|notes)',
'--include (personnel|tracklist|notes)'
]
},
'search': {
'args': '"query string"',
'opts': [
'--lookup (artist|label|release)',
],
]
},
}
META_LOOKUP = {
'1': 'id: int - discogs ID to retrieve',
'--lookup': '(artist|label|release)',
'"(artist|label|release)"': 'Type of query to perform',
'--exclude': '(personnel|tracklist|notes)',
'--include': '(personnel|tracklist|notes)'
}
META_LOOKUP.update(SUBCOMMANDS)
59 changes: 45 additions & 14 deletions discogs_cli/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,18 @@ class Release(Discogs):
:param release_id: A Discogs.com release id.
"""

def __init__(self, release_id):
def __init__(self, release_id, exclude="None", include="All"):
super(Release, self).__init__()
self.release_id = release_id

self.discogs = self.client.release(self.release_id)
self.exclude = exclude
self.include = include


def show(self):
out = []
year = self.discogs.year

extraartists = self.discogs.data["extraartists"]
out.append('{artists} - {title}'.format(artists=','.join(
self._artists(self.discogs.data['artists'])),
title=self.discogs.data['title']))
Expand All @@ -307,17 +309,46 @@ def show(self):
out.append(self.clabel('Year:') + ' {year}'.format(year=year))
out.append(self.clabel('Genre:') + ' {genre}'.format(genre=', '.join(
self.discogs.genres)))
out.append(self.clabel('Style:') + ' {style}'.format(style=', '.join(
self.discogs.styles)))
try:
out.append(self.clabel('Style:') + ' {style}'.format(style=', '.join(
self.discogs.styles)))
except:
print("Style info not available.")
out.append(self.clabel('Rating:') + ' {rating}/5'.format(
rating=self.discogs.data.get('community', {}).get('rating',
{}).get('average')))
out.append(self._separator('Tracklist'))
for t in self.discogs.data['tracklist']:
duration = ' {0}'.format(t.get('duration'))
out.append('{pos}\t{title} {dur}'.format(
pos=t['position'], title=t['title'], dur=duration))

out.append(self._separator('Notes'))
out.append(self.discogs.data.get('notes', 'None.'))
{}).get('average')))
out = self.show_extra(self.exclude,self.include,out)
click.echo('\n'.join(out), color=True)

def show_extra(self,exclude,include,out):
personnel,tracklist,notes = True,True,True
if "personnel" in exclude:
personnel = False
elif "tracklist" in exclude:
tracklist = False
elif "notes" in exclude:
notes = False
elif "personnel" in include:
tracklist,notes = False,False
elif "tracklist" in include:
personnel,notes = False,False
elif "notes" in include:
personnel,tracklist = False,False

if personnel is True:
out.append(self._separator('Personnel'))
for t in self.discogs.data['extraartists']:
name = t["name"]
role = t["role"]
out.append(self.clabel('{role}: '.format(role=role)) + ' {name}'.format(
name=name))
if tracklist is True:
out.append(self._separator('Tracklist'))
for t in self.discogs.data['tracklist']:
duration = ' {0}'.format(t.get('duration'))
out.append('{pos}\t{title} {dur}'.format(
pos=t['position'], title=t['title'], dur=duration))
if notes is True:
out.append(self._separator('Notes'))
out.append(self.discogs.data.get('notes', 'None.'))
return out
6 changes: 4 additions & 2 deletions discogs_cli/main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def label(label_id):

@cli.command('release')
@click.argument('release_id')
def release(release_id):
@click.option('--exclude', default="None")
@click.option('--include', default="All")
def release(release_id,exclude,include):
"""Retrieve a single release from the discogs database."""
r = Release(release_id)
r = Release(release_id,exclude=exclude,include=include)

try:
r.show()
Expand Down