trackma 0.7__py3.4.egg → 0.7.1__py3.4.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.
EGG-INFO/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: Trackma
3
- Version: 0.7
3
+ Version: 0.7.1
4
4
  Summary: Open multi-site list manager
5
5
  Home-page: https://github.com/z411/trackma
6
6
  Author: z411
EGG-INFO/SOURCES.txt CHANGED
@@ -40,6 +40,7 @@ trackma/lib/libshikimori.py
40
40
  trackma/lib/libvndb.py
41
41
  trackma/tracker/__init__.py
42
42
  trackma/tracker/inotify.py
43
+ trackma/tracker/inotifyBase.py
43
44
  trackma/tracker/plex.py
44
45
  trackma/tracker/polling.py
45
46
  trackma/tracker/pyinotify.py
EGG-INFO/requires.txt CHANGED
@@ -1,10 +1,8 @@
1
1
 
2
2
  [GTK]
3
3
  pygobject
4
- Pillow
5
4
 
6
5
  [Qt]
7
- Pillow
8
6
 
9
7
  [curses]
10
8
  urwid
Binary file
Binary file
Binary file
trackma/engine.py CHANGED
@@ -152,7 +152,10 @@ class Engine:
152
152
  if self.config['tracker_update_prompt']:
153
153
  self._emit_signal('prompt_for_update', show, episode)
154
154
  else:
155
- self.set_episode(show['id'], episode)
155
+ try:
156
+ self.set_episode(show['id'], episode)
157
+ except utils.TrackmaError as e:
158
+ self.msg.warn(self.name, "Can't update episode: {}".format(e))
156
159
 
157
160
  def _tracker_unrecognised(self, show_title, episode):
158
161
  if self.config['tracker_not_found_prompt']:
@@ -190,6 +193,7 @@ class Engine:
190
193
  tracker_list.append({'id': show['id'],
191
194
  'title': show['title'],
192
195
  'my_progress': show['my_progress'],
196
+ 'total': show['total'],
193
197
  'type': None,
194
198
  'titles': self.data_handler.get_show_titles(show),
195
199
  }) # TODO types
@@ -692,6 +696,9 @@ class Engine:
692
696
  return best_candidate[0], best_candidate[2]
693
697
 
694
698
  def get_new_episodes(self, showlist):
699
+ # DEPRECATED !
700
+ self.msg.debug(self.name, "DEPRECATED: get_new_episodes")
701
+
695
702
  results = list()
696
703
  total = len(showlist)
697
704
  t = time.time()
trackma/lib/libkitsu.py CHANGED
@@ -273,7 +273,7 @@ class libkitsu(lib):
273
273
  #"include": self.mediatype, # TODO : This returns a 500 for some reason.
274
274
  "include": "media",
275
275
  # TODO : List for manga should be different
276
- "fields[anime]": "id,slug,canonicalTitle,titles,episodeCount,synopsis,subtype,posterImage",
276
+ "fields[anime]": "id,slug,canonicalTitle,titles,episodeCount,synopsis,subtype,posterImage,startDate,endDate",
277
277
  "page[limit]": "250",
278
278
  }
279
279
 
@@ -329,8 +329,13 @@ class libkitsu(lib):
329
329
  show['url'] = info['url']
330
330
  show['total'] = info['total']
331
331
  show['image'] = info['image']
332
+
332
333
  show['image_thumb'] = info['image_thumb']
333
334
 
335
+ show['start_date'] = info['start_date']
336
+ show['end_date'] = info['end_date']
337
+ show['status'] = info['status']
338
+
334
339
  def request_info(self, item_list):
335
340
  print("These are missing: " + repr(item_list))
336
341
  # TODO implement
@@ -433,14 +438,31 @@ class libkitsu(lib):
433
438
  return json.dumps(values)
434
439
 
435
440
  def _str2date(self, string):
436
- if string != '0000-00-00':
437
- try:
438
- return datetime.datetime.strptime(string, "%Y-%m-%d")
439
- except:
440
- return None # Ignore date if it's invalid
441
- else:
441
+ if string is None:
442
442
  return None
443
443
 
444
+ try:
445
+ return datetime.datetime.strptime(string, "%Y-%m-%d")
446
+ except:
447
+ self.msg.debug(self.name, 'Invalid date {}'.format(string))
448
+ return None # Ignore date if it's invalid
449
+
450
+ def _guess_status(self, start_date, end_date):
451
+ # Try to guess show status by checking start and end dates
452
+ now = datetime.datetime.now()
453
+
454
+ if end_date and end_date < now:
455
+ return utils.STATUS_FINISHED
456
+
457
+ if start_date:
458
+ if start_date > now:
459
+ return utils.STATUS_NOTYET
460
+ else:
461
+ return utils.STATUS_AIRING
462
+
463
+ # Safe to assume dates haven't even been announced yet
464
+ return utils.STATUS_NOTYET
465
+
444
466
  def _parse_info(self, media):
445
467
  info = utils.show()
446
468
  attr = media['attributes']
@@ -450,13 +472,10 @@ class libkitsu(lib):
450
472
 
451
473
  if media['type'] == 'anime':
452
474
  total = attr['episodeCount']
453
- type_str = 'showType'
454
475
  elif media['type'] == 'manga':
455
476
  total = attr['chapterCount']
456
- type_str = 'mangaType'
457
477
  elif media['type'] == 'drama':
458
478
  total = attr['episodeCount'] # TODO Unconfirmed
459
- type_str = 'dramaType'
460
479
 
