trackma 0.6__py3.5.egg → 0.7.4__py3.5.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. EGG-INFO/PKG-INFO +1 -1
  2. EGG-INFO/SOURCES.txt +23 -6
  3. EGG-INFO/entry_points.txt +4 -3
  4. EGG-INFO/requires.txt +1 -3
  5. trackma/__pycache__/__init__.cpython-35.pyc +0 -0
  6. trackma/__pycache__/accounts.cpython-35.pyc +0 -0
  7. trackma/__pycache__/data.cpython-35.pyc +0 -0
  8. trackma/__pycache__/engine.cpython-35.pyc +0 -0
  9. trackma/__pycache__/messenger.cpython-35.pyc +0 -0
  10. trackma/__pycache__/utils.cpython-35.pyc +0 -0
  11. trackma/data/kitsu.png +0 -0
  12. trackma/data.py +28 -17
  13. trackma/engine.py +208 -64
  14. trackma/extras/AnimeInfoExtractor.py +14 -5
  15. trackma/extras/__pycache__/AnimeInfoExtractor.cpython-35.pyc +0 -0
  16. trackma/extras/__pycache__/__init__.cpython-35.pyc +0 -0
  17. trackma/lib/__pycache__/__init__.cpython-35.pyc +0 -0
  18. trackma/lib/__pycache__/lib.cpython-35.pyc +0 -0
  19. trackma/lib/__pycache__/libanilist.cpython-35.pyc +0 -0
  20. trackma/lib/__pycache__/libkitsu.cpython-35.pyc +0 -0
  21. trackma/lib/__pycache__/libmal.cpython-35.pyc +0 -0
  22. trackma/lib/__pycache__/libshikimori.cpython-35.pyc +0 -0
  23. trackma/lib/__pycache__/libvndb.cpython-35.pyc +0 -0
  24. trackma/lib/libanilist.py +21 -17
  25. trackma/lib/libkitsu.py +506 -0
  26. trackma/lib/libmal.py +15 -15
  27. trackma/lib/libshikimori.py +3 -3
  28. trackma/lib/libvndb.py +26 -14
  29. trackma/messenger.py +1 -1
  30. trackma/tracker/__init__.py +0 -0
  31. trackma/tracker/__pycache__/__init__.cpython-35.pyc +0 -0
  32. trackma/tracker/__pycache__/inotify.cpython-35.pyc +0 -0
  33. trackma/tracker/__pycache__/inotifyBase.cpython-35.pyc +0 -0
  34. trackma/tracker/__pycache__/plex.cpython-35.pyc +0 -0
  35. trackma/tracker/__pycache__/polling.cpython-35.pyc +0 -0
  36. trackma/tracker/__pycache__/pyinotify.cpython-35.pyc +0 -0
  37. trackma/tracker/__pycache__/tracker.cpython-35.pyc +0 -0
  38. trackma/tracker/__pycache__/win32.cpython-35.pyc +0 -0
  39. trackma/tracker/inotify.py +69 -0
  40. trackma/tracker/inotifyBase.py +107 -0
  41. trackma/tracker/plex.py +139 -0
  42. trackma/tracker/polling.py +55 -0
  43. trackma/tracker/pyinotify.py +90 -0
  44. trackma/tracker/tracker.py +223 -0
  45. trackma/tracker/win32.py +74 -0
  46. trackma/ui/__pycache__/__init__.cpython-35.pyc +0 -0
  47. trackma/ui/__pycache__/cli.cpython-35.pyc +0 -0
  48. trackma/ui/__pycache__/curses.cpython-35.pyc +0 -0
  49. trackma/ui/__pycache__/gtkui.cpython-35.pyc +0 -0
  50. trackma/ui/__pycache__/qt4ui.cpython-35.pyc +0 -0
  51. trackma/ui/__pycache__/qtui.cpython-35.pyc +0 -0
  52. trackma/ui/cli.py +195 -26
  53. trackma/ui/curses.py +133 -66
  54. trackma/ui/gtkui.py +253 -78
  55. trackma/ui/qt4ui.py +25 -0
  56. trackma/ui/qtui.py +357 -186
  57. trackma/utils.py +40 -11
  58. trackma/__pycache__/tracker.cpython-35.pyc +0 -0
  59. trackma/data/hb.jpg +0 -0
  60. trackma/data/melative.jpg +0 -0
  61. trackma/extras/__pycache__/plex.cpython-35.pyc +0 -0
  62. trackma/extras/plex.py +0 -101
  63. trackma/lib/__pycache__/libhb.cpython-35.pyc +0 -0
  64. trackma/lib/__pycache__/libmelative.cpython-35.pyc +0 -0
  65. trackma/lib/libhb.py +0 -237
  66. trackma/lib/libmelative.py +0 -204
  67. trackma/tracker.py +0 -390
