Example #1
0
def do_disable_check():
    scrapers = relevant_scrapers()
    auto_disable = kodi.get_setting('auto-disable')
    check_freq = int(kodi.get_setting('disable-freq'))
    disable_thresh = int(kodi.get_setting('disable-thresh'))
    for cls in scrapers:
        last_check = db_connection.get_setting('%s_check' % (cls.get_name()))
        last_check = int(last_check) if last_check else 0
        tries = kodi.get_setting('%s_try' % (cls.get_name()))
        tries = int(tries) if tries else 0
        if tries > 0 and tries / check_freq > last_check / check_freq:
            kodi.set_setting('%s_check' % (cls.get_name()), str(tries))
            success_rate = calculate_success(cls.get_name())
            if success_rate < disable_thresh:
                if auto_disable == DISABLE_SETTINGS.ON:
                    kodi.set_setting('%s-enable' % (cls.get_name()), 'false')
                    kodi.notify(msg='[COLOR blue]%s[/COLOR] %s' % (i18n('scraper_disabled')), duration=5000)
                elif auto_disable == DISABLE_SETTINGS.PROMPT:
                    dialog = xbmcgui.Dialog()
                    line1 = i18n('disable_line1') % (cls.get_name(), 100 - success_rate, tries)
                    line2 = i18n('disable_line2')
                    line3 = i18n('disable_line3')
                    ret = dialog.yesno('SALTS', line1, line2, line3, i18n('keep_enabled'), i18n('disable_it'))
                    if ret:
                        kodi.set_setting('%s-enable' % (cls.get_name()), 'false')
Example #2
0
def do_disable_check():
    scrapers = relevant_scrapers()
    auto_disable = ADDON.get_setting('auto-disable')
    check_freq = int(ADDON.get_setting('disable-freq'))
    disable_thresh = int(ADDON.get_setting('disable-thresh'))
    for cls in scrapers:
        last_check = db_connection.get_setting('%s_check' % (cls.get_name()))
        last_check = int(last_check) if last_check else 0
        tries = ADDON.get_setting('%s_try' % (cls.get_name()))
        tries = int(tries) if tries else 0
        if tries > 0 and tries / check_freq > last_check / check_freq:
            ADDON.set_setting('%s_check' % (cls.get_name()), str(tries))
            success_rate = calculate_success(cls.get_name())
            if success_rate < disable_thresh:
                if auto_disable == DISABLE_SETTINGS.ON:
                    ADDON.set_setting('%s-enable' % (cls.get_name()), 'false')
                    notify(msg='[COLOR blue]%s[/COLOR] %s' % (i18n('scraper_disabled')), duration=5000)
                elif auto_disable == DISABLE_SETTINGS.PROMPT:
                    dialog = xbmcgui.Dialog()
                    line1 = i18n('disable_line1') % (cls.get_name(), 100 - success_rate, tries)
                    line2 = i18n('disable_line2')
                    line3 = i18n('disable_line3')
                    ret = dialog.yesno('SALTS', line1, line2, line3, i18n('keep_enabled'), i18n('disable_it'))
                    if ret:
                        ADDON.set_setting('%s-enable' % (cls.get_name()), 'false')
Example #3
0
def get_resume_choice(trakt_id, season, episode):
    if kodi.get_setting("trakt_bookmark") == "true":
        resume_point = "%s%%" % (trakt_api.get_bookmark(trakt_id, season, episode))
        header = i18n("trakt_bookmark_exists")
    else:
        resume_point = format_time(db_connection.get_bookmark(trakt_id, season, episode))
        header = i18n("local_bookmark_exists")
    question = i18n("resume_from") % (resume_point)
    return xbmcgui.Dialog().yesno(header, question, "", "", i18n("start_from_beginning"), i18n("resume")) == 1
Example #4
0
def get_resume_choice(trakt_id, season, episode):
    if kodi.get_setting('trakt_bookmark') == 'true':
        resume_point = '%s%%' % (trakt_api.get_bookmark(trakt_id, season, episode))
        header = i18n('trakt_bookmark_exists')
    else:
        resume_point = format_time(db_connection.get_bookmark(trakt_id, season, episode))
        header = i18n('local_bookmark_exists')
    question = i18n('resume_from') % (resume_point)
    return xbmcgui.Dialog().yesno(header, question, '', '', i18n('start_from_beginning'), i18n('resume')) == 1
Example #5
0
def choose_list(username=None):
    lists = trakt_api.get_lists(username)
    if username is None: lists.insert(0, {'name': 'watchlist', 'ids': {'slug': WATCHLIST_SLUG}})
    if lists:
        dialog = xbmcgui.Dialog()
        index = dialog.select(i18n('pick_a_list'), [list_data['name'] for list_data in lists])
        if index > -1:
            return lists[index]['ids']['slug']
    else:
        kodi.notify(msg=i18n('no_lists_for_user') % (username), duration=5000)
Example #6
0
def choose_list(username=None):
    lists = trakt_api.get_lists(username)
    if username is None:
        lists.insert(0, {"name": "watchlist", "ids": {"slug": WATCHLIST_SLUG}})
    if lists:
        dialog = xbmcgui.Dialog()
        index = dialog.select(i18n("pick_a_list"), [list_data["name"] for list_data in lists])
        if index > -1:
            return lists[index]["ids"]["slug"]
    else:
        kodi.notify(msg=i18n("no_lists_for_user") % (username), duration=5000)
Example #7
0
        def onClick(self, control):
            # print 'onClick: %s' % (control)
            if control == AUTH_BUTTON:
                if not self.__get_token():
                    kodi.notify(msg=i18n('pin_auth_failed'), duration=5000)
                    return
                self.auth = True

            if control == LATER_BUTTON:
                kodi.notify(msg=i18n('remind_in_24hrs'), duration=5000)
                kodi.set_setting('last_reminder', str(int(time.time())))

            if control == NEVER_BUTTON:
                kodi.notify(msg=i18n('use_addon_settings'), duration=5000)
                kodi.set_setting('last_reminder', '-1')

            if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]:
                self.close()