461
480
  info.update({
462
481
  'id': int(media['id']),
@@ -466,6 +485,8 @@ class libkitsu(lib):
466
485
  'total': total or 0,
467
486
  'image': attr['posterImage']['small'],
468
487
  'image_thumb': attr['posterImage']['tiny'],
488
+ 'start_date': self._str2date(attr['startDate']),
489
+ 'end_date': self._str2date(attr['endDate']),
469
490
  'url': "https://kitsu.io/{}/{}".format(self.mediatype, attr['slug']),
470
491
  'aliases': list(filter(None, attr['titles'].values())),
471
492
  'extra': [
@@ -474,5 +495,13 @@ class libkitsu(lib):
474
495
  ]
475
496
  })
476
497
 
498
+ # WORKAROUND: Shows with 1 episode (TVs, SPs, OVAs) end the same day they start
499
+ if total == 1:
500
+ info['end_date'] = info['start_date']
501
+
502
+ # WORKAROUND: Since there's no way to get the formal status,
503
+ # use the helper function to guess it.
504
+ info['status'] = self._guess_status(info['start_date'], info['end_date'])
505
+
477
506
  return info
478
507
 
@@ -14,69 +14,15 @@
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
  #
16
16
 
17
- import os
18
- import re
19
17
 
20
18
  import inotify.adapters
21
19
  import inotify.constants
22
20
 
23
- from trackma.tracker import tracker
21
+ from trackma.tracker import inotifyBase
24
22
  from trackma import utils
25
23
 
26
- class inotifyTracker(tracker.TrackerBase):
24
+ class inotifyTracker(inotifyBase.inotifyBase):
27
25
  name = 'Tracker (inotify)'
28
- open_pathname = None
29
-
30
- def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
31
- super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
32
-
33
- self.re_players = re.compile(self.process_name.encode('utf-8'))
34
-
35
- def _is_being_played(self, filename):
36
- """
37
- This function makes sure that the filename is being played
38
- by the player specified in players.
39
-
40
- It uses procfs so if we're using inotify that means we're using Linux
41
- thus we should be safe.
42
- """
43
-
44
- for p in os.listdir("/proc/"):
45
- if not p.isdigit(): continue
46
- d = "/proc/%s/fd/" % p
47
- try:
48
- for fd in os.listdir(d):
49
- f = os.readlink(d+fd)
50
- if f == filename:
51
- # Get process name
52
- with open('/proc/%s/cmdline' % p, 'rb') as f:
53
- pname = f.read()
54
-
55
- # Check if it's our process
56
- if self.re_players.match(pname):
57
- return True
58
- except OSError:
59
- pass
60
-
61
- return False
62
-
63
- def _proc_open(self, path, filename):
64
- pathname = "/".join([path, filename])
65
-
66
- if self._is_being_played(pathname):
67
- self.open_pathname = pathname
68
-
69
- (state, show_tuple) = self._get_playing_show(filename)
70
- self.update_show_if_needed(state, show_tuple)
71
-
72
- def _proc_close(self, path, filename):
73
- pathname = "/".join([path, filename])
74
-
75
- if pathname == self.open_pathname:
76
- self.open_pathname = None
77
-
78
- (state, show_tuple) = self._get_playing_show(None)
79
- self.update_show_if_needed(state, show_tuple)
80
26
 
81
27
  def observe(self, watch_dir, interval):
82
28
  # Note that this lib uses bytestrings for filenames and paths.
@@ -0,0 +1,110 @@
1
+ # This file is part of Trackma.
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ import os
18
+ import re
19
+ import time
20
+
21
+ from trackma.tracker import tracker
22
+ from trackma import utils
23
+
24
+ class inotifyBase(tracker.TrackerBase):
25
+ open_file = (None, None, None)
26
+
27
+ def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
28
+ super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
29
+
30
+ self.re_players = re.compile(self.process_name.encode('utf-8'))
31
+
32
+ def _is_being_played(self, filename):
33
+ """
34
+ This function makes sure that the filename is being played
35
+ by the player specified in players.
36
+
37
+ It uses procfs so if we're using inotify that means we're using Linux
38
+ thus we should be safe.
39
+ """
40
+
41
+ for p in os.listdir("/proc/"):
42
+ if not p.isdigit(): continue
43
+ d = "/proc/%s/fd/" % p
44
+ try:
45
+ for fd in os.listdir(d):
46
+ f = os.readlink(d+fd)
47
+ if f == filename:
48
+ # Get process name
49
+ with open('/proc/%s/cmdline' % p, 'rb') as f:
50
+ cmdline = f.read()
51
+ pname = cmdline.partition(b'\x00')[0]
52
+ self.msg.debug(self.name, 'Playing process: {} {} ({})'.format(p, pname, cmdline))
53
+
54
+ # Check if it's our process
55
+ if self.re_players.search(pname):
56
+ return p, fd
57
+ else:
58
+ self.msg.debug(self.name, "Not read by player ({})".format(pname))
59
+ except OSError:
60
+ pass
61
+
62
+ self.msg.debug(self.name, "Couldn't find playing process.")
63
+ return None, None
64
+
65
+ def _closed_handle(self, pid, fd):
66
+ """ Check if this pid has closed this handle (or never opened it) """
67
+ d = "/proc/%s/fd/%s" % (pid, fd)
68
+ return not os.path.islink(d)
69
+
70
+ def _proc_open(self, path, name):
71
+ self.msg.debug(self.name, 'Got OPEN event: {} {}'.format(path, name))
72
+ pathname = os.path.join(path, name)
73
+
74
+ if self.open_file[0]:
75
+ self.msg.debug(self.name, "There's already a tracked open file.")
76
+ return
77
+
78
+ pid, fd = self._is_being_played(pathname)
79
+
80
+ if pid:
81
+ self._emit_signal('detected', path, name)
82
+ self.open_file = (pathname, pid, fd)
83
+
84
+ (state, show_tuple) = self._get_playing_show(name)
85
+ self.msg.debug(self.name, "Got status: {} {}".format(state, show_tuple))
86
+ self.update_show_if_needed(state, show_tuple)
87
+ else:
88
+ self.msg.debug(self.name, "Not played by player, ignoring.")
89
+
90
+ def _proc_close(self, path, name):
91
+ self.msg.debug(self.name, 'Got CLOSE event: {} {}'.format(path, name))
92
+ pathname = os.path.join(path, name)
93
+
94
+ open_pathname, pid, fd = self.open_file
95
+ time.sleep(0.1) # TODO : If we don't wait the filehandle will still be there
96
+
97
+ if pathname != open_pathname:
98
+ self.msg.debug(self.name, "A different file was closed.")
99
+ return
100
+
101
+ if not self._closed_handle(pid, fd):
102
+ self.msg.debug(self.name, "Our pid hasn't closed the file.")
103
+ return
104
+
105
+ self._emit_signal('detected', path, name)
106
+ self.open_file = (None, None, None)
107
+
108
+ (state, show_tuple) = self._get_playing_show(None)
109
+ self.update_show_if_needed(state, show_tuple)
110
+
trackma/tracker/plex.py CHANGED
@@ -32,6 +32,8 @@ class PlexTracker(tracker.TrackerBase):
32
32
 
