Skip to content

Commit

Permalink
move countdown from urlresolver into common.addon
Browse files Browse the repository at this point in the history
did a little tidying up and add docs while i was at it.
  • Loading branch information
t0mm0 committed Oct 30, 2011
1 parent 196648e commit 4f92b2d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
60 changes: 60 additions & 0 deletions script.module.t0mm0.common/lib/t0mm0/common/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,67 @@ def show_small_popup(self, title='', msg='', delay=5000, image=''):
'''
xbmc.executebuiltin('XBMC.Notification("%s","%s",%d,"%s")' %
(title, msg, delay, image))


def show_countdown(self, time_to_wait, title='', text=''):
'''
Show a countdown dialog with a progress bar for XBMC while delaying
execution. Necessary for some filehosters eg. megaupload
The original version of this code came from Anarchintosh.
Args:
time_to_wait (int): number of seconds to pause for.
Kwargs:
title (str): Displayed in the title of the countdown dialog. Default
is blank.
text (str): A line of text to be displayed in the dialog. Default
is blank.
Returns:
``True`` if countdown is allowed to complete, ``False`` if the
user cancelled the countdown.
'''

dialog = xbmcgui.DialogProgress()
ret = dialog.create(title)

self.log_notice('waiting %d secs' % time_to_wait)

secs = 0
increment = 100 / time_to_wait

cancelled = False
while secs <= time_to_wait:

if (dialog.iscanceled()):
cancelled = True
break

if secs != 0:
xbmc.sleep(1000)

secs_left = time_to_wait - secs
if secs_left == 0:
percent = 100
else:
percent = increment * secs

remaining_display = ('Wait %d seconds for the ' +
'video stream to activate...') % secs_left
dialog.update(percent, text, remaining_display)

secs += 1

if cancelled == True:
self.log_notice('countdown cancelled')
return False
else:
self.log_debug('countdown finished waiting')
return True


def show_settings(self):
'''Shows the settings dialog for this addon.'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import urllib2

from lib import _megaupload
from urlresolver.countdown import countdown
from urlresolver.plugnplay.interfaces import UrlResolver
from urlresolver.plugnplay.interfaces import SiteAuth
from urlresolver.plugnplay.interfaces import PluginSettings
Expand Down Expand Up @@ -52,11 +51,10 @@ def get_media_url(self, host, media_id):
common.addon.log_debug('login type: %s' % self.login_type)
ok = True
if self.login_type == 'free':
ok = countdown(25, title='megaupload',
text='loading video from free account')
ok = common.addon.show_countdown(25, title='megaupload', text='loading video from free account')
elif not self.login_type:
ok = countdown(45, title='megaupload',
text='loading video with no account')
ok = common.addon.show_countdown(45, title='megaupload',
text='loading video with no account')
if ok:
return media_url[0]
else:
Expand Down

0 comments on commit 4f92b2d

Please sign in to comment.