Example #8
0
        def onClick(self, control):
            # print 'onClick: %s' % (control)
            if control == AUTH_BUTTON:
                if not self.__get_token():
                    kodi.notify(msg=i18n('pin_auth_failed'), duration=5000)
                    return
                self.auth = True

            if control == LATER_BUTTON:
                kodi.notify(msg=i18n('remind_in_24hrs'), duration=5000)
                kodi.set_setting('last_reminder', str(int(time.time())))

            if control == NEVER_BUTTON:
                kodi.notify(msg=i18n('use_addon_settings'), duration=5000)
                kodi.set_setting('last_reminder', '-1')

            if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]:
                self.close()
Example #9
0
def parallel_get_url(q, scraper, video):
    worker = threading.current_thread()
    log_utils.log('Worker: %s (%s) for %s url' % (worker.name, worker, scraper.get_name()), log_utils.LOGDEBUG)
    url = scraper.get_url(video)
    log_utils.log('%s returned url %s from %s' % (scraper.get_name(), url, worker), log_utils.LOGDEBUG)
    if not url: url = ''
    if url == FORCE_NO_MATCH:
        label = '[%s] [COLOR green]%s[/COLOR]' % (scraper.get_name(), i18n('force_no_match'))
    else:
        label = '[%s] %s' % (scraper.get_name(), url)
    related = {'class': scraper, 'url': url, 'name': scraper.get_name(), 'label': label}
    q.put(related)
Example #10
0
def get_section_params(section):
    section_params = {}
    section_params['section'] = section
    if section == SECTIONS.TV:
        section_params['next_mode'] = MODES.SEASONS
        section_params['folder'] = True
        section_params['video_type'] = VIDEO_TYPES.TVSHOW
        section_params['content_type'] = CONTENT_TYPES.TVSHOWS
        section_params['search_img'] = 'television_search.png'
        section_params['label_plural'] = i18n('tv_shows')
        section_params['label_single'] = i18n('tv_show')
    else:
        section_params['next_mode'] = MODES.GET_SOURCES
        section_params['folder'] = kodi.get_setting('source-win') == 'Directory' and kodi.get_setting('auto-play') == 'false'
        section_params['video_type'] = VIDEO_TYPES.MOVIE
        section_params['content_type'] = CONTENT_TYPES.MOVIES
        section_params['search_img'] = 'movies_search.png'
        section_params['label_plural'] = i18n('movies')
        section_params['label_single'] = i18n('movie')

    return section_params
Example #11
0
def perform_auto_conf(responses):
    length = len(responses)
    TOTAL = 12
    if length < TOTAL:
        responses += [True] * (TOTAL - length)
        
    if responses[0]: kodi.set_setting('trakt_timeout', '60')
    if responses[1]: kodi.set_setting('calendar-day', '-1')
    if responses[2]: kodi.set_setting('calendar_time', '2')
    if responses[3]: kodi.set_setting('source_timeout', '20')
    if responses[4]: kodi.set_setting('include_watchlist_next', 'true')
    if responses[5]: kodi.set_setting('filter_direct', 'true')
    if responses[6]: kodi.set_setting('filter_unusable', 'true')
    if responses[7]: kodi.set_setting('show_debrid', 'true')
    if responses[8]: kodi.set_setting('source_results', '0')
    if responses[9]:
        kodi.set_setting('enable_sort', 'true')
        kodi.set_setting('sort1_field', '2')
        kodi.set_setting('sort2_field', '5')
        kodi.set_setting('sort3_field', '6')
        kodi.set_setting('sort4_field', '1')
        kodi.set_setting('sort5_field', '3')
        kodi.set_setting('sort6_field', '4')

    if responses[10]:
        tiers = ['Local', 'Furk.net', 'Premiumize.me', 'EasyNews', 'DD.tv', 'NoobRoom',
                 ['WatchHD', 'IFlix', 'MoviesPlanet', 'CyberReel', '9Movies', '123Movies', 'niter.tv', 'ororo.tv'],
                 ['movietv.to', 'StreamLord', 'tunemovie', 'afdah.org', 'xmovies8', 'xmovies8.v2', 'alluc.com'],
                 ['torba.se', 'IzlemeyeDeger', 'Rainierland', 'zumvo.com', 'PutMV', 'MiraDeTodo', 'beinmovie'],
                 ['SezonLukDizi', 'Dizimag', 'Dizilab', 'Dizigold', 'Diziay', 'Dizipas', 'OneClickTVShows'],
                 ['DDLValley', 'ReleaseBB', 'MyVideoLinks.eu', 'OCW', 'RLSSource.net', 'TVRelease.Net'],
                 ['IceFilms', 'PrimeWire', 'Flixanity', 'wso.ch', 'WatchSeries', 'UFlix.org', 'Putlocker', 'MovieHut'],
                 ['funtastic-vids', 'WatchFree.to', 'pftv', 'streamallthis.is', 'Movie4K', 'afdah', 'SolarMovie', 'yify-streaming'],
                 ['CouchTunerV2', 'CouchTunerV1', 'Watch8Now', 'yshows', 'TwoMovies.us', 'iWatchOnline', 'vidics.ch', 'pubfilm'],
                 ['OnlineMoviesIs', 'OnlineMoviesPro', 'ViewMovies', 'movie25', 'viooz.ac', 'view47', 'MoviesHD', 'wmo.ch'],
                 ['ayyex', 'stream-tv.co', 'clickplay.to', 'MintMovies', 'MovieNight', 'cmz', 'ch131', 'filmikz.ch'],
                 ['MovieTube', 'LosMovies', 'FilmStreaming.in', 'moviestorm.eu', 'MerDB'],
                 'MoviesOnline7']
    
        sso = []
        random_sso = kodi.get_setting('random_sso') == 'true'
        for tier in tiers:
            if isinstance(tier, basestring):
                sso.append(tier)
            else:
                if random_sso:
                    random.shuffle(tier)
                sso += tier
        kodi.set_setting('source_sort_order', '|'.join(sso))
    
    if responses[11]: reset_base_url()
    kodi.set_setting('filter-unknown', 'false')
    kodi.notify(msg=i18n('auto_conf_complete'))