33
33
  def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
34
34
  self.config = utils.parse_config(utils.get_root_filename('config.json'), utils.config_defaults)
35
+ self.update_wait = update_wait
36
+ self.status_log = [None, None]
35
37
  super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
36
38
 
37
39
  def get_plex_status(self):
@@ -70,19 +72,24 @@ class PlexTracker(tracker.TrackerBase):
70
72
  self.msg.info(self.name, "Using Plex.")
71
73
 
72
74
  while self.active:
73
- status = self.get_plex_status()
75
+ self.status_log.append(self.get_plex_status())
74
76
 
75
- if status == ACTIVE or status == IDLE:
76
- if status == IDLE:
77
- self.msg.info(self.name, "Using Plex.")
77
+ if self.status_log[-1] == ACTIVE or self.status_log[-1] == IDLE:
78
+ if self.status_log[-1] == IDLE and self.status_log[-2] == NOT_RUNNING:
79
+ self.msg.info(self.name, "Reconnected to Plex.")
80
+
81
+ if self.config['plex_obey_update_wait_s']:
82
+ self.wait_s = self.update_wait
83
+ else:
84
+ self.wait_s = self.timer_from_file()
78
85
 
79
- self.wait_s = self.timer_from_file()
80
86
  filename = self.playing_file()
81
87
  (state, show_tuple) = self._get_playing_show(filename)
82
88
  self.update_show_if_needed(state, show_tuple)
83
-
84
- elif status == NOT_RUNNING:
89
+ elif self.status_log[-1] == NOT_RUNNING and self.status_log[-2] == NOT_RUNNING:
85
90
  self.msg.warn(self.name, "Plex Media Server is not running.")
91
+
92
+ del self.status_log[0]
86
93
 
87
94
  # Wait for the interval before running check again
88
95
  time.sleep(interval)
@@ -16,64 +16,12 @@
16
16
 
17
17
  import pyinotify
18
18
 
19
- import os
20
- import re
21
-
22
- from trackma.tracker import tracker
19
+ from trackma.tracker import inotifyBase
23
20
  from trackma import utils
24
21
 
25
- class pyinotifyTracker(tracker.TrackerBase):
22
+ class pyinotifyTracker(inotifyBase.inotifyBase):
26
23
  name = 'Tracker (pyinotify)'
27
24
 
28
- open_pathname = None
29
-
30
- def __init__(self, messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt):
31
- super().__init__(messenger, tracker_list, process_name, watch_dir, interval, update_wait, update_close, not_found_prompt)
32
-
33
- self.re_players = re.compile(self.process_name.encode('utf-8'))
34
-
35
- def _is_being_played(self, filename):
36
- """
37
- This function makes sure that the filename is being played
38
- by the player specified in players.
39
-
40
- It uses procfs so if we're using inotify that means we're using Linux
41
- thus we should be safe.
42
- """
43
-
44
- for p in os.listdir("/proc/"):
45
- if not p.isdigit(): continue
46
- d = "/proc/%s/fd/" % p
47
- try:
48
- for fd in os.listdir(d):
49
- f = os.readlink(d+fd)
50
- if f == filename:
51
- # Get process name
52
- with open('/proc/%s/cmdline' % p, 'rb') as f:
53
- pname = f.read()
54
-
55
- # Check if it's our process
56
- if self.re_players.match(pname):
57
- return True
58
- except OSError:
59
- pass
60
-
61
- return False
62
-
63
- def _proc_open(self, pathname, filename):
64
- if self._is_being_played(pathname):
65
- self.open_pathname = pathname
66
-
67
- (state, show_tuple) = self._get_playing_show(filename)
68
- self.update_show_if_needed(state, show_tuple)
69
-
70
- def _proc_close(self, pathname):
71
- if pathname == self.open_pathname:
72
- self.open_pathname = None
73
-
74
- (state, show_tuple) = self._get_playing_show(None)
75
- self.update_show_if_needed(state, show_tuple)
76
-
77
25
  def observe(self, watch_dir, interval):
78
26
  self.msg.info(self.name, 'Using pyinotify.')
79
27
  wm = pyinotify.WatchManager() # Watch Manager
@@ -91,18 +39,15 @@ class pyinotifyTracker(tracker.TrackerBase):
91
39
 