trackma/ui/cli.py CHANGED
@@ -15,14 +15,19 @@
15
15
  #
16
16
 
17
17
  import sys
18
+
18
19
  try:
19
20
  import readline
21
+ has_readline = True
20
22
  except ImportError:
23
+ has_readline = False
21
24
  pass # readline is optional
25
+
22
26
  import cmd
23
27
  import shlex
24
28
  import textwrap
25
29
  import re
30
+ import getopt
26
31
  from operator import itemgetter # Used for sorting list
27
32
 
28
33
  from trackma.engine import Engine
@@ -30,7 +35,6 @@ from trackma.accounts import AccountManager
30
35
  from trackma import messenger
31
36
  from trackma import utils
32
37
 
33
- _DEBUG = False
34
38
  _COLOR_RESET = '\033[0m'
35
39
  _COLOR_ENGINE = '\033[0;32m'
36
40
  _COLOR_DATA = '\033[0;33m'
@@ -61,8 +65,10 @@ class Trackma_cmd(cmd.Cmd):
61
65
  completekey = 'Tab'
62
66
  cmdqueue = []
63
67
  stdout = sys.stdout
68
+ in_prompt = False
64
69
  sortedlist = []
65
70
  needed_args = {
71
+ 'altname': (1, 2),
66
72
  'filter': (0, 1),
67
73
  'sort': 1,
68
74
  'mediatype': (0, 1),
@@ -76,15 +82,27 @@ class Trackma_cmd(cmd.Cmd):
76
82
  'status': 2,
77
83
  }
78
84
 
79
- def __init__(self):
80
- print('Trackma v'+utils.VERSION+' Copyright (C) 2012 z411')
81
- print('This program comes with ABSOLUTELY NO WARRANTY; for details type `info\'')
85
+ def __init__(self, account_num=None, debug=False):
86
+ print('Trackma v'+utils.VERSION+' Copyright (C) 2012-2017 z411')
87
+ print('This program comes with ABSOLUTELY NO WARRANTY; for details type `about\'')
82
88
  print('This is free software, and you are welcome to redistribute it')
83
- print('under certain conditions; see the file COPYING for details.')
89
+ print('under certain conditions; see the COPYING file for details.')
84
90
  print()
85
91
 
92
+ self.debug = debug
93
+
86
94
  self.accountman = Trackma_accounts()
87
- self.account = self.accountman.select_account(False)
95
+ if account_num:
96
+ try:
97
+ self.account = self.accountman.get_account(int(account_num))
98
+ except KeyError:
99
+ print("Account {} doesn't exist.".format(account_num))
100
+ self.account = self.accountman.select_account(True)
101
+ except ValueError:
102
+ print("Account {} must be numeric.".format(account_num))
103
+ self.account = self.accountman.select_account(True)
104
+ else:
105
+ self.account = self.accountman.select_account(False)
88
106
 
89
107
  def _update_prompt(self):