Example #12
0
def do_disable_check():
    auto_disable = kodi.get_setting('auto-disable')
    disable_limit = int(kodi.get_setting('disable-limit'))
    for cls in relevant_scrapers():
        setting = '%s_last_results' % (cls.get_name())
        fails = kodi.get_setting(setting)
        fails = int(fails) if fails else 0
        if fails >= disable_limit:
            if auto_disable == DISABLE_SETTINGS.ON:
                kodi.set_setting('%s-enable' % (cls.get_name()), 'false')
                kodi.notify(msg='[COLOR blue]%s[/COLOR] %s' %
                            (cls.get_name(), i18n('scraper_disabled')),
                            duration=5000)
                kodi.set_setting(setting, '0')
            elif auto_disable == DISABLE_SETTINGS.PROMPT:
                dialog = xbmcgui.Dialog()
                line1 = i18n('disable_line1') % (cls.get_name(), fails)
                line2 = i18n('disable_line2')
                line3 = i18n('disable_line3')
                ret = dialog.yesno('SALTS', line1, line2, line3,
                                   i18n('keep_enabled'), i18n('disable_it'))
                if ret:
                    kodi.set_setting('%s-enable' % (cls.get_name()), 'false')
                    kodi.set_setting(setting, '0')
                else:
                    kodi.set_setting(setting, '-1')
Example #13
0
def parallel_get_url(q, scraper, video):
    worker = threading.current_thread()
    log_utils.log("Worker: %s (%s) for %s url" % (worker.name, worker, scraper.get_name()), log_utils.LOGDEBUG)
    url = scraper.get_url(video)
    log_utils.log("%s returned url %s from %s" % (scraper.get_name(), url, worker), log_utils.LOGDEBUG)
    if not url:
        url = ""
    if url == FORCE_NO_MATCH:
        label = "[%s] [COLOR green]%s[/COLOR]" % (scraper.get_name(), i18n("force_no_match"))
    else:
        label = "[%s] %s" % (scraper.get_name(), url)
    related = {"class": scraper, "url": url, "name": scraper.get_name(), "label": label}
    q.put(related)
Example #14
0
def get_section_params(section):
    section_params = {}
    section_params["section"] = section
    if section == SECTIONS.TV:
        section_params["next_mode"] = MODES.SEASONS
        section_params["folder"] = True
        section_params["video_type"] = VIDEO_TYPES.TVSHOW
        section_params["content_type"] = CONTENT_TYPES.TVSHOWS
        section_params["search_img"] = "television_search.png"
        section_params["label_plural"] = i18n("tv_shows")
        section_params["label_single"] = i18n("tv_show")
    else:
        section_params["next_mode"] = MODES.GET_SOURCES
        section_params["folder"] = (
            kodi.get_setting("source-win") == "Directory" and kodi.get_setting("auto-play") == "false"
        )
        section_params["video_type"] = VIDEO_TYPES.MOVIE
        section_params["content_type"] = CONTENT_TYPES.MOVIES
        section_params["search_img"] = "movies_search.png"
        section_params["label_plural"] = i18n("movies")
        section_params["label_single"] = i18n("movie")

    return section_params
Example #15
0
def do_disable_check():
    auto_disable = kodi.get_setting('auto-disable')
    disable_limit = int(kodi.get_setting('disable-limit'))
    for cls in relevant_scrapers():
        setting = '%s_last_results' % (cls.get_name())
        fails = kodi.get_setting(setting)
        fails = int(fails) if fails else 0
        if fails >= disable_limit:
            if auto_disable == DISABLE_SETTINGS.ON:
                kodi.set_setting('%s-enable' % (cls.get_name()), 'false')
                kodi.notify(msg='[COLOR blue]%s[/COLOR] %s' % (cls.get_name(), i18n('scraper_disabled')), duration=5000)
                kodi.set_setting(setting, '0')
            elif auto_disable == DISABLE_SETTINGS.PROMPT:
                dialog = xbmcgui.Dialog()
                line1 = i18n('disable_line1') % (cls.get_name(), fails)
                line2 = i18n('disable_line2')
                line3 = i18n('disable_line3')
                ret = dialog.yesno('SALTS', line1, line2, line3, i18n('keep_enabled'), i18n('disable_it'))
                if ret:
                    kodi.set_setting('%s-enable' % (cls.get_name()), 'false')
                    kodi.set_setting(setting, '0')
                else:
                    kodi.set_setting(setting, '-1')
Example #16
0
def do_disable_check():
    auto_disable = kodi.get_setting("auto-disable")
    disable_limit = int(kodi.get_setting("disable-limit"))
    for cls in relevant_scrapers():
        setting = "%s_last_results" % (cls.get_name())
        fails = kodi.get_setting(setting)
        fails = int(fails) if fails else 0
        if fails >= disable_limit:
            if auto_disable == DISABLE_SETTINGS.ON:
                kodi.set_setting("%s-enable" % (cls.get_name()), "false")
                kodi.notify(msg="[COLOR blue]%s[/COLOR] %s" % (cls.get_name(), i18n("scraper_disabled")), duration=5000)
                kodi.set_setting(setting, "0")
            elif auto_disable == DISABLE_SETTINGS.PROMPT:
                dialog = xbmcgui.Dialog()
                line1 = i18n("disable_line1") % (cls.get_name(), fails)
                line2 = i18n("disable_line2")
                line3 = i18n("disable_line3")
                ret = dialog.yesno("SALTS", line1, line2, line3, i18n("keep_enabled"), i18n("disable_it"))
                if ret:
                    kodi.set_setting("%s-enable" % (cls.get_name()), "false")
                    kodi.set_setting(setting, "0")
                else:
                    kodi.set_setting(setting, "-1")