92
40
  def process_IN_OPEN(self, event):
93
41
  if not event.mask & pyinotify.IN_ISDIR:
94
- self.parent._emit_signal('detected', event.path, event.name)
95
- self.parent._proc_open(event.pathname, event.name)
42
+ self.parent._proc_open(event.path, event.name)
96
43
 
97
44
  def process_IN_CLOSE_NOWRITE(self, event):
98
45
  if not event.mask & pyinotify.IN_ISDIR:
99
- self.parent._emit_signal('detected', event.path, event.name)
100
- self.parent._proc_close(event.pathname)
46
+ self.parent._proc_close(event.path, event.name)
101
47
 
102
48
  def process_IN_CLOSE_WRITE(self, event):
103
49
  if not event.mask & pyinotify.IN_ISDIR:
104
- self.parent._emit_signal('detected', event.path, event.name)
105
- self.parent._proc_close(event.pathname)
50
+ self.parent._proc_close(event.path, event.name)
106
51
 
107
52
  def process_IN_CREATE(self, event):
108
53
  if not event.mask & pyinotify.IN_ISDIR:
@@ -122,6 +67,7 @@ class pyinotifyTracker(tracker.TrackerBase):
122
67
 
123
68
  handler = EventHandler(parent=self)
124
69
  notifier = pyinotify.Notifier(wm, handler)
70
+ self.msg.debug(self.name, 'Watching directory {}'.format(watch_dir))
125
71
  wdd = wm.add_watch(watch_dir, mask, rec=True, auto_add=True)
126
72
 
127
73
  try:
@@ -136,6 +82,7 @@ class pyinotifyTracker(tracker.TrackerBase):
136
82
  else:
137
83
  timeout = 1000 # Check each second for counting
138
84
  else:
85
+ self.msg.debug(self.name, "Sending last state {} {}".format(self.last_state, self.last_show_tuple))
139
86
  self.update_show_if_needed(self.last_state, self.last_show_tuple)
140
87
  finally:
141
88
  notifier.stop()
@@ -121,6 +121,12 @@ class TrackerBase(object):
121
121
  elif action:
122
122
  action()
123
123
 
124
+ def _ignore_current(self):
125
+ # Stops attempt to update current episode
126
+ self.last_updated = True
127
+ self.last_state = utils.TRACKER_IGNORED
128
+ self._emit_signal('state', utils.TRACKER_IGNORED, None)
129
+
124
130
  def _update_state(self, state):
125
131
  # Call when show or state is changed. Perform queued update if any, and clear playing flag.
126
132
  if self.last_close_queue:
@@ -146,10 +152,12 @@ class TrackerBase(object):
146
152
  self._emit_signal('playing', show['id'], True, episode)
147
153
  # Check if we shouldn't update the show
148
154
  if episode != (show['my_progress'] + 1):
149
- self.msg.warn(self.name, 'Player is not playing the next episode of %s. Ignoring.' % show['title'])
150
- self.last_updated = True
151
- self.last_state = utils.TRACKER_IGNORED
152
- self._emit_signal('state', utils.TRACKER_IGNORED, None)
155
+ self.msg.warn(self.name, 'Not playing the next episode of %s. Ignoring.' % show['title'])
156
+ self._ignore_current()
157
+ return
158
+ if episode < 1 or (show['total'] and episode > show['total']):
159
+ self.msg.warn(self.name, 'Playing an invalid episode of %s. Ignoring.' % show['title'])
160
+ self._ignore_current()
153
161
  return
154
162
 
155
163
  # Start our countdown
Binary file
Binary file
Binary file
trackma/ui/cli.py CHANGED
@@ -830,7 +830,7 @@ class Trackma_cmd(cmd.Cmd):
830
830
  # List shows
831
831
  for index, show in showlist:
832
832
  if self.engine.mediainfo['has_progress']:
833
- episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total'])
833
+ episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total'] or '?')
834
834
  else:
835
835
  episodes_str = "-"
836
836
 
trackma/ui/curses.py CHANGED
@@ -1003,7 +1003,7 @@ class ShowWalker(urwid.SimpleListWalker):
1003
1003
  class ShowItem(urwid.WidgetWrap):
1004
1004
  def __init__(self, show, has_progress=True, altname=None, eps=None):
1005
1005
  if has_progress:
1006
- self.episodes_str = urwid.Text("{0:3} / {1}".format(show['my_progress'], show['total']))
1006
+ self.episodes_str = urwid.Text("{0:3} / {1}".format(show['my_progress'], show['total'] or '?'))
1007
1007
  else:
1008
1008
  self.episodes_str = urwid.Text("-")
1009
1009
 
trackma/ui/gtkui.py CHANGED
@@ -1827,7 +1827,7 @@ class Settings(Gtk.Window):
1827
1827
  line0.pack_start(lbl_player, False, False, 5)
1828
1828
  line0.pack_start(self.txt_player, True, True, 0)
1829
1829
  line0.pack_start(playerbrowse_button, False, False, 0)
1830
-
1830
+
1831
1831
  ### Tracker ###
1832
1832
 
1833
1833
  # Labels
@@ -1840,9 +1840,6 @@ class Settings(Gtk.Window):
1840
1840
  lbl_tracker_enabled = Gtk.Label('Enable Tracker')
1841
1841
  lbl_tracker_enabled.set_size_request(120, -1)
1842
1842
  lbl_tracker_enabled.set_xalign(0)
1843
- lbl_tracker_plex_host_port = Gtk.Label('Host and Port')
1844
- lbl_tracker_plex_host_port.set_size_request(120, -1)
1845
- lbl_tracker_plex_host_port.set_xalign(0)
1846
1843
  lbl_tracker_update_wait = Gtk.Label('Wait before update')
