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

list shows in json format #662

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
44 changes: 44 additions & 0 deletions trackma/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Trackma_cmd(command.Cmd):
'sort': 1,
'mediatype': (0, 1),
'info': 1,
'name': 1,
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
'search': 1,
'add': 1,
'del': 1,
Expand Down Expand Up @@ -362,6 +363,29 @@ def do_list(self, args):
# Show the list in memory
self._make_list(self.sortedlist)

def do_list_raw(self, args):
"""
Similar to list except remove formatting.
: name list_raw
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
"""
self._make_list_raw(self.sortedlist)

def do_name(self, args):
"""
Print title name for given index.

:param show Show index.
:usage name <index>
"""
try:
show = self._get_show(args[0])
details = self.engine.get_show_details(show)
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved
except utils.TrackmaError as e:
self.display_error(e)
return

print(show['title'])

def do_info(self, args):
"""
Gets detailed information about a local show.
Expand Down Expand Up @@ -945,6 +969,26 @@ def _make_list(self, showlist):
print('%d results' % len(showlist))
print()

def _make_list_raw(self, showlist):
"""
Helper function for printing a non-formatted show list
"""
altnames = self.engine.altnames()

# List shows
for index, show in showlist:
if self.engine.mediainfo['has_progress']:
episodes_str = "{0}\t{1}".format(
show['my_progress'], show['total'] or '?')
else:
episodes_str = "-"

# Get title (and alt. title) and if need be, truncate it
title_str = show['title']
if altnames.get(show['id']):
title_str += " [{}]".format(altnames.get(show['id']))
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved

print(index,title_str, episodes_str,show['my_score'],sep='\t')
FichteFoll marked this conversation as resolved.
Show resolved Hide resolved

class Trackma_accounts(AccountManager):
def _get_id(self, index):
Expand Down