Example #17
0
 def __attempt_db_recovery(self):
     self.__recovery = True
     header = i18n('recovery_header')
     if xbmcgui.Dialog().yesno(header, i18n('rec_mig_1'), i18n('rec_mig_2')):
         try: self.init_database('0.0.0')
         except Exception as e:
             log_utils.log('DB Migration Failed: %s' % (e), log_utils.LOGWARNING)
             if xbmcgui.Dialog().yesno(header, i18n('rec_reset_1'), i18n('rec_reset_2'), i18n('rec_reset_3')):
                 try: result = self.reset_db()
                 except Exception as e:
                     log_utils.log('Reset Failed: %s' % (e), log_utils.LOGWARNING)
                     kodi.notify(msg=i18n('reset_failed') % e, duration=5000)
                 else:
                     if result:
                         kodi.notify(msg=i18n('db_reset_success'))
Example #18
0
 def attempt_db_recovery(self):
     header = i18n('recovery_header')
     if xbmcgui.Dialog().yesno(header, i18n('rec_mig_1'), i18n('rec_mig_2')):
         try: self.init_database('0.0.0')
         except Exception as e:
             log_utils.log('DB Migration Failed: %s' % (e), log_utils.LOGWARNING)
             if self.db_type == DB_TYPES.SQLITE:
                 if xbmcgui.Dialog().yesno(header, i18n('rec_reset_1'), i18n('rec_reset_2'), i18n('rec_reset_3')):
                     try: self.reset_db()
                     except Exception as e:
                         log_utils.log('Reset Failed: %s' % (e), log_utils.LOGWARNING)
                         try: msg = i18n('reset_failed') % (e)
                         except: msg = 'Reset Failed: %s' % (e)
                     else:
                         msg = i18n('db_reset_success')
                     kodi.notify(msg=msg, duration=5000)
Example #19
0
def perform_auto_conf(responses):
    length = len(responses)
    TOTAL = 12
    if length < TOTAL:
        responses += [True] * (TOTAL - length)

    if responses[0]: kodi.set_setting('trakt_timeout', '60')
    if responses[1]: kodi.set_setting('calendar-day', '-1')
    if responses[2]: kodi.set_setting('calendar_time', '2')
    if responses[3]: kodi.set_setting('source_timeout', '20')
    if responses[4]: kodi.set_setting('include_watchlist_next', 'true')
    if responses[5]: kodi.set_setting('filter_direct', 'true')
    if responses[6]: kodi.set_setting('filter_unusable', 'true')
    if responses[7]: kodi.set_setting('show_debrid', 'true')
    if responses[8]: kodi.set_setting('source_results', '0')
    if responses[9]:
        kodi.set_setting('enable_sort', 'true')
        kodi.set_setting('sort1_field', '2')
        kodi.set_setting('sort2_field', '5')
        kodi.set_setting('sort3_field', '6')
        kodi.set_setting('sort4_field', '1')
        kodi.set_setting('sort5_field', '3')
        kodi.set_setting('sort6_field', '4')

    if responses[10]:
        tiers = [
            'Local', 'Furk.net', 'Premiumize.me', 'EasyNews', 'DD.tv',
            'NoobRoom',
            [
                'WatchHD', 'IFlix', 'MoviesPlanet', 'CyberReel', '9Movies',
                '123Movies', 'niter.tv', 'ororo.tv'
            ],
            [
                'movietv.to', 'StreamLord', 'tunemovie', 'afdah.org',
                'xmovies8', 'xmovies8.v2', 'alluc.com'
            ],
            [
                'torba.se', 'IzlemeyeDeger', 'Rainierland', 'zumvo.com',
                'PutMV', 'MiraDeTodo', 'beinmovie'
            ],
            [
                'SezonLukDizi', 'Dizimag', 'Dizilab', 'Dizigold', 'Diziay',
                'Dizipas', 'OneClickTVShows', 'MovieFarsi'
            ],
            [
                'DDLValley', 'ReleaseBB', 'MyVideoLinks.eu', 'OneClickWatch',
                'RLSSource.net', 'TVRelease.Net'
            ],
            [
                'IceFilms', 'PrimeWire', 'Flixanity', 'wso.ch', 'WatchSeries',
                'UFlix.org', 'Putlocker', 'MovieHut'
            ],
            [
                'funtastic-vids', 'WatchFree.to', 'pftv', 'streamallthis.is',
                'Movie4K', 'afdah', 'SolarMovie', 'yify-streaming'
            ],
            [
                'CouchTunerV2', 'CouchTunerV1', 'Watch8Now', 'yshows',
                'TwoMovies.us', 'iWatchOnline', 'vidics.ch', 'pubfilm'
            ],
            [
                'OnlineMoviesIs', 'OnlineMoviesPro', 'ViewMovies', 'movie25',
                'viooz.ac', 'view47', 'MoviesHD', 'wmo.ch'
            ],
            [
                'ayyex', 'stream-tv.co', 'clickplay.to', 'MintMovies',
                'MovieNight', 'cmz', 'ch131', 'filmikz.ch'
            ],
            [
                'MovieTube', 'LosMovies', 'FilmStreaming.in', 'moviestorm.eu',
                'MerDB'
            ], 'MoviesOnline7'
        ]

        sso = []
        random_sso = kodi.get_setting('random_sso') == 'true'
        for tier in tiers:
            if isinstance(tier, basestring):
                sso.append(tier)
            else:
                if random_sso:
                    random.shuffle(tier)
                sso += tier
        kodi.set_setting('source_sort_order', '|'.join(sso))

    if responses[11]: reset_base_url()
    kodi.set_setting('filter-unknown', 'false')
    kodi.notify(msg=i18n('auto_conf_complete'))