1847
1844
  lbl_tracker_update_wait.set_size_request(120, -1)
1848
1845
  lbl_tracker_update_wait.set_xalign(0)
@@ -1858,11 +1855,6 @@ class Settings(Gtk.Window):
1858
1855
  self.browse_button = Gtk.Button('Browse...')
1859
1856
  self.browse_button.connect("clicked", self.__do_browse, 'Select search directory', self.txt_searchdir, True)
1860
1857
  self.chk_tracker_enabled = Gtk.CheckButton()
1861
- self.txt_plex_host = Gtk.Entry()
1862
- self.txt_plex_host.set_max_length(4096)
1863
- self.txt_plex_port = Gtk.Entry()
1864
- self.txt_plex_port.set_max_length(5)
1865
- self.txt_plex_port.set_width_chars(5)
1866
1858
  self.chk_tracker_enabled.connect("toggled", self.tracker_type_sensitive)
1867
1859
  self.spin_tracker_update_wait = Gtk.SpinButton()
1868
1860
  self.spin_tracker_update_wait.set_adjustment(Gtk.Adjustment(value=5, lower=0, upper=500, step_incr=1, page_incr=10))
@@ -1901,11 +1893,6 @@ class Settings(Gtk.Window):
1901
1893
  line2.pack_start(lbl_process, False, False, 5)
1902
1894
  line2.pack_start(self.txt_process, True, True, 0)
1903
1895
 
1904
- line7 = Gtk.HBox(False, 5)
1905
- line7.pack_start(lbl_tracker_plex_host_port, False, False, 5)
1906
- line7.pack_start(self.txt_plex_host, True, True, 0)
1907
- line7.pack_start(self.txt_plex_port, True, True, 0)
1908
-
1909
1896
  line3 = Gtk.HBox(False, 5)
1910
1897
  line3.pack_start(lbl_tracker_enabled, False, False, 5)
1911
1898
  line3.pack_start(self.chk_tracker_enabled, False, False, 0)
@@ -1921,6 +1908,37 @@ class Settings(Gtk.Window):
1921
1908
  line9.pack_start(lbl_tracker_update_options, False, False, 5)
1922
1909
  line9.pack_start(self.chk_tracker_update_close, False, False, 0)
1923
1910
  line9.pack_start(self.chk_tracker_update_prompt, False, False, 0)
1911
+
1912
+ ### Plex ###
1913
+ header6 = Gtk.Label()
1914
+ header6.set_text('<b>Plex Media Server</b>')
1915
+ header6.set_use_markup(True)
1916
+ header6.set_xalign(0)
1917
+
1918
+ # Labels
1919
+ lbl_tracker_plex_host_port = Gtk.Label('Host and Port')
1920
+ lbl_tracker_plex_host_port.set_size_request(120, -1)
1921
+ lbl_tracker_plex_host_port.set_xalign(0)
1922
+ lbl_tracker_plex_obey_wait = Gtk.Label('Use "wait before update" time')
1923
+ lbl_tracker_plex_obey_wait.set_size_request(120, -1)
1924
+ lbl_tracker_plex_obey_wait.set_xalign(0)
1925
+
1926
+ # Entries
1927
+ self.txt_plex_host = Gtk.Entry()
1928
+ self.txt_plex_host.set_max_length(4096)
1929
+ self.txt_plex_port = Gtk.Entry()
1930
+ self.txt_plex_port.set_max_length(5)
1931
+ self.txt_plex_port.set_width_chars(5)
1932
+ self.chk_tracker_plex_obey_wait = Gtk.CheckButton()
1933
+
1934
+ # HBoxes
1935
+ line7 = Gtk.HBox(False, 5)
1936
+ line7.pack_start(lbl_tracker_plex_host_port, False, False, 5)
1937
+ line7.pack_start(self.txt_plex_host, True, True, 0)
1938
+ line7.pack_start(self.txt_plex_port, True, True, 0)
1939
+ line10 = Gtk.HBox(False, 5)
1940
+ line10.pack_start(lbl_tracker_plex_obey_wait, False, False, 5)
1941
+ line10.pack_start(self.chk_tracker_plex_obey_wait, False, False, 0)
1924
1942
 
1925
1943
  ### Auto-retrieve ###
1926
1944
  header2 = Gtk.Label()
@@ -2090,9 +2108,11 @@ class Settings(Gtk.Window):
2090
2108
  page0.pack_start(line3, False, False, 0)
2091
2109
  page0.pack_start(line1, False, False, 0)
2092
2110
  page0.pack_start(line2, False, False, 0)
2093
- page0.pack_start(line7, False, False, 0)
2094
2111
  page0.pack_start(line8, False, False, 0)
2095
2112
  page0.pack_start(line9, False, False, 0)
2113
+ page0.pack_start(header6, False, False, 0)
2114
+ page0.pack_start(line7, False, False, 0)
2115
+ page0.pack_start(line10, False, False, 0)
2096
2116
 
2097
2117
  page1 = Gtk.VBox(False, 10)
2098
2118
  page1.set_border_width(10)
@@ -2126,6 +2146,7 @@ class Settings(Gtk.Window):
2126
2146
  self.txt_searchdir.set_text(self.engine.get_config('searchdir'))
2127
2147
  self.txt_plex_host.set_text(self.engine.get_config('plex_host'))
2128
2148
  self.txt_plex_port.set_text(self.engine.get_config('plex_port'))
2149
+ self.chk_tracker_plex_obey_wait.set_active(self.engine.get_config('plex_obey_update_wait_s'))
2129
2150
  self.chk_tracker_enabled.set_active(self.engine.get_config('tracker_enabled'))
