示例#1
0
 def create_nfo(item_id, item_driveid, nfo_path, provider):
     url = provider.get_item(
         item_driveid=item_driveid,
         item_id=item_id,
         include_download_info=True)["download_info"]["url"]
     headers = {
         "Authorization":
         "Bearer %s" % provider.get_access_tokens()['access_token']
     }
     try:
         response = Request(url, None, headers).request()
     except:
         Logger.error('Error on request to: %s' % url)
         return False
     f = None
     try:
         f = KodiUtils.file(nfo_path, 'w')
         f.write(response)
     except Exception as err:
         Logger.error(err)
         return False
     finally:
         if f:
             f.close()
     return True
示例#2
0
 def create_nfo(driveid, item, item_name, nfo_path):
     item_enc = urllib.quote_plus(item_name.encode('utf-8'))
     dl_url = DownloadServiceUtil.download_item(driveid, item, item_enc)
     try:
         response = Request(dl_url, None).request()
     except:
         Logger.error('Error on request to: %s' % dl_url)
         return False
     f = None
     try:
         f=KodiUtils.file(nfo_path,'w')
         f.write(response)
     except Exception as err:
         Logger.error(err)
         return False
     finally:
         if f:
             f.close()
     return True
 def get_subtitles(self):
     try:
         from clouddrive.common.remote.request import Request
         from clouddrive.common.service.download import DownloadServiceUtil
         response = Request(self.getPlayingFile() + '?subtitles',
                            None).request_json()
         if response and 'driveid' in response and 'subtitles' in response:
             driveid = response['driveid']
             subtitles = response['subtitles']
             for subtitle in subtitles:
                 url = DownloadServiceUtil.build_download_url(
                     driveid,
                     Utils.default(
                         Utils.get_safe_value(subtitle, 'drive_id'),
                         driveid), subtitle['id'],
                     urllib.quote(Utils.str(subtitle['name'])))
                 Logger.debug('subtitle: %s' % url)
                 self.setSubtitles(url)
     except Exception as e:
         Logger.error(e)
         from clouddrive.common.remote.errorreport import ErrorReport
         ErrorReport.handle_exception(e)
示例#4
0
 def _refresh_slideshow(self, driveid, item_driveid, item_id, path,
                        change_token, wait_for_slideshow):
     if wait_for_slideshow:
         Logger.notice(
             'Waiting up to 10 minutes until the slideshow for folder %s starts...'
             % Utils.default(item_id, path))
         max_waiting_time = time.time() + 10 * 60
         while not self.cancel_operation(
         ) and not KodiUtils.get_cond_visibility(
                 'Slideshow.IsActive') and max_waiting_time > time.time():
             if self._system_monitor.waitForAbort(2):
                 break
         self._print_slideshow_info()
     interval = self._addon.getSetting('slideshow_refresh_interval')
     Logger.notice(
         'Waiting up to %s minute(s) to check if it is needed to refresh the slideshow of folder %s...'
         % (interval, Utils.default(item_id, path)))
     target_time = time.time() + int(interval) * 60
     while not self.cancel_operation() and target_time > time.time(
     ) and KodiUtils.get_cond_visibility('Slideshow.IsActive'):
         if self._system_monitor.waitForAbort(10):
             break
     self._print_slideshow_info()
     if not self.cancel_operation() and KodiUtils.get_cond_visibility(
             'Slideshow.IsActive'):
         try:
             self._slideshow(driveid, item_driveid, item_id, path,
                             change_token)
         except Exception as e:
             Logger.error(
                 'Slideshow failed to auto refresh. Will be restarted when possible. Error: '
             )
             Logger.error(ExceptionUtils.full_stacktrace(e))
             self._refresh_slideshow(driveid, item_driveid, item_id, path,
                                     None, wait_for_slideshow)
     else:
         Logger.notice(
             'Slideshow is not running anymore or abort requested.')