Example #20
0
def download_media(url, path, file_name):
    try:
        progress = int(ADDON.get_setting('down_progress'))
        import urllib2
        request = urllib2.Request(url)
        request.add_header('User-Agent', USER_AGENT)
        request.add_unredirected_header('Host', request.get_host())
        response = urllib2.urlopen(request)

        content_length = 0
        if 'Content-Length' in response.info():
            content_length = int(response.info()['Content-Length'])

        file_name = file_name.replace('.strm', get_extension(url, response))
        full_path = os.path.join(path, file_name)
        log_utils.log('Downloading: %s -> %s' % (url, full_path), xbmc.LOGDEBUG)

        path = xbmc.makeLegalFilename(path)
        if not xbmcvfs.exists(path):
            try:
                try: xbmcvfs.mkdirs(path)
                except: os.mkdir(path)
            except Exception as e:
                raise Exception(i18n('failed_create_dir'))

        file_desc = xbmcvfs.File(full_path, 'w')
        total_len = 0
        if progress:
            if progress == PROGRESS.WINDOW:
                dialog = xbmcgui.DialogProgress()
            else:
                dialog = xbmcgui.DialogProgressBG()

            dialog.create('Stream All The Sources', i18n('downloading') % (file_name))
            dialog.update(0)
        while True:
            data = response.read(CHUNK_SIZE)
            if not data:
                break

            if progress == PROGRESS.WINDOW and dialog.iscanceled():
                break

            total_len += len(data)
            if not file_desc.write(data):
                raise Exception('failed_write_file')

            percent_progress = (total_len) * 100 / content_length if content_length > 0 else 0
            log_utils.log('Position : %s / %s = %s%%' % (total_len, content_length, percent_progress), xbmc.LOGDEBUG)
            if progress == PROGRESS.WINDOW:
                dialog.update(percent_progress)
            elif progress == PROGRESS.BACKGROUND:
                dialog.update(percent_progress, 'Stream All The Sources')
        else:
            notify(msg=i18n('download_complete') % (file_name), duration=5000)
            log_utils.log('Download Complete: %s -> %s' % (url, full_path), xbmc.LOGDEBUG)

        file_desc.close()
        if progress:
            dialog.close()

    except Exception as e:
        log_utils.log('Error (%s) during download: %s -> %s' % (str(e), url, file_name), xbmc.LOGERROR)
        notify(msg=i18n('download_error') % (str(e), file_name), duration=5000)
Example #21
0
def download_media(url, path, file_name):
    try:
        progress = int(kodi.get_setting("down_progress"))
        request = urllib2.Request(url)
        request.add_header("User-Agent", USER_AGENT)
        request.add_unredirected_header("Host", request.get_host())
        response = urllib2.urlopen(request)

        content_length = 0
        if "Content-Length" in response.info():
            content_length = int(response.info()["Content-Length"])

        file_name = file_name.replace(".strm", get_extension(url, response))
        full_path = os.path.join(path, file_name)
        log_utils.log("Downloading: %s -> %s" % (url, full_path), log_utils.LOGDEBUG)

        path = xbmc.makeLegalFilename(path)
        if not xbmcvfs.exists(path):
            try:
                try:
                    xbmcvfs.mkdirs(path)
                except:
                    os.mkdir(path)
            except Exception as e:
                raise Exception(i18n("failed_create_dir"))

        file_desc = xbmcvfs.File(full_path, "w")
        total_len = 0
        if progress:
            if progress == PROGRESS.WINDOW:
                dialog = xbmcgui.DialogProgress()
            else:
                dialog = xbmcgui.DialogProgressBG()

            dialog.create("Stream All The Sources", i18n("downloading") % (file_name))
            dialog.update(0)
        while True:
            data = response.read(CHUNK_SIZE)
            if not data:
                break

            if progress == PROGRESS.WINDOW and dialog.iscanceled():
                break

            total_len += len(data)
            if not file_desc.write(data):
                raise Exception("failed_write_file")

            percent_progress = (total_len) * 100 / content_length if content_length > 0 else 0
            log_utils.log(
                "Position : %s / %s = %s%%" % (total_len, content_length, percent_progress), log_utils.LOGDEBUG
            )
            if progress == PROGRESS.WINDOW:
                dialog.update(percent_progress)
            elif progress == PROGRESS.BACKGROUND:
                dialog.update(percent_progress, "Stream All The Sources")
        else:
            kodi.notify(msg=i18n("download_complete") % (file_name), duration=5000)
            log_utils.log("Download Complete: %s -> %s" % (url, full_path), log_utils.LOGDEBUG)

        file_desc.close()
        if progress:
            dialog.close()

    except Exception as e:
        log_utils.log("Error (%s) during download: %s -> %s" % (str(e), url, file_name), log_utils.LOGERROR)
        kodi.notify(msg=i18n("download_error") % (str(e), file_name), duration=5000)
Example #22
0
def get_pin():
    AUTH_BUTTON = 200
    LATER_BUTTON = 201
    NEVER_BUTTON = 202
    ACTION_PREVIOUS_MENU = 10
    ACTION_BACK = 92
    CENTER_Y = 6
    CENTER_X = 2

    class PinAuthDialog(xbmcgui.WindowXMLDialog):
        auth = False

        def onInit(self):
            self.pin_edit_control = self.__add_editcontrol(30, 240, 40, 450)
            self.setFocus(self.pin_edit_control)
            auth = self.getControl(AUTH_BUTTON)
            never = self.getControl(NEVER_BUTTON)
            self.pin_edit_control.controlUp(never)
            self.pin_edit_control.controlLeft(never)
            self.pin_edit_control.controlDown(auth)
            self.pin_edit_control.controlRight(auth)
            auth.controlUp(self.pin_edit_control)
            auth.controlLeft(self.pin_edit_control)
            never.controlDown(self.pin_edit_control)
            never.controlRight(self.pin_edit_control)

        def onAction(self, action):
            # print 'Action: %s' % (action.getId())
            if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
                self.close()

        def onControl(self, control):
            # print 'onControl: %s' % (control)
            pass

        def onFocus(self, control):
            # print 'onFocus: %s' % (control)
            pass

        def onClick(self, control):
            # print 'onClick: %s' % (control)
            if control == AUTH_BUTTON:
                if not self.__get_token():
                    kodi.notify(msg=i18n('pin_auth_failed'), duration=5000)
                    return
                self.auth = True

            if control == LATER_BUTTON:
                kodi.notify(msg=i18n('remind_in_24hrs'), duration=5000)
                kodi.set_setting('last_reminder', str(int(time.time())))

            if control == NEVER_BUTTON:
                kodi.notify(msg=i18n('use_addon_settings'), duration=5000)
                kodi.set_setting('last_reminder', '-1')

            if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]:
                self.close()

        def __get_token(self):
            pin = self.pin_edit_control.getText().strip()
            if pin:
                try:
                    trakt_api = Trakt_API(use_https=use_https,
                                          timeout=trakt_timeout)
                    result = trakt_api.get_token(pin=pin)
                    kodi.set_setting('trakt_oauth_token',
                                     result['access_token'])
                    kodi.set_setting('trakt_refresh_token',
                                     result['refresh_token'])
                    profile = trakt_api.get_user_profile(cached=False)
                    kodi.set_setting(
                        'trakt_user',
                        '%s (%s)' % (profile['username'], profile['name']))
                    return True
                except Exception as e:
                    log_utils.log('Trakt Authorization Failed: %s' % (e),
                                  log_utils.LOGDEBUG)
                    return False
            return False

        # have to add edit controls programatically because getControl() (hard) crashes XBMC on them
        def __add_editcontrol(self, x, y, height, width):
            media_path = os.path.join(kodi.get_path(), 'resources', 'skins',
                                      'Default', 'media')
            temp = xbmcgui.ControlEdit(
                0,
                0,
                0,
                0,
                '',
                font='font12',
                textColor='0xFFFFFFFF',
                focusTexture=os.path.join(media_path, 'button-focus2.png'),
                noFocusTexture=os.path.join(media_path, 'button-nofocus.png'),
                _alignment=CENTER_Y | CENTER_X)
            temp.setPosition(x, y)
            temp.setHeight(height)
            temp.setWidth(width)
            self.addControl(temp)
            return temp

    dialog = PinAuthDialog('TraktPinAuthDialog.xml', kodi.get_path())
    dialog.doModal()
    if dialog.auth:
        kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000)
    del dialog
Example #23
0
def get_pin():
    AUTH_BUTTON = 200
    LATER_BUTTON = 201
    NEVER_BUTTON = 202
    ACTION_PREVIOUS_MENU = 10
    ACTION_BACK = 92
    CENTER_Y = 6
    CENTER_X = 2
    
    class PinAuthDialog(xbmcgui.WindowXMLDialog):
        auth = False
        
        def onInit(self):
            self.pin_edit_control = self.__add_editcontrol(30, 240, 40, 450)
            self.setFocus(self.pin_edit_control)
            auth = self.getControl(AUTH_BUTTON)
            never = self.getControl(NEVER_BUTTON)
            self.pin_edit_control.controlUp(never)
            self.pin_edit_control.controlLeft(never)
            self.pin_edit_control.controlDown(auth)
            self.pin_edit_control.controlRight(auth)
            auth.controlUp(self.pin_edit_control)
            auth.controlLeft(self.pin_edit_control)
            never.controlDown(self.pin_edit_control)
            never.controlRight(self.pin_edit_control)
            
        def onAction(self, action):
            # print 'Action: %s' % (action.getId())
            if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
                self.close()

        def onControl(self, control):
            # print 'onControl: %s' % (control)
            pass

        def onFocus(self, control):
            # print 'onFocus: %s' % (control)
            pass

        def onClick(self, control):
            # print 'onClick: %s' % (control)
            if control == AUTH_BUTTON:
                if not self.__get_token():
                    kodi.notify(msg=i18n('pin_auth_failed'), duration=5000)
                    return
                self.auth = True

            if control == LATER_BUTTON:
                kodi.notify(msg=i18n('remind_in_24hrs'), duration=5000)
                kodi.set_setting('last_reminder', str(int(time.time())))

            if control == NEVER_BUTTON:
                kodi.notify(msg=i18n('use_addon_settings'), duration=5000)
                kodi.set_setting('last_reminder', '-1')

            if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]:
                self.close()
        
        def __get_token(self):
            pin = self.pin_edit_control.getText().strip()
            if pin:
                try:
                    trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout)
                    result = trakt_api.get_token(pin=pin)
                    kodi.set_setting('trakt_oauth_token', result['access_token'])
                    kodi.set_setting('trakt_refresh_token', result['refresh_token'])
                    profile = trakt_api.get_user_profile(cached=False)
                    kodi.set_setting('trakt_user', '%s (%s)' % (profile['username'], profile['name']))
                    return True
                except Exception as e:
                    log_utils.log('Trakt Authorization Failed: %s' % (e), log_utils.LOGDEBUG)
                    return False
            return False
        
        # have to add edit controls programatically because getControl() (hard) crashes XBMC on them
        def __add_editcontrol(self, x, y, height, width):
            media_path = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media')
            temp = xbmcgui.ControlEdit(0, 0, 0, 0, '', font='font12', textColor='0xFFFFFFFF', focusTexture=os.path.join(media_path, 'button-focus2.png'),
                                       noFocusTexture=os.path.join(media_path, 'button-nofocus.png'), _alignment=CENTER_Y | CENTER_X)
            temp.setPosition(x, y)
            temp.setHeight(height)
            temp.setWidth(width)
            self.addControl(temp)
            return temp
        
    dialog = PinAuthDialog('TraktPinAuthDialog.xml', kodi.get_path())
    dialog.doModal()
    if dialog.auth:
        kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000)
    del dialog
Example #24
0
def do_auto_config():
    ACTION_PREVIOUS_MENU = 10
    ACTION_BACK = 92
    CONTINUE_BUTTON = 200
    CANCEL_BUTTON = 201

    starty = 60
    posx = 30
    gap = 35
    RADIO_BUTTONS = [
        i18n('set_trakt_timeout'),
        i18n('set_cal_start'),
        i18n('set_cal_airtime'),
        i18n('set_scraper_timeout'),
        i18n('set_wl_mne'),
        i18n('set_test_direct'),
        i18n('set_filter_unusable'),
        i18n('set_show_debrid'),
        i18n('set_no_limit'),
        i18n('set_source_sort'),
        i18n('set_sso'),
        i18n('set_reset_url'),
        i18n('select_all_none')]
    
    class AutoConfDialog(xbmcgui.WindowXMLDialog):
        def onInit(self):
            log_utils.log('onInit:', log_utils.LOGDEBUG)
            self.OK = False
            self.radio_buttons = []
            posy = starty
            for label in RADIO_BUTTONS:
                self.radio_buttons.append(self.__get_radio_button(posx, posy, label))
                posy += gap
            
            try: responses = json.loads(kodi.get_setting('prev_responses'))
            except: responses = [True] * len(self.radio_buttons)
            if len(responses) < len(self.radio_buttons):
                responses += [True] * (len(self.radio_buttons) - len(responses))
            
            self.addControls(self.radio_buttons)
            last_button = None
            for response, radio_button in zip(responses, self.radio_buttons):
                radio_button.setSelected(response)
                if last_button is not None:
                    radio_button.controlUp(last_button)
                    radio_button.controlLeft(last_button)
                    last_button.controlDown(radio_button)
                    last_button.controlRight(radio_button)
                last_button = radio_button

            continue_ctrl = self.getControl(CONTINUE_BUTTON)
            cancel_ctrl = self.getControl(CANCEL_BUTTON)
            self.radio_buttons[0].controlUp(cancel_ctrl)
            self.radio_buttons[0].controlLeft(cancel_ctrl)
            self.radio_buttons[-1].controlDown(continue_ctrl)
            self.radio_buttons[-1].controlRight(continue_ctrl)
            continue_ctrl.controlUp(self.radio_buttons[-1])
            continue_ctrl.controlLeft(self.radio_buttons[-1])
            cancel_ctrl.controlDown(self.radio_buttons[0])
            cancel_ctrl.controlRight(self.radio_buttons[0])
            
        def __get_radio_button(self, x, y, label):
            kwargs = {'font': 'font12', 'focusTexture': 'button-focus2.png', 'noFocusTexture': 'button-nofocus.png', 'focusOnTexture': 'radiobutton-focus.png',
                      'noFocusOnTexture': 'radiobutton-focus.png', 'focusOffTexture': 'radiobutton-nofocus.png', 'noFocusOffTexture': 'radiobutton-nofocus.png'}
            temp = xbmcgui.ControlRadioButton(x, y, 450, 30, label, **kwargs)
            return temp
            
        def onAction(self, action):
            # log_utils.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG)
            if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
                self.close()

        def onControl(self, control):
            # log_utils.log('onControl: %s' % (control), log_utils.LOGDEBUG)
            pass

        def onFocus(self, control):
            # log_utils.log('onFocus: %s' % (control), log_utils.LOGDEBUG)
            pass

        def onClick(self, control):
            # log_utils.log('onClick: %s' % (control), log_utils.LOGDEBUG)
            focus_button = self.getControl(control)
            if focus_button == self.radio_buttons[-1]:
                all_status = focus_button.isSelected()
                for button in self.radio_buttons:
                    button.setSelected(all_status)
            
            if control == CONTINUE_BUTTON:
                self.OK = True
                
            if control == CANCEL_BUTTON:
                self.OK = False

            if control == CONTINUE_BUTTON or control == CANCEL_BUTTON:
                self.close()
        
        def get_responses(self):
            return [bool(button.isSelected()) for button in self.radio_buttons]

    dialog = AutoConfDialog('AutoConfDialog.xml', kodi.get_path())
    dialog.doModal()
    if dialog.OK:
        responses = dialog.get_responses()
        kodi.set_setting('prev_responses', json.dumps(responses))
        perform_auto_conf(responses)
    del dialog
Example #25
0
def download_media(url, path, file_name):
    try:
        progress = int(kodi.get_setting('down_progress'))
        request = urllib2.Request(url)
        request.add_header('User-Agent', USER_AGENT)
        request.add_unredirected_header('Host', request.get_host())
        response = urllib2.urlopen(request)

        content_length = 0
        if 'Content-Length' in response.info():
            content_length = int(response.info()['Content-Length'])

        file_name = file_name.replace('.strm', get_extension(url, response))
        full_path = os.path.join(path, file_name)
        log_utils.log('Downloading: %s -> %s' % (url, full_path), log_utils.LOGDEBUG)

        path = xbmc.makeLegalFilename(path)
        if not xbmcvfs.exists(path):
            try:
                try: xbmcvfs.mkdirs(path)
                except: os.mkdir(path)
            except Exception as e:
                raise Exception(i18n('failed_create_dir'))

        file_desc = xbmcvfs.File(full_path, 'w')
        total_len = 0
        if progress:
            if progress == PROGRESS.WINDOW:
                dialog = xbmcgui.DialogProgress()
            else:
                dialog = xbmcgui.DialogProgressBG()

            dialog.create('Stream All The Sources', i18n('downloading') % (file_name))
            dialog.update(0)
        while True:
            data = response.read(CHUNK_SIZE)
            if not data:
                break

            if progress == PROGRESS.WINDOW and dialog.iscanceled():
                break

            total_len += len(data)
            if not file_desc.write(data):
                raise Exception('failed_write_file')

            percent_progress = (total_len) * 100 / content_length if content_length > 0 else 0
            log_utils.log('Position : %s / %s = %s%%' % (total_len, content_length, percent_progress), log_utils.LOGDEBUG)
            if progress == PROGRESS.WINDOW:
                dialog.update(percent_progress)
            elif progress == PROGRESS.BACKGROUND:
                dialog.update(percent_progress, 'Stream All The Sources')
        else:
            kodi.notify(msg=i18n('download_complete') % (file_name), duration=5000)
            log_utils.log('Download Complete: %s -> %s' % (url, full_path), log_utils.LOGDEBUG)

        file_desc.close()
        if progress:
            dialog.close()

    except Exception as e:
        log_utils.log('Error (%s) during download: %s -> %s' % (str(e), url, file_name), log_utils.LOGERROR)
        kodi.notify(msg=i18n('download_error') % (str(e), file_name), duration=5000)
Example #26
0
def do_auto_config():
    ACTION_PREVIOUS_MENU = 10
    ACTION_BACK = 92
    CONTINUE_BUTTON = 200
    CANCEL_BUTTON = 201

    starty = 60
    posx = 30
    gap = 35
    RADIO_BUTTONS = [
        i18n('set_trakt_timeout'),
        i18n('set_cal_start'),
        i18n('set_cal_airtime'),
        i18n('set_scraper_timeout'),
        i18n('set_wl_mne'),
        i18n('set_test_direct'),
        i18n('set_filter_unusable'),
        i18n('set_show_debrid'),
        i18n('set_no_limit'),
        i18n('set_source_sort'),
        i18n('set_sso'),
        i18n('set_reset_url'),
        i18n('select_all_none')
    ]

    class AutoConfDialog(xbmcgui.WindowXMLDialog):
        def onInit(self):
            log_utils.log('onInit:', log_utils.LOGDEBUG)
            self.OK = False
            self.radio_buttons = []
            posy = starty
            for label in RADIO_BUTTONS:
                self.radio_buttons.append(
                    self.__get_radio_button(posx, posy, label))
                posy += gap

            try:
                responses = json.loads(kodi.get_setting('prev_responses'))
            except:
                responses = [True] * len(self.radio_buttons)
            if len(responses) < len(self.radio_buttons):
                responses += [True
                              ] * (len(self.radio_buttons) - len(responses))

            self.addControls(self.radio_buttons)
            last_button = None
            for response, radio_button in zip(responses, self.radio_buttons):
                radio_button.setSelected(response)
                if last_button is not None:
                    radio_button.controlUp(last_button)
                    radio_button.controlLeft(last_button)
                    last_button.controlDown(radio_button)
                    last_button.controlRight(radio_button)
                last_button = radio_button

            continue_ctrl = self.getControl(CONTINUE_BUTTON)
            cancel_ctrl = self.getControl(CANCEL_BUTTON)
            self.radio_buttons[0].controlUp(cancel_ctrl)
            self.radio_buttons[0].controlLeft(cancel_ctrl)
            self.radio_buttons[-1].controlDown(continue_ctrl)
            self.radio_buttons[-1].controlRight(continue_ctrl)
            continue_ctrl.controlUp(self.radio_buttons[-1])
            continue_ctrl.controlLeft(self.radio_buttons[-1])
            cancel_ctrl.controlDown(self.radio_buttons[0])
            cancel_ctrl.controlRight(self.radio_buttons[0])

        def __get_radio_button(self, x, y, label):
            kwargs = {
                'font': 'font12',
                'focusTexture': 'button-focus2.png',
                'noFocusTexture': 'button-nofocus.png',
                'focusOnTexture': 'radiobutton-focus.png',
                'noFocusOnTexture': 'radiobutton-focus.png',
                'focusOffTexture': 'radiobutton-nofocus.png',
                'noFocusOffTexture': 'radiobutton-nofocus.png'
            }
            temp = xbmcgui.ControlRadioButton(x, y, 450, 30, label, **kwargs)
            return temp

        def onAction(self, action):
            # log_utils.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG)
            if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
                self.close()

        def onControl(self, control):
            # log_utils.log('onControl: %s' % (control), log_utils.LOGDEBUG)
            pass

        def onFocus(self, control):
            # log_utils.log('onFocus: %s' % (control), log_utils.LOGDEBUG)
            pass

        def onClick(self, control):
            # log_utils.log('onClick: %s' % (control), log_utils.LOGDEBUG)
            focus_button = self.getControl(control)
            if focus_button == self.radio_buttons[-1]:
                all_status = focus_button.isSelected()
                for button in self.radio_buttons:
                    button.setSelected(all_status)

            if control == CONTINUE_BUTTON:
                self.OK = True

            if control == CANCEL_BUTTON:
                self.OK = False

            if control == CONTINUE_BUTTON or control == CANCEL_BUTTON:
                self.close()

        def get_responses(self):
            return [bool(button.isSelected()) for button in self.radio_buttons]

    dialog = AutoConfDialog('AutoConfDialog.xml', kodi.get_path())
    dialog.doModal()
    if dialog.OK:
        responses = dialog.get_responses()
        kodi.set_setting('prev_responses', json.dumps(responses))
        perform_auto_conf(responses)
    del dialog