90
108
  self.prompt = "{c_u}{u}{c_r} [{c_a}{a}{c_r}] ({c_mt}{mt}{c_r}) {c_s}{s}{c_r} >> ".format(
@@ -109,15 +127,20 @@ class Trackma_cmd(cmd.Cmd):
109
127
  # otherwise use title
110
128
  try:
111
129
  index = int(title)-1
112
- return self.sortedlist[index]
130
+ return self.sortedlist[index][1]
113
131
  except (ValueError, AttributeError, IndexError):
114
132
  return self.engine.get_show_info_title(title)
115
133
 
116
134
  def _ask_update(self, show, episode):
117
- do_update = input("Should I update %s to episode %d? [y/N] " % (show['title'], episode))
118
- if do_update.lower() == 'y':
135
+ do = input("Should I update {} to episode {}? [y/N] ".format(show['title'], episode))
136
+ if do.lower() == 'y':
119
137
  self.engine.set_episode(show['id'], episode)
120
138
 
139
+ def _ask_add(self, show_title, episode):
140
+ do = input("Should I search for the show {}? [y/N] ".format(show_title))
141
+ if do.lower() == 'y':
142
+ self.do_add([show_title])
143
+
121
144
  def start(self):
122
145
  """
123
146
  Initializes the engine
@@ -131,6 +154,7 @@ class Trackma_cmd(cmd.Cmd):
131
154
  self.engine.connect_signal('status_changed', self._load_list)
132
155
  self.engine.connect_signal('episode_changed', self._load_list)
133
156
  self.engine.connect_signal('prompt_for_update', self._ask_update)
157
+ self.engine.connect_signal('prompt_for_add', self._ask_add)
134
158
  self.engine.start()
135
159
 
136
160
  # Start with default filter selected
@@ -144,6 +168,21 @@ class Trackma_cmd(cmd.Cmd):
144
168
  self.do_filter(None) # Show available filters
145
169
  print()
146
170
 
171
+ def do_about(self, args):
172
+ print("Trackma {} by z411 (z411@omaera.org)".format(utils.VERSION))
173
+ print("Trackma is an open source client for media tracking websites.")
174
+ print("https://github.com/z411/trackma")
175
+ print()
176
+ print("This program is licensed under the GPLv3 and it comes with ASOLUTELY NO WARRANTY.")
177
+ print("Many contributors have helped to run this project; for more information see the AUTHORS file.")
178
+ print("For more information about the license, see the COPYING file.")
179
+ print()
180
+ print("If you encounter any problems please report them in https://github.com/z411/trackma/issues")
181
+ print()
182
+ print("This is the CLI version of Trackma. To see available commands type `help'.")
183
+ print("For other available interfaces please see the README file.")
184
+ print()
185
+
147
186
  def do_help(self, arg):
148
187
  if arg:
149
188
  try:
@@ -305,7 +344,11 @@ class Trackma_cmd(cmd.Cmd):
305
344
  self.display_error(e)
306
345
  return
307
346
 
308
- print("Title: %s" % details['title'])
347
+ print(details['title'])
348
+ print("-" * len(details['title']))
349
+ print(show['url'])
350
+ print()
351
+
309
352
  for line in details['extra']:
310
353
  print("%s: %s" % line)
311
354
 
@@ -316,7 +359,7 @@ class Trackma_cmd(cmd.Cmd):
316
359
  :param pattern Regex pattern to search for.
317
360
  :usage search <pattern>
318
361
  """
319
- sortedlist = list(v for v in self.sortedlist if re.match(args[0], v[1]['title'], re.I))
362
+ sortedlist = list(v for v in self.sortedlist if re.search(args[0], v[1]['title'], re.I))
320
363
  self._make_list(sortedlist)
321
364
 
322
365
  def do_add(self, args):
@@ -367,11 +410,11 @@ class Trackma_cmd(cmd.Cmd):
367
410
  except utils.TrackmaError as e:
368
411
  self.display_error(e)
369
412
 
370
- def do_scaneps(self, args):
413
+ def do_rescan(self, args):
371
414
  """
372
415
  Re-scans the local library.
373
416
  """
374
- self.engine.scan_library()
417
+ self.engine.scan_library(rescan=True)
375
418
 
376
419
  def do_random(self, args):
377
420
  """
@@ -382,6 +425,43 @@ class Trackma_cmd(cmd.Cmd):
382
425
  except utils.TrackmaError as e:
383
426
  self.display_error(e)
384
427
 
428
+ def do_tracker(self, args):
429
+ """
430
+ Shows information about the tracker, if it's running.
431
+
432
+ :usage trackmer
433
+ """
434
+ try:
435
+ info = self.engine.tracker_status()
436
+ print("- Tracker status -")
437
+
438
+ if info:
439
+ if info['state'] == utils.TRACKER_NOVIDEO:
440
+ state = 'No video'
441
+ elif info['state'] == utils.TRACKER_PLAYING:
442
+ state = 'Playing'
443
+ elif info['state'] == utils.TRACKER_UNRECOGNIZED:
444
+ state = 'Unrecognized'
445
+ elif info['state'] == utils.TRACKER_NOT_FOUND:
446
+ state = 'Not found'
447
+ elif info['state'] == utils.TRACKER_IGNORED:
448
+ state = 'Ignored'
449
+ else:
450
+ state = 'N/A'
451
+
452
+ print("State: {}".format(state))
453
+ print("Filename: {}".format(info['filename'] or 'N/A'))
454
+ print("Timer: {}".format(info['timer'] or 'N/A'))
455
+ if info['show']:
456
+ (show, ep) = info['show']
457
+ print("Show: {}\nEpisode: {}".format(show['title'], ep))
458
+ else:
459
+ print("Show: N/A")
460
+ else:
461
+ print("Not started")
462
+ except utils.TrackmaError as e:
463
+ self.display_error(e)
464
+
385
465
  def do_play(self, args):
386
466
  """
387
467
  Starts the media player with the specified episode number (next if not specified).
@@ -469,6 +549,27 @@ class Trackma_cmd(cmd.Cmd):
469
549
  except utils.TrackmaError as e:
470
550
  self.display_error(e)
471
551
 
552
+ def do_altname(self, args):
553
+ """
554
+ Changes the alternative name of a show.
555
+ Use the command 'altname' without arguments to clear the alternative
556
+ name.
557
+
558
+ :param show Show index or name
559
+ :param alt The alternative name. Use `altname` without alt to clear it
560
+ :usage altname <show index or name> <alternative name>
561
+ """
562
+ try:
563
+ altnames = self.engine.altnames()
564
+ show = self._get_show(args[0])
565
+ altname = args[1] if len(args) > 1 else ''
566
+ self.engine.altname(show['id'],altname)
567
+ except IndexError:
568
+ print("Missing arguments")
569
+ return
570
+ except utils.TrackmaError as e:
571
+ self.display_error(e)
572
+
472
573
  def do_send(self, args):
473
574
  """
474
575
  Sends queued changes to the remote service.
@@ -567,6 +668,20 @@ class Trackma_cmd(cmd.Cmd):
567
668
  def emptyline(self):
568
669
  return
569
670
 
671
+ def preloop(self):
672
+ """ Override. """
673
+ self.in_prompt = True
674
+
675
+ def precmd(self, line):
676
+ """ Override. """
677
+ self.in_prompt = False
678
+ return line
679
+
680
+ def postcmd(self, stop, line):
681
+ """ Override. """
682
+ self.in_prompt = True
683
+ return stop
684
+
570
685
  def onecmd(self, line):
571
686
  """ Override. """
572
687
  cmd, arg, line = self.parseline(line)
@@ -606,7 +721,7 @@ class Trackma_cmd(cmd.Cmd):
606
721
  print("Incorrent number of arguments. See `help %s`" % cmd)
607
722
 
608
723
  def display_error(self, e):
609
- print("%s%s: %s%s" % (_COLOR_ERROR, type(e), e, _COLOR_RESET))
724
+ print("%s%s: %s%s" % (_COLOR_ERROR, type(e).__name__, e, _COLOR_RESET))
610
725
 
611
726
  def messagehandler(self, classname, msgtype, msg):
612
727
  """
@@ -620,19 +735,35 @@ class Trackma_cmd(cmd.Cmd):
620
735
  color_escape = _COLOR_ENGINE
621
736
  elif classname == 'Data':
622
737
  color_escape = _COLOR_DATA
623
- elif classname == 'Tracker':
624
- color_escape = _COLOR_TRACKER
625
738
  elif classname.startswith('lib'):
626
739
  color_escape = _COLOR_API
740
+ elif classname.startswith('Tracker'):
741
+ color_escape = _COLOR_TRACKER
627
742
  else:
628
743
  color_reset = ''
629
744
 
630
745
  if msgtype == messenger.TYPE_INFO:
631
- print("%s%s: %s%s" % (color_escape, classname, msg, color_reset))
746
+ out = "%s%s: %s%s" % (color_escape, classname, msg, color_reset)
632
747
  elif msgtype == messenger.TYPE_WARN:
633
- print("%s%s warning: %s%s" % (color_escape, classname, msg, color_reset))
634
- elif _DEBUG and msgtype == messenger.TYPE_DEBUG:
635
- print("%s%s: %s%s" % (color_escape, classname, msg, color_reset))
748
+ out = "%s%s warning: %s%s" % (color_escape, classname, msg, color_reset)
749
+ elif self.debug and msgtype == messenger.TYPE_DEBUG:
750
+ out = "[D] %s%s: %s%s" % (color_escape, classname, msg, color_reset)
751
+ else:
752
+ return # Unrecognized message, don't show anything
753
+
754
+ if has_readline and self.in_prompt:
755
+ # If we're in a prompt and receive a message
756
+ # (often from the tracker) we need to clear the line
757
+ # first, show the message, then re-show the prompt.
758
+ buf = readline.get_line_buffer()
759
+ self.stdout.write('\r' + ' '*(len(self.prompt)+len(buf)) + '\r')
760
+
761
+ print(out)
762
+
763
+ self.stdout.write(self.prompt + buf)
764
+ self.stdout.flush()
765
+ else:
766
+ print(out)
636
767
 
637
768
  def _guess_status(self, string):
638
769
  for k, v in self.engine.mediainfo['statuses_dict'].items():
@@ -672,6 +803,7 @@ class Trackma_cmd(cmd.Cmd):
672
803
  col_title_length = 5
673
804
  col_episodes_length = 9
674
805
  col_score_length = 6
806
+ altnames = self.engine.altnames()
675
807
 
676
808
  # Calculate maximum width for the title column
677
809
  # based on the width of the terminal
@@ -691,19 +823,21 @@ class Trackma_cmd(cmd.Cmd):
691
823
  # Print header
692
824
  print("| {0:{1}} {2:{3}} {4:{5}} {6:{7}} |".format(
693
825
  'Index', col_index_length,
694
- 'Title', col_title_length,
826
+ 'Title', max_title_length,
695
827
  'Progress', col_episodes_length,
696
828
  'Score', col_score_length))
697
829
 
698
830
  # List shows
699
831
  for index, show in showlist:
700
832
  if self.engine.mediainfo['has_progress']:
701
- episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total'])
833
+ episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total'] or '?')
702
834
  else:
703
835
  episodes_str = "-"
704
836
 
705
- # Truncate title if needed
837
+ #Get title (and alt. title) and if need be, truncate it
706
838
  title_str = show['title']
839
+ if altnames.get(show['id']):
840
+ title_str += "[{}]".format(altnames.get(show['id']))
707
841
  title_str = title_str[:max_title_length] if len(title_str) > max_title_length else title_str
708
842
 
709
843
  # Color title according to status
@@ -715,7 +849,7 @@ class Trackma_cmd(cmd.Cmd):
715
849
  print("| {0:^{1}} {2}{3} {4:{5}} {6:^{7}} |".format(
716
850
  index, col_index_length,
717
851
  colored_title,
718
- '.' * (col_title_length-len(show['title'])),
852
+ '.' * (max_title_length-len(title_str)),
719
853
  episodes_str, col_episodes_length,
720
854
  show['my_score'], col_score_length))
721
855
 
@@ -823,13 +957,48 @@ class Trackma_accounts(AccountManager):
823
957
  print("No accounts.")
824
958
 
825
959
 
960
+ def usage():
961
+ print("Usage: trackma [options]")
962
+ print()
963
+ print("Options:")
964
+ print(" -a --account\tPre-selects account number")
965
+ print(" -d --debug\tShows debugging information")
966
+ print(" -h --help\tShows this help")
967
+ print()
968
+ print("Example:")
969
+ print(" trackma -a3")
970
+ print("or:")
971
+ print(" trackma --account=3")
972
+ sys.exit()
973
+
826
974
  def main():
827
- main_cmd = Trackma_cmd()
975
+ # Process args
976
+ debug = False
977
+ account_num = None
978
+
979
+ try:
980
+ opts, args = getopt.getopt(sys.argv[1:], "ha:d", ["help", "account=", "debug"])
981
+ except getopt.GetoptError as err:
982
+ print(err)
983
+ usage()
984
+
985
+ for o, a in opts:
986
+ if o in ('-a', '--account'):
987
+ print("Using account {}.".format(a))
988
+ account_num = a
989
+ elif o in ('-d', '--debug'):
990
+ print("Enabling debug messages.")
991
+ debug = True
992
+ elif o in ('-h', '--help'):
993
+ usage()
994
+
995
+ # Boot Trackma CLI
996
+ main_cmd = Trackma_cmd(account_num, debug)
828
997
  try:
829
998
  main_cmd.start()
830
999
  main_cmd.cmdloop()
831
1000
  except utils.TrackmaFatal as e:
832
- print("%s%s: %s%s" % (_COLOR_FATAL, type(e), e, _COLOR_RESET))
1001
+ print("%s%s: %s%s" % (_COLOR_FATAL, type(e).__name__, e, _COLOR_RESET))
833
1002
 
834
1003
  if __name__ == '__main__':
835
1004
  main()