示例#5
0
 def _handle_exception(self, ex, show_error_dialog = True):
     stacktrace = ExceptionUtils.full_stacktrace(ex)
     rex = ExceptionUtils.extract_exception(ex, RequestException)
     uiex = ExceptionUtils.extract_exception(ex, UIException)
     httpex = ExceptionUtils.extract_exception(ex, HTTPError)
     urlex = ExceptionUtils.extract_exception(ex, URLError)
     line1 = self._common_addon.getLocalizedString(32027)
     line2 = Utils.unicode(ex)
     line3 = self._common_addon.getLocalizedString(32016)
     
     if uiex:
         line1 = self._common_addon.getLocalizedString(int(Utils.str(uiex)))
         line2 = Utils.unicode(uiex.root_exception)
     elif rex and rex.response:
         line1 += ' ' + Utils.unicode(rex)
         line2 = ExceptionUtils.extract_error_message(rex.response)
     send_report = True
     add_account_cmd = 'RunPlugin('+self._addon_url + '?' + urllib.urlencode({'action':'_add_account', 'content_type': self._content_type})+')'
     if isinstance(ex, AccountNotFoundException) or isinstance(ex, DriveNotFoundException):
         show_error_dialog = False
         if self._dialog.yesno(self._addon_name, self._common_addon.getLocalizedString(32063) % '\n'):
             KodiUtils.executebuiltin(add_account_cmd)
     elif rex and httpex:
         if httpex.code >= 500:
             line1 = self._common_addon.getLocalizedString(32035)
             line2 = None
             line3 = self._common_addon.getLocalizedString(32038)
         elif httpex.code >= 400:
             driveid = Utils.get_safe_value(self._addon_params, 'driveid')
             if driveid:
                 self._account_manager.load()
                 account = self._account_manager.get_account_by_driveid(driveid)
                 drive = self._account_manager.get_drive_by_driveid(driveid)
                 if KodiUtils.get_signin_server() in rex.request or httpex.code == 401:
                     send_report = False
                     show_error_dialog = False
                     if self._dialog.yesno(self._addon_name, self._common_addon.getLocalizedString(32046) % (self._get_display_name(account, drive, True), '\n')):
                         KodiUtils.executebuiltin(add_account_cmd)
                 elif httpex.code == 403:
                     line1 = self._common_addon.getLocalizedString(32019)
                     line2 = line3 = None
                 elif httpex.code == 404:
                     send_report = False
                     line1 = self._common_addon.getLocalizedString(32037)
                     line2 = line2 = None
                 else:
                     line1 = self._common_addon.getLocalizedString(32036)
                     line3 = self._common_addon.getLocalizedString(32038)
             else:
                 if KodiUtils.get_signin_server()+'/pin/' in rex.request and httpex.code == 404 and self._ip_before_pin:
                     ip_after_pin = Request(KodiUtils.get_signin_server() + '/ip', None).request()
                     if self._ip_before_pin != ip_after_pin:
                         send_report = False
                         line1 = self._common_addon.getLocalizedString(32072)
                         line2 = self._common_addon.getLocalizedString(32073) % (self._ip_before_pin, ip_after_pin,)
     elif urlex:
         reason = Utils.str(urlex.reason)
         line3 = self._common_addon.getLocalizedString(32074)
         if '[Errno 101]' in reason:
             line1 = self._common_addon.getLocalizedString(32076)
         elif '[Errno 11001]' in reason:
             line1 = self._common_addon.getLocalizedString(32077)
         elif 'CERTIFICATE_VERIFY_FAILED' in reason:
             line1 = self._common_addon.getLocalizedString(32078)
         else:
             line1 = self._common_addon.getLocalizedString(32075)
         
     report = '[%s] [%s]/[%s]\n\n%s\n%s\n%s\n\n%s' % (self._addonid, self._addon_version, self._common_addon_version, line1, line2, line3, stacktrace)
     if rex:
         report += '\n\n%s\nResponse:\n%s' % (rex.request, rex.response)
     report += '\n\nshow_error_dialog: %s' % show_error_dialog
     Logger.error(report)
     if show_error_dialog:
         self._dialog.ok(self._addon_name, line1, line2, line3)
     if send_report:
         report_error = KodiUtils.get_addon_setting('report_error', self._common_addon_id) == 'true'
         report_error_invite = KodiUtils.get_addon_setting('report_error_invite', self._common_addon_id) == 'true'
         if not report_error and not report_error_invite:
             if not self._dialog.yesno(self._addon_name, self._common_addon.getLocalizedString(32050), None, None, self._common_addon.getLocalizedString(32012), self._common_addon.getLocalizedString(32013)):
                 KodiUtils.set_addon_setting('report_error', 'true', self._common_addon_id)
             KodiUtils.set_addon_setting('report_error_invite', 'true', self._common_addon_id)
         ErrorReport.send_report(report)
 def log_error(self, format, *args):
     Logger.error("[%s.service] %s\n" %
                  (self.server.service.name, format % args))