Skip to content

Commit

Permalink
Merge pull request #4 from sharkykh/feature/paused-at
Browse files Browse the repository at this point in the history
Redesign & add "Paused At" info
  • Loading branch information
sharkykh committed Jan 10, 2019
2 parents d1a69f0 + 0e18a58 commit e76d38e
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ python main.pyw


## Screenshot
![Screenshot](https://cloud.githubusercontent.com/assets/10238474/22926771/be59930e-f2b6-11e6-9f4e-619aa5d1f235.png)
![Screenshot](https://user-images.githubusercontent.com/10238474/50996863-cb4b5680-152b-11e9-9ec3-c21787289594.png)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
six >= 1.11.0
arrow < 1.0.0 , >= 0.10.0
six < 2.0.0, >= 1.11.0
trakt.py == 3.0.0
22 changes: 14 additions & 8 deletions send_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
from __future__ import print_function
from __future__ import unicode_literals

import random

from tppm import Application

from trakt import Trakt


def gen_progress():
return random.uniform(0.0, 100.0)


def send_test_data():
Trakt['scrobble'].pause(movie={'ids': {'tmdb': 118340}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5761493}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5951173}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5950264}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5966778}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5966780}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5940102}})
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 6636942}})
Trakt['scrobble'].pause(movie={'ids': {'tmdb': 118340}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5761493}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5951173}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5950264}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5966778}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5966780}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 5940102}}, progress=gen_progress())
Trakt['scrobble'].pause(episode={'ids': {'tvdb': 6636942}}, progress=gen_progress())

print('Test data sent.')

Expand Down
31 changes: 27 additions & 4 deletions tppm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import webbrowser
from operator import itemgetter

import arrow

import six.moves.tkinter as Tk
import six.moves.tkinter_messagebox as tk_messagebox
from six import itervalues
Expand All @@ -24,7 +26,7 @@
set_icon
)

__version__ = '0.6'
__version__ = '0.7'

TRAKT_APP = {
'name': 'Playback Progress Manager',
Expand Down Expand Up @@ -83,6 +85,16 @@ def destroy(self):
class MainScreen(MainUI):
""" Main UI extension """

def _open_repo(self, event):
confirm = tk_messagebox.askokcancel(
None,
'Open the GitHub repository?'
)
if not confirm:
return False

webbrowser.open_new_tab('https://github.com/sharkykh/TraktPlaybackProgressManager')

# Auth & Login
def hide_auth_button(self):
""" Hide auth button """
Expand Down Expand Up @@ -116,7 +128,8 @@ def _listbox_onselect(self, event):

# (De)Select All
def _btn_toggle_selection_command(self):
multiple = len(self._listbox.curselection()) > 1
one_option = len(self.root.playback_ids) == 1
multiple = len(self._listbox.curselection()) > (0 if one_option else 1)
action = 'selection_clear' if multiple else 'selection_set'
getattr(self._listbox, action)(0, Tk.END)
self._listbox.event_generate('<<ListboxSelect>>')
Expand Down Expand Up @@ -226,7 +239,7 @@ def main(self):
def _fetch_list(self):
if not self.authorization:
tk_messagebox.showwarning('Error', 'Authentication required.')
return []
raise auth.NotAuthenticatedError()

def make_items(data):
for obj in itervalues(playback):
Expand All @@ -249,7 +262,11 @@ def refresh_list(self, local=False):
"""
self.main_win.listbox_clear_all() # Clear
if not local:
self.playback_ids = self._fetch_list()
try:
self.playback_ids = self._fetch_list()
except auth.NotAuthenticatedError:
self.playback_ids = []
return False

if not self.playback_ids:
if not local:
Expand Down Expand Up @@ -289,13 +306,16 @@ def update_info(self, newinfo):
:param newinfo: Episode or Movie item from playback_ids
"""
if len(newinfo) == 1:
paused_at = arrow.get(newinfo[0].paused_at).to('local').format('YYYY-MM-DD HH:mm:ss ZZ')

if isinstance(newinfo[0], Episode):
self.main_win.lbl_showName.set('Show:')
self.main_win.lbl_season.set('Season:')
self.main_win.lbl_episode.set('Episode:')
self.main_win.lbl_episodeTitle.set('Title:')

self.main_win.txt_ID.set(newinfo[0].id)
self.main_win.txt_paused_at.set(paused_at)
self.main_win.txt_progress.set('%0.f%%' % newinfo[0].progress)
self.main_win.txt_showName.set(newinfo[0].show.title)
self.main_win.txt_season.set(newinfo[0].pk[0])
Expand All @@ -309,6 +329,7 @@ def update_info(self, newinfo):
self.main_win.lbl_episodeTitle.set('')

self.main_win.txt_ID.set(newinfo[0].id)
self.main_win.txt_paused_at.set(paused_at)
self.main_win.txt_progress.set('%0.f%%' % newinfo[0].progress)
self.main_win.txt_showName.set(newinfo[0].title)
self.main_win.txt_season.set(newinfo[0].year)
Expand All @@ -322,6 +343,7 @@ def update_info(self, newinfo):
self.main_win.lbl_episodeTitle.set('Title:')

self.main_win.txt_ID.set('')
self.main_win.txt_paused_at.set('')
self.main_win.txt_progress.set('')
self.main_win.txt_showName.set('')
self.main_win.txt_season.set('')
Expand All @@ -335,6 +357,7 @@ def update_info(self, newinfo):
self.main_win.lbl_episodeTitle.set('Title:')

self.main_win.txt_ID.set('<Multiple>')
self.main_win.txt_paused_at.set('<Multiple>')
self.main_win.txt_progress.set('<Multiple>')
self.main_win.txt_showName.set('<Multiple>')
self.main_win.txt_season.set('<Multiple>')
Expand Down
4 changes: 4 additions & 0 deletions tppm/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ def load(path):
return json.load(fh)
except ValueError:
return None


class NotAuthenticatedError(Exception):
pass

0 comments on commit e76d38e

Please sign in to comment.