2130
2151
  self.rbtn_autosend_at_exit.set_active(self.engine.get_config('autosend_at_exit'))
2131
2152
  self.spin_tracker_update_wait.set_value(self.engine.get_config('tracker_update_wait_s'))
@@ -2136,6 +2157,7 @@ class Settings(Gtk.Window):
2136
2157
  self.rbtn_tracker_local.set_active(True)
2137
2158
  self.txt_plex_host.set_sensitive(False)
2138
2159
  self.txt_plex_port.set_sensitive(False)
2160
+ self.chk_tracker_plex_obey_wait.set_sensitive(False)
2139
2161
  elif self.engine.get_config('tracker_type') == 'plex':
2140
2162
  self.rbtn_tracker_plex.set_active(True)
2141
2163
  self.txt_process.set_sensitive(False)
@@ -2175,6 +2197,7 @@ class Settings(Gtk.Window):
2175
2197
  self.engine.set_config('searchdir', self.txt_searchdir.get_text())
2176
2198
  self.engine.set_config('plex_host', self.txt_plex_host.get_text())
2177
2199
  self.engine.set_config('plex_port', self.txt_plex_port.get_text())
2200
+ self.engine.set_config('plex_obey_update_wait_s', self.chk_tracker_plex_obey_wait.get_active())
2178
2201
  self.engine.set_config('tracker_enabled', self.chk_tracker_enabled.get_active())
2179
2202
  self.engine.set_config('autosend_at_exit', self.rbtn_autosend_at_exit.get_active())
2180
2203
  self.engine.set_config('tracker_update_wait_s', self.spin_tracker_update_wait.get_value())
@@ -2243,9 +2266,11 @@ class Settings(Gtk.Window):
2243
2266
  self.txt_process.set_sensitive(True)
2244
2267
  self.txt_plex_host.set_sensitive(False)
2245
2268
  self.txt_plex_port.set_sensitive(False)
2269
+ self.chk_tracker_plex_obey_wait.set_sensitive(False)
2246
2270
  elif self.rbtn_tracker_plex.get_active():
2247
2271
  self.txt_plex_host.set_sensitive(True)
2248
2272
  self.txt_plex_port.set_sensitive(True)
2273
+ self.chk_tracker_plex_obey_wait.set_sensitive(True)
2249
2274
  self.txt_process.set_sensitive(False)
2250
2275
  self.spin_tracker_update_wait.set_sensitive(True)
2251
2276
  else:
@@ -2253,6 +2278,7 @@ class Settings(Gtk.Window):
2253
2278
  self.spin_tracker_update_wait.set_sensitive(False)
2254
2279
  self.txt_plex_host.set_sensitive(False)
2255
2280
  self.txt_plex_port.set_sensitive(False)
2281
+ self.chk_tracker_plex_obey_wait.set_sensitive(False)
2256
2282
 
2257
2283
  def __do_browse(self, widget, title, entry, dironly=False):
2258
2284
  browsew = Gtk.FileChooserDialog(title,
trackma/ui/qtui.py CHANGED
@@ -109,9 +109,11 @@ class Trackma(QMainWindow):
109
109
  Main GUI class
110
110
 
111
111
  """
112
+ debug = False
112
113
  config = None
113
114
  tray = None
114
115
  accountman = None
116
+ accountman_widget = None
115
117
  worker = None
116
118
  image_worker = None
117
119
  started = False
@@ -120,8 +122,9 @@ class Trackma(QMainWindow):
120
122
  finish = False
121
123
  was_maximized = False
122
124
 
123
- def __init__(self):
125
+ def __init__(self, debug=False):
124
126
  QMainWindow.__init__(self, None)
127
+ self.debug = debug
125
128
 
126
129
  # Load QT specific configuration
127
130
  self.configfile = utils.get_root_filename('ui-qt.json')
@@ -141,9 +144,12 @@ class Trackma(QMainWindow):
141
144
  if default:
142
145
  self.start(default)
143
146
  else:
144
- self.accountman_widget = AccountDialog(None, self.accountman)
145
- self.accountman_widget.selected.connect(self.accountman_selected)
146
- self.accountman_widget.show()
147
+ self.accountman_create()
148
+ accountman_widget.show()
149
+
150
+ def accountman_create(self):
151
+ self.accountman_widget = AccountDialog(None, self.accountman)
152
+ self.accountman_widget.selected.connect(self.accountman_selected)
147
153
 
148
154
  def accountman_selected(self, account_num, remember):
149
155
  account = self.accountman.get_account(account_num)
@@ -480,7 +486,7 @@ class Trackma(QMainWindow):
480
486
  self._tray()
481
487
 
482
488
  # Connect worker signals
483
- self.worker.changed_status.connect(self.status)
489
+ self.worker.changed_status.connect(self.ws_changed_status)
484
490
  self.worker.raised_error.connect(self.error)
485
491
  self.worker.raised_fatal.connect(self.fatal)
486
492
  self.worker.changed_show.connect(self.ws_changed_show)
@@ -733,7 +739,7 @@ class Trackma(QMainWindow):
733
739
  title_str = show['title']
734
740
  if altname:
735
741
  title_str += " [%s]" % altname
736
- progress_str = "%d / %d" % (show['my_progress'], show['total'])
742
+ progress_str = "{} / {}".format(show['my_progress'], show['total'] or '?')
737
743
  percent_widget = EpisodeBar(self, self.config['colors'])
738
744
  percent_widget.setRange(0, 100)
739
745
  percent_widget.setBarStyle(self.config['episodebar_style'], self.config['episodebar_text'])
@@ -840,7 +846,7 @@ class Trackma(QMainWindow):
840
846
  # Regenerate Play Episode Menu
841
847
  self.generate_episode_menus(self.menu_play, show['total'], show['my_progress'])
842
848
  else:
843
- self.show_progress.setMaximum(utils.estimate_aired_episodes(show))
849
+ self.show_progress.setMaximum(utils.estimate_aired_episodes(show) or 10000)
844
850
  self.generate_episode_menus(self.menu_play, utils.estimate_aired_episodes(show),show['my_progress'])
845
851
 
846
852
  # Update information
@@ -1168,11 +1174,14 @@ class Trackma(QMainWindow):
1168
1174
  ep_default = 1
1169
1175
  ep_min = 1
1170
1176
  ep_max = utils.estimate_aired_episodes(show)
1171
- if ep_max is None:
1172
- ep_max = max(show['total'],1)
1177
+ if not ep_max:
1178
+ # If we don't know the total just allow anything
1179
+ ep_max = show['total'] or 10000
1180
+
1173
1181
  episode, ok = QInputDialog.getInt(self, 'Play Episode',
1174
1182
  'Enter an episode number of %s to play:' % show['title'],
1175
1183
  ep_default, ep_min, ep_max)
1184
+
1176
1185
  if ok:
1177
1186
  self.s_play(False, episode)
1178
1187
 
@@ -1210,7 +1219,7 @@ class Trackma(QMainWindow):
1210
1219
  if queue:
1211
1220
  reply = QMessageBox.question(self, 'Confirmation',
1212
1221
  'There are %d unsynced changes. Do you want to send them first? (Choosing No will discard them!)' % len(queue),
1213
- QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel)
1222
+ QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
1214
1223
 
1215
1224
  if reply == QMessageBox.Yes:
1216
1225
  self.s_send(True)
@@ -1229,6 +1238,9 @@ class Trackma(QMainWindow):
1229
1238
  self.worker_call('list_upload', self.r_generic_ready)
1230
1239
 
1231
1240
  def s_switch_account(self):
1241
+ if not self.accountman_widget:
1242
+ self.accountman_create()
1243
+
1232
1244
  self.accountman_widget.setModal(True)
1233
1245
  self.accountman_widget.show()
1234
1246
 
@@ -1302,6 +1314,12 @@ class Trackma(QMainWindow):
1302
1314
  showlist.setColumnWidth(index, MIN_WIDTH)
1303
1315
 
1304
1316
  ### Worker slots
1317
+ def ws_changed_status(self, classname, msgtype, msg):
1318
+ if msgtype != messenger.TYPE_DEBUG:
1319
+ self.status('{}: {}'.format(classname, msg))
1320
+ elif self.debug:
1321
+ print('[D] {}: {}'.format(classname, msg))
1322
+
1305
1323
  def ws_changed_show(self, show, is_playing=False, episode=None, altname=None):
1306
1324
  if show:
1307
1325
  if not self.show_lists:
@@ -1784,8 +1802,6 @@ class SettingsDialog(QDialog):
1784
1802
  self.tracker_type_local.toggled.connect(self.tracker_type_change)
1785
1803
  self.tracker_type_plex = QRadioButton('Plex media server')
1786
1804
  self.tracker_type_plex.toggled.connect(self.tracker_type_change)
1787
- self.plex_host = QLineEdit()
1788
- self.plex_port = QLineEdit()
1789
1805
  self.tracker_interval = QSpinBox()
1790
1806
  self.tracker_interval.setRange(5, 1000)
1791
1807
  self.tracker_interval.setMaximumWidth(60)
@@ -1802,8 +1818,6 @@ class SettingsDialog(QDialog):
1802
1818
  g_media_layout.addRow(self.tracker_type_plex)
1803
1819
  g_media_layout.addRow('Tracker interval (seconds)', self.tracker_interval)
1804
1820
  g_media_layout.addRow('Process name (regex)', self.tracker_process)
1805
- g_media_layout.addRow('Plex host', self.plex_host)
1806
- g_media_layout.addRow('Plex port', self.plex_port)
1807
1821
  g_media_layout.addRow('Wait before updating (seconds)', self.tracker_update_wait)
1808
1822
  g_media_layout.addRow('Wait until the player is closed', self.tracker_update_close)
1809
1823
  g_media_layout.addRow('Ask before updating', self.tracker_update_prompt)
@@ -1811,6 +1825,22 @@ class SettingsDialog(QDialog):
1811
1825
 
1812
1826
  g_media.setLayout(g_media_layout)
1813
1827
 
1828
+ # Group: Plex settings
1829
+ g_plex = QGroupBox('Plex Media Server')
1830
+ g_plex.setFlat(True)
1831
+ self.plex_host = QLineEdit()
1832
+ self.plex_port = QLineEdit()
1833
+ self.plex_obey_wait = QCheckBox()
1834
+
1835
+ g_plex_layout = QGridLayout()
1836
+ g_plex_layout.addWidget(QLabel('Host and Port'), 0, 0, 1, 1)
1837
+ g_plex_layout.addWidget(self.plex_host, 0, 1, 1, 1)
1838
+ g_plex_layout.addWidget(self.plex_port, 0, 2, 1, 2)
1839
+ g_plex_layout.addWidget(QLabel('Use "wait before updating" time'), 1, 0, 1, 1)
1840
+ g_plex_layout.addWidget(self.plex_obey_wait, 1, 2, 1, 1)
1841
+
1842
+ g_plex.setLayout(g_plex_layout)
1843
+
1814
1844
  # Group: Play Next
1815
1845
  g_playnext = QGroupBox('Play Next')
1816
1846
  g_playnext.setFlat(True)
@@ -1836,6 +1866,7 @@ class SettingsDialog(QDialog):
1836
1866
 
1837
1867
  # Media form
1838
1868
  page_media_layout.addWidget(g_media)
1869
+ page_media_layout.addWidget(g_plex)
1839
1870
  page_media_layout.addWidget(g_playnext)
1840
1871
  page_media.setLayout(page_media_layout)
1841
1872
 
@@ -2076,11 +2107,13 @@ class SettingsDialog(QDialog):
2076
2107
  self.library_autoscan.setChecked(engine.get_config('library_autoscan'))
2077
2108
  self.plex_host.setText(engine.get_config('plex_host'))
2078
2109
  self.plex_port.setText(engine.get_config('plex_port'))
2110
+ self.plex_obey_wait.setChecked(engine.get_config('plex_obey_update_wait_s'))
2079
2111
 
2080
2112
  if tracker_type == 'local':
2081
2113
  self.tracker_type_local.setChecked(True)
2082
2114
  self.plex_host.setEnabled(False)
2083
2115
  self.plex_port.setEnabled(False)
2116
+ self.plex_obey_wait.setEnabled(False)
2084
2117
  elif tracker_type == 'plex':
2085
2118
  self.tracker_type_plex.setChecked(True)
2086
2119
  self.tracker_process.setEnabled(False)
@@ -2150,6 +2183,7 @@ class SettingsDialog(QDialog):
2150
2183
  engine.set_config('library_autoscan', self.library_autoscan.isChecked())
2151
2184
  engine.set_config('plex_host', self.plex_host.text())
2152
2185
  engine.set_config('plex_port', self.plex_port.text())
2186
+ engine.set_config('plex_obey_update_wait_s', self.plex_obey_wait.isChecked())
2153
2187
 
2154
2188
  if self.tracker_type_local.isChecked():
2155
2189
  engine.set_config('tracker_type', 'local')
@@ -2218,15 +2252,18 @@ class SettingsDialog(QDialog):
2218
2252
  self.tracker_process.setEnabled(True)
2219
2253
  self.plex_host.setEnabled(False)
2220
2254
  self.plex_port.setEnabled(False)
2255
+ self.plex_obey_wait.setEnabled(False)
2221
2256
  elif self.tracker_type_plex.isChecked():
2222
2257
  self.plex_host.setEnabled(True)
2223
2258
  self.plex_port.setEnabled(True)
2259
+ self.plex_obey_wait.setEnabled(True)
2224
2260
  self.tracker_process.setEnabled(False)
2225
2261
  else:
2226
2262
  self.tracker_type_local.setEnabled(False)
2227
2263
  self.tracker_type_plex.setEnabled(False)
2228
2264
  self.plex_host.setEnabled(False)
2229
2265
  self.plex_port.setEnabled(False)
2266
+ self.plex_obey_wait.setEnabled(False)
2230
2267
  self.tracker_process.setEnabled(False)
2231
2268
  self.tracker_interval.setEnabled(False)
2232
2269
  self.tracker_update_wait.setEnabled(False)
@@ -2864,7 +2901,7 @@ class Engine_Worker(QtCore.QThread):
2864
2901
  finished = QtCore.pyqtSignal(dict)
2865
2902
 
2866
2903
  # Message handler signals
2867
- changed_status = QtCore.pyqtSignal(str)
2904
+ changed_status = QtCore.pyqtSignal(str, int, str)
2868
2905
  raised_error = QtCore.pyqtSignal(str)
2869
2906
  raised_fatal = QtCore.pyqtSignal(str)
2870
2907
 
@@ -2914,7 +2951,7 @@ class Engine_Worker(QtCore.QThread):
2914
2951
  }
2915
2952
 
2916
2953
  def _messagehandler(self, classname, msgtype, msg):
2917
- self.changed_status.emit("%s: %s" % (classname, msg))
2954
+ self.changed_status.emit(classname, msgtype, msg)
2918
2955
 
2919
2956
  def _error(self, msg):
2920
2957
  self.raised_error.emit(str(msg))
@@ -3142,9 +3179,23 @@ def getColor(colorString):
3142
3179
 
3143
3180
 
3144
3181
  def main():
3182
+ debug = False
3183
+
3184
+ print("Trackma-qt v{}".format(utils.VERSION))
3185
+
3186
+ if '-h' in sys.argv:
3187
+ print("Usage: trackma-qt [options]")
3188
+ print()
3189
+ print('Options:')
3190
+ print(' -d Shows debugging information')
3191
+ print(' -h Shows this help')
3192
+ return
3193
+ if '-d' in sys.argv:
3194
+ debug = True
3195
+
3145
3196
  app = QApplication(sys.argv)
3146
3197
  try:
3147
- mainwindow = Trackma()
3198
+ mainwindow = Trackma(debug)
3148
3199
  sys.exit(app.exec_())
3149
3200
  except utils.TrackmaFatal as e:
3150
3201
  QMessageBox.critical(None, 'Fatal Error', "{0}".format(e), QMessageBox.Ok)
trackma/utils.py CHANGED
@@ -21,7 +21,7 @@ import json
21
21
  import difflib
22
22
  import pickle
23
23
 
24
- VERSION = '0.7'
24
+ VERSION = '0.7.1'
25
25
 
26
26
  datadir = os.path.dirname(__file__)
27
27
  LOGIN_PASSWD = 1
@@ -287,6 +287,7 @@ config_defaults = {
287
287
  'tracker_type': "local",
288
288
  'plex_host': "localhost",
289
289
  'plex_port': "32400",
290
+ 'plex_obey_update_wait_s': False,
290
291
  }
291
292
  userconfig_defaults = {
292
293
  'mediatype': '',