Пример #1
0
 def fetch(self, url, params=None, data=None, **request_params):
     try:
         with Timer(logger=self.log,
                    name='Fetching URL %s with params %r' % (url, params)):
             time.sleep(1)
             response = self.session.request('post' if data else 'get',
                                             url,
                                             params=params,
                                             data=data,
                                             **request_params)
             response.raise_for_status()
             self.save_cookies()
             return response
     except Timeout as e:
         raise ScraperError(32000,
                            "Timeout while fetching URL: %s (%%s)" % url,
                            lang(30000),
                            cause=e)
     except NoValidProxiesFound as e:
         raise ScraperError(32005, "Can't find anonymous proxy", cause=e)
     except RequestException as e:
         raise ScraperError(32001,
                            "Can't fetch URL: %s (%%s)" % url,
                            lang(30000),
                            cause=e)
     except ProxyListException as e:
         plugin.set_setting('use-proxy', 0)
         raise ScraperError(32004,
                            "Can't load anonymous proxy list",
                            cause=e)
Пример #2
0
 def fetch(self, url, params=None, data=None, **request_params):
     try:
         with Timer(logger=self.log,
                    name='Fetching URL %s with params %r' % (url, params)):
             response = self.session.request(
                 'post' if data else 'get',
                 url,
                 params=params,
                 data=data,
                 headers={
                     'User-Agent':
                     'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4'
                 },
                 **request_params)
             response.raise_for_status()
             self.save_cookies()
             return response
     except Timeout as e:
         raise ScraperError(32000,
                            "Timeout while fetching URL: %s (%%s)" % url,
                            lang(30000),
                            cause=e)
     except NoValidProxiesFound as e:
         raise ScraperError(32005, "Can't find anonymous proxy", cause=e)
     except RequestException as e:
         raise ScraperError(32001,
                            "Can't fetch URL: %s (%%s)" % url,
                            lang(30000),
                            cause=e)
     except ProxyListException as e:
         plugin.set_setting('use-proxy', 0)
         raise ScraperError(32004,
                            "Can't load anonymous proxy list",
                            cause=e)
Пример #3
0
def add_to_library(series_id):
    items = library_items()
    scraper = get_scraper()
    if series_id not in items:
        items.append(series_id)
        if plugin.get_setting('sync_add_remove_favorite', bool):
            scraper.api.favorite(series_id)
    plugin.set_setting('update-library', True)
    xbmc.executebuiltin(actions.refresh())
Пример #4
0
def remove_from_library(series_id):
    items = library_items()
    scraper = get_scraper()
    if series_id in items:
        items.remove(series_id)
        if plugin.get_setting('sync_add_remove_favorite', bool):
            scraper.api.favorite(series_id)
    library_new_episodes().remove_by(series_id=series_id)
    plugin.set_setting('update-library', True)
    xbmc.executebuiltin(actions.refresh())
Пример #5
0
def create_lostfilm_source():
    from support.sources import Sources, TvDbScraperSettings, SourceAlreadyExists
    sources = Sources()
    plugin.log.info("Creating LostFilm.TV source...")
    try:
        sources.add_video(plugin.get_setting('library-path', unicode), 'LostFilm.TV', TvDbScraperSettings())
    except SourceAlreadyExists:
        plugin.set_setting('lostfilm-source-created', True)
        raise LocalizedError(40408, "Source is already exist")
    plugin.log.info("LostFilm.TV source created, restart needed...")
    plugin.set_setting('lostfilm-source-created', True)
    d = xbmcgui.Dialog()
    if d.yesno(lang(40404), lang(40405)):
        xbmc.executebuiltin('Quit')
Пример #6
0
def create_lostfilm_source():
    from support.sources import Sources, TvDbScraperSettings, SourceAlreadyExists
    sources = Sources()
    plugin.log.info("Creating LostFilm.TV source...")
    try:
        sources.add_video(plugin.get_setting('library-path', unicode), 'LostFilm.TV', TvDbScraperSettings())
    except SourceAlreadyExists:
        plugin.set_setting('lostfilm-source-created', True)
        raise LocalizedError(40408, "Source is already exist")
    plugin.log.info("LostFilm.TV source created, restart needed...")
    plugin.set_setting('lostfilm-source-created', True)
    d = xbmcgui.Dialog()
    if d.yesno(lang(40404), lang(40405)):
        xbmc.executebuiltin('Quit')
Пример #7
0
 def fetch(self, url, params=None, data=None, **request_params):
     try:
         with Timer(logger=self.log, name='Fetching URL %s with params %r' % (url, params)):
             response = self.session.request('post' if data else 'get',
                                             url, params=params, data=data,
                                             **request_params)
             response.raise_for_status()
             self.save_cookies()
             return response
     except Timeout as e:
         raise ScraperError(32000, "Timeout while fetching URL: %s (%%s)" % url, lang(30000), cause=e)
     except NoValidProxiesFound as e:
         raise ScraperError(32005, "Can't find anonymous proxy", cause=e)
     except RequestException as e:
         raise ScraperError(32001, "Can't fetch URL: %s (%%s)" % url, lang(30000), cause=e)
     except ProxyListException as e:
         plugin.set_setting('use-proxy', 0)
         raise ScraperError(32004, "Can't load anonymous proxy list", cause=e)
 def fetch(self, url, params=None, data=None, **request_params):
     try:
         with Timer(logger=self.log, name='Fetching URL %s with params %r' % (url, params)):
             response = self.session.request('post' if data else 'get',
                                             url, params=params, data=data,
                                             headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4'},
                                             **request_params)
             response.raise_for_status()
             self.save_cookies()
             return response
     except Timeout as e:
         raise ScraperError(32000, "Timeout while fetching URL: %s (%%s)" % url, lang(30000), cause=e)
     except NoValidProxiesFound as e:
         raise ScraperError(32005, "Can't find anonymous proxy", cause=e)
     except RequestException as e:
         raise ScraperError(32001, "Can't fetch URL: %s (%%s)" % url, lang(30000), cause=e)
     except ProxyListException as e:
         plugin.set_setting('use-proxy', 0)
         raise ScraperError(32004, "Can't load anonymous proxy list", cause=e)
Пример #9
0
def check_availability():
    use_proxy = plugin.get_setting('use_proxy', bool)
    plugin.log.info("[1/3] Try open LostFilm.TV")
    try:
        res = check_site()
        code = res.status_code
        content = res.text
        if code != 200 or 'LostFilm.TV' not in content:  # Если с текущими настройками не лост
            if not use_proxy:
                plugin.log.info(
                    "[2/3] Can't open LostFilm.TV. Try enable proxy")
                plugin.set_setting("use_proxy", True)
            else:
                plugin.log.info(
                    "[2/3] Can't open LostFilm.TV with proxy. Try disable (for some providers is help)"
                )
                plugin.set_setting("use_proxy", False)
            res = check_site()
            code = res.status_code
            content = res.text
            if code != 200 or 'LostFilm.TV' not in content:  # Если после изменения тоже самое
                plugin.set_setting("use_proxy", use_proxy)
                plugin.log.info(
                    "[3/3] Can't open LostFilm.TV with and without proxy. Check Internet Cable or use VPN"
                )
                return False
            else:
                plugin.log.info("[3/3] LostFilm.TV is availability!")
                return True
        else:
            plugin.log.info(
                "[3/3] LostFilm.TV is availability without change settings!")
            return True
    except Exception as e:
        plugin.log.error("ERR CHECK_AVAILABLE: %s" % e)
        return False
Пример #10
0
def update_library_on_demand():
    plugin.set_setting('update-library', True)
Пример #11
0
def update_library_on_demand():
    plugin.set_setting('update-library', True)
    from lostfilm.common import update_library
    update_library()
Пример #12
0
        else:
            notify(e.localized)
    except Exception as e:
        plugin.log.exception(e)
        notify(lang(40410))
    finally:
        plugin.close_storages()
    return False


if __name__ == '__main__':
    sleep(5000)
    safe_update_library()
    next_run = None
    while not abort_requested():
        now = datetime.datetime.now()
        update_on_demand = plugin.get_setting('update-library', bool)
        if not next_run:
            next_run = now
            next_run += datetime.timedelta(hours=12)
            plugin.log.info("Scheduling next library update at %s" % next_run)
        elif now > next_run and not xbmc.Player().isPlaying(
        ) or update_on_demand:
            updated = safe_update_library()
            if update_on_demand:
                plugin.set_setting('update-library', False)
                if updated:
                    plugin.refresh_container()
            next_run = None
        sleep(1000)
Пример #13
0
def check_last_episode(e):
    storage = plugin.get_storage()
    if 'last_episode' in storage and storage['last_episode'] != e:
        plugin.log.info("Last episode changed, updating library...")
        plugin.set_setting('update-library', True)
    storage['last_episode'] = e
Пример #14
0
def check_first_start():
    if is_authorized() and not plugin.get_setting('first-start', bool):
        d = xbmcgui.Dialog()
        plugin.set_setting('first-start', 'true')
        if d.yesno(lang(40402), *(lang(40403).split("|"))):
            create_lostfilm_source()
Пример #15
0
def clear_series():
    series_cache().clear()
    plugin.set_setting('clear-cache', False)
    return
Пример #16
0
def check_last_episode(e):
    storage = plugin.get_storage()
    if 'last_episode' in storage and storage['last_episode'] != e:
        plugin.log.info("Last episode changed, updating library...")
        plugin.set_setting('update-library', True)
    storage['last_episode'] = e
Пример #17
0
def check_first_start():
    if is_authorized() and not plugin.get_setting('first-start', bool):
        d = xbmcgui.Dialog()
        plugin.set_setting('first-start', 'true')
        if d.yesno(lang(40402), *(lang(40403).split("|"))):
            create_lostfilm_source()
Пример #18
0
        if e.kwargs.get('dialog'):
            xbmcgui.Dialog().ok(lang(30000), *e.localized.split("|"))
        else:
            notify(e.localized)
    except Exception as e:
        plugin.log.exception(e)
        notify(lang(40410))
    finally:
        plugin.close_storages()
    return False

if __name__ == '__main__':
    sleep(5000)
    safe_update_library()
    next_run = None
    while not abort_requested():
        now = datetime.datetime.now()
        update_on_demand = plugin.get_setting('update-library', bool)
        if not next_run:
            next_run = now
            next_run += datetime.timedelta(hours=12)
            plugin.log.info("Scheduling next library update at %s" % next_run)
        elif now > next_run and not xbmc.Player().isPlaying() or update_on_demand:
            updated = safe_update_library()
            if update_on_demand:
                plugin.set_setting('update-library', False)
                if updated:
                    plugin.refresh_container()
            next_run = None
        sleep(1000)
Пример #19
0
def add_to_library(series_id):
    items = library_items()
    if series_id not in items:
        items.append(series_id)
    plugin.set_setting('update-library', True)
Пример #20
0
def remove_from_library(series_id):
    items = library_items()
    if series_id in items:
        items.remove(series_id)
    library_new_episodes().remove_by(series_id=series_id)
    plugin.set_setting('update-library', True)
Пример #21
0
def add_to_library(series_id):
    items = library_items()
    if series_id not in items:
        items.append(series_id)
    plugin.set_setting('update-library', True)
Пример #22
0
def update_library_on_demand():
    plugin.set_setting('update-library', True)
Пример #23
0
def remove_from_library(series_id):
    items = library_items()
    if series_id in items:
        items.remove(series_id)
    library_new_episodes().remove_by(series_id=series_id)
    plugin.set_setting('update-library', True)