Exemple #1
0
    def estimate_error(self, results, prec, epsilon):
        r"""
        Given results from integrations `[I_1, I_2, \ldots, I_k]` done
        with a quadrature of rule of degree `1, 2, \ldots, k`, estimate
        the error of `I_k`.

        For `k = 2`, we estimate  `|I_{\infty}-I_2|` as `|I_2-I_1|`.

        For `k > 2`, we extrapolate `|I_{\infty}-I_k| \approx |I_{k+1}-I_k|`
        from `|I_k-I_{k-1}|` and `|I_k-I_{k-2}|` under the assumption
        that each degree increment roughly doubles the accuracy of
        the quadrature rule (this is true for both :class:`TanhSinh`
        and :class:`GaussLegendre`). The extrapolation formula is given
        by Borwein, Bailey & Girgensohn. Although not very conservative,
        this method seems to be very robust in practice.
        """
        if len(results) == 2:
            return abs(results[0]-results[1])
        try:
            if results[-1] == results[-2] == results[-3]:
                return mpf(0)
            D1 = log(abs(results[-1]-results[-2]), 10)
            D2 = log(abs(results[-1]-results[-3]), 10)
        except ValueError:
            return epsilon
        D3 = -prec
        D4 = min(0, max(D1**2/D2, 2*D1, D3))
        return mpf(10) ** int(D4)
Exemple #2
0
def stop(request):
    global activeList, stopList, stopped, stopDict, queueList, queueFuncs, queueTimes, queueUsers
    RID = str(request.GET['all'])
    stopDict[RID] = RID
    try:
        try:
            # this section will error if request is being processed already, ie its for removing queued requests only
            # the section below should handle active processes
            qid = queueList[RID]
            thisFunc = queueFuncs[qid]
            functions.log(request, "QSTOP", thisFunc)
            queueList.pop(RID, 0)   # try to remove from queuelist before processing
        except:
            # if we are here then most likely the process was ongoing when stop came through
            pass

        pid = activeList.index(RID)
        stopList[pid] = RID
        activeList[pid] = 0
        functions.log(request, "QSTOP", request.user)
        myDict = {'error': 'none', 'message': 'Your analysis has been stopped!'}
        stop = json.dumps(myDict)
        return HttpResponse(stop, content_type='application/json')
    except Exception as e:
        myDict = {'error': 'Analysis not running'}
        stop = json.dumps(myDict)
        return HttpResponse(stop, content_type='application/json')
 def setup_subs(self, label, path):
     iterator = 0
     subs = self.torrent.getSubsIds(label)
     log('[setup_subs] subs: '+str(subs))
     if len(subs) > 0:
         showMessage(self.localize('Information'),
                     self.localize('Downloading and copy subtitles. Please wait.'), forced=True)
         for ind, title in subs:
             self.torrent.continueSession(ind)
         while iterator < 100:
             xbmc.sleep(1000)
             #self.torrent.debug()
             status = self.torrent.torrentHandle.status()
             iterator = int(status.progress * 100)
         # xbmc.sleep(2000)
         for ind, title in subs:
             folder = title.split(os.sep)[0]
             temp = os.path.basename(title)
             addition = os.path.dirname(title).lstrip(folder + os.sep).replace(os.sep, '.').replace(' ', '_').strip()
             ext = temp.split('.')[-1]
             temp = temp[:len(temp) - len(ext) - 1] + '.' + addition + '.' + ext
             newFileName = os.path.join(os.path.dirname(path), temp)
             log('[setup_subs]: '+str((os.path.join(os.path.dirname(os.path.dirname(path)),title),newFileName)))
             if not xbmcvfs.exists(newFileName):
                 xbmcvfs.copy(os.path.join(os.path.dirname(os.path.dirname(path)), title), newFileName)
Exemple #4
0
def set_bias():
    try:     
        bias = float(_self.ui.editBias.text())
        DEV.yoko.set_voltage(bias)
        DEV.yoko.output(True)
    except Exception,e:
        log("Failed to set Bias",e)
def url_get(url, params={}, headers={}, post = None):

    if params:
        import urllib
        url = "%s?%s" % (url, urllib.urlencode(params))

    if post:
        import urllib
        post = urllib.urlencode(post)

    req = urllib2.Request(url, post)
    req.add_header("User-Agent", USER_AGENT)

    for k, v in headers.items():
        req.add_header(k, v)

    try:
        with closing(urllib2.urlopen(req)) as response:
            data = response.read()
            if response.headers.get("Content-Encoding", "") == "gzip":
                import zlib
                return zlib.decompressobj(16 + zlib.MAX_WBITS).decompress(data)
            return data
    except urllib2.HTTPError as e:
        log("[antizapret]: HTTP Error(%s): %s" % (e.errno, e.strerror))
        return None
    def loop(self):
        debug_counter = 0
        pause = True
        with closing(
                OverlayText(w=OVERLAY_WIDTH, h=OVERLAY_HEIGHT, alignment=XBFONT_CENTER_X | XBFONT_CENTER_Y)) as overlay:
            with nested(self.attach(overlay.show, self.on_playback_paused),
                        self.attach(overlay.hide, self.on_playback_resumed, self.on_playback_stopped)):
                while not xbmc.abortRequested and self.isPlaying():
                    #self.print_fulldebug()
                    status = self.engine.status()
                    file_status = self.engine.file_status(self.contentId)
                    self.watchedTime = xbmc.Player().getTime()
                    if self.iterator == 100 and debug_counter < 100:
                        debug_counter += 1
                    else:
                        self.totalTime = xbmc.Player().getTotalTime()
                        self.print_debug(status)
                        debug_counter=0

                    overlay.text = "\n".join(self._get_status_lines(status, file_status))

                    self.iterator = int(file_status.progress * 100)

                    if pause and self.__settings__.getSetting("pause_onplay") == 'true':
                        pause = False
                        xbmc.Player().pause()
                        log('[loop]: xbmc.Player().pause()')
                    xbmc.sleep(1000)
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            torrentFile = self.magnetToTorrent(torrentUrl)
            content = xbmcvfs.File(file_decode(torrentFile), "rb").read()
        else:
            torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + self.md5(
                torrentUrl) + '.torrent'
            try:
                if not re.match("^http\:.+$", torrentUrl):
                    content = xbmcvfs.File(file_decode(torrentUrl), "rb").read()
                else:
                    request = urllib2.Request(torrentUrl)
                    request.add_header('Referer', torrentUrl)
                    request.add_header('Accept-encoding', 'gzip')
                    result = urllib2.urlopen(request)
                    if result.info().get('Content-Encoding') == 'gzip':
                        buf = StringIO(result.read())
                        f = gzip.GzipFile(fileobj=buf)
                        content = f.read()
                    else:
                        content = result.read()

                localFile = xbmcvfs.File(torrentFile, "w+b")
                localFile.write(content)
                localFile.close()
            except Exception, e:
                log('Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile +
                    '" in Torrent::saveTorrent' + '. Exception: ' + str(e))
                return
Exemple #8
0
def datfuncCall(request):
    global datActiveList, datQueueList, datQueueFuncs, datStopList, datStopDict, datStatDict, datQList, datQueueTimes, datQueueUsers
    RID = request.POST['RID']
    funcName = request.POST['funcName']
    datQueueList[RID] = RID  # add to queuelist, remove when processed or stopped
    datQueueFuncs[RID] = funcName
    datQueueTimes[RID] = str(datetime.datetime.now())
    datQueueUsers[RID] = request.user.username
    # add a timestamp dict as well, to sort the others for logging purposes
    qDict = {'RID': RID, 'funcName': funcName, 'request': request, 'stop': datStopList}
    datQList.append(qDict)
    datQ.put(qDict, True)
    datStatDict[RID] = int(datQ.qsize())

    # print log info, need to write this to a file somewhere
    functions.log(request, "QADD", funcName)
    while True:
        try:
            results = datRecent[RID]
            datRecent.pop(RID, 0)
            datStatDict.pop(RID, 0)
            # this return resets data like mothurStatSave
            return results
        except KeyError:
            if RID in datStopList:
                datStatDict.pop(RID, 0)
        except Exception as e:
            print "Unexpected exception: "+str(e)
        sleep(1)
def get_best(Data, search, year):
    log('****** Finding TMDB: ' + str(search) + '; year ' + str(year))
    shows = []
    itemIndex = -1
    if len(search) == 2:
        mediaName, mediaAltTitle = search
    else:
        mediaName, mediaAltTitle = search[0], None
    for show in Data:
        show = show[1]
        itemIndex = itemIndex + 1
        Syear = None
        if show.get('release_date'):
            Syear = int(show.get('release_date').split('-')[0])
        Stitle = show.get('title')
        popularity = int(show.get('popularity'))
        Soriginal_title = show.get('original_title')

        rate = scoreMediaTitleMatch(mediaName, mediaAltTitle, year, Stitle, Soriginal_title, Syear, itemIndex,
                                    popularity)
        shows.append({'rate': rate, 'itemIndex': itemIndex})

    shows = sorted(shows, key=lambda x: x['rate'], reverse=True)
    for s in shows:
        i = int(s['itemIndex'])
        show = Data[i][1]
        if isinstance(show.get('release_date'), str):
            release_date=str(show.get('release_date').split('-')[0])
        else:
            release_date='0'
        log(' ... %d: id="%s", name="%s", year="%s", score="%d".' %
               (i, str(show['id']), show.get('title').encode('utf-8'), release_date,
                s['rate']))
    if shows:
        return shows[0]
 def downloadLoop(self, title):
     db = DownloadDB()
     status = 'downloading'
     while db.get(title) and status != 'stopped':
         status = db.get_status(title)
         if not self.paused:
             if status == 'pause':
                 self.paused = True
                 self.session.pause()
         else:
             if status != 'pause':
                 self.paused = False
                 self.session.resume()
         s = self.torrentHandle.status()
         info = {}
         info['upload'] = s.upload_payload_rate
         info['download'] = s.download_payload_rate
         info['peers'] = s.num_peers
         info['seeds'] = s.num_seeds
         iterator = int(s.progress * 100)
         info['progress'] = iterator
         db.update(title, info)
         #self.debug()
         xbmc.sleep(3000)
     log('out of downloadLoop')
     self.session.remove_torrent(self.torrentHandle)
     return
Exemple #11
0
    def saveTorrent(self, torrentUrl):
        #if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            self.magnetLink = torrentUrl
            self.magnetToTorrent(torrentUrl)
            self.magnetLink = None
            return self.torrentFile
        else:
            if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
            torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
            try:
                if not re.match("^http\:.+$", torrentUrl):
                    content = xbmcvfs.File(torrentUrl, "rb").read()
                else:
                    request = urllib2.Request(torrentUrl)
                    request.add_header('Referer', torrentUrl)
                    request.add_header('Accept-encoding', 'gzip')
                    result = urllib2.urlopen(request)
                    if result.info().get('Content-Encoding') == 'gzip':
                        buf = StringIO(result.read())
                        decomp = zlib.decompressobj(16 + zlib.MAX_WBITS)
                        content = decomp.decompress(buf.getvalue())
                    else:
                        content = result.read()

                localFile = xbmcvfs.File(torrentFile, "w+b")
                localFile.write(content)
                localFile.close()
            except Exception, e:
                log('Unable to rename torrent file from %s to %s in InposLoader::saveTorrent. Exception: %s' %
                        (torrentUrl, torrentFile, str(e)))
                return
Exemple #12
0
def sp(conn,cur):
    #6 sp
    try:
        sqlstr="""
            update dhalldata
            set spname = t.proname,
                proxl_id = t.proxl_id,
                proxl    = t.proxl,
                prozl_id = t.prozl_id,
                prozl    = t.prozl,
                prodl_id = t.prodl_id,
                prodl    = t.prodl,
                braxl_id = t.braxl_id,
                braxl    = t.braxl,
                brazl_id = t.brazl_id,
                brazl    = t.brazl,
                bradl_id = t.bradl_id,
                bradl    = t.bradl,
                normalprice = t.normalprice,
                status   = '5',
                barcode  = t.barcode,
                packetqty1 = t.packetqty1
            from product_all as t
            where spcode = t.proid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("sp更新数据失败!",logfile)
    def __init__(self, userStorageDirectory, torrentUrl, params={}):
        self.userStorageDirectory = userStorageDirectory
        self.torrentUrl = torrentUrl
        xbmc.Player.__init__(self)
        log("[TorrentPlayer] Initalized")
        self.params = params
        self.get = self.params.get
        self.contentId = int(self.get("url"))
        if self.get("seek"):
            self.seek = int(self.get("seek"))
            log('[TorrentPlayer] Seek='+str(self.seek))   
        self.torrent = Downloader.Torrent(self.userStorageDirectory, self.torrentUrl, self.torrentFilesDirectory).player
        try:
            if self.get("url2"):
                self.ids_video = urllib.unquote_plus(self.get("url2")).split(',')
            else:
                self.ids_video = self.get_ids()
        except:
            pass
        self.init()
        self.setup_torrent()
        if self.buffer():
            while True:
                if self.setup_play():
                    debug('************************************* GOING LOOP')
                    self.torrent.startSession()
                    self.torrent.continueSession(self.contentId)
                    self.loop()
                    WatchedHistoryDB().add(self.basename, foldername(self.torrent.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize / 1024 / 1024)
                else:
                    break
                debug('************************************* GO NEXT?')
                if self.next_dl and self.next_dling and isinstance(self.next_contentId, int) and self.iterator == 100:
                    if not self.next_play:
                        xbmc.sleep(3000)
                        if not xbmcgui.Dialog().yesno(
                                self.localize('python-libtorrent'),
                                self.localize('Would you like to play next episode?'),
                                self.display_name):
                            break
                    self.contentId = self.next_contentId
                    continue
                debug('************************************* NO! break')
                break

        self.torrent.stopSession()
        self.torrent.threadComplete = True
        self.torrent.checkThread()
        if '1' != self.__settings__.getSetting("keep_files") and 'Saved Files' not in self.userStorageDirectory:
            xbmc.sleep(1000)
            clearStorage(self.userStorageDirectory)
        else:
            if self.seeding_status:
                showMessage(self.localize('Information'),
                            self.localize('Torrent is seeding. To stop it use Download Status.'), forced=True)
            else:
                if self.seeding: self.db_delete()
                showMessage(self.localize('Information'),
                            self.localize('Torrent downloading is stopped.'), forced=True)
Exemple #14
0
def init(conn, cur):
    try:
        sqlstr  = " delete from dhalldata_temp; "
        sqlstr += " delete from dhalldata "
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("清除数据,准备数据加工")
    def __init__(self, storageDirectory='', torrentFile='', torrentFilesDirectory='torrents'):
        try:
            from ASCore import TSengine as tsengine

            log('Imported TSengine from ASCore')
        except Exception, e:
            log('Error importing TSengine from ASCore. Exception: ' + str(e))
            return
Exemple #16
0
def write_config(text):
    from functions import log
    try:
        if not _self.f_config == None:
            _self.f_config.write(text)
            _self.f_config.flush()
    except Exception,e:
        log("Failed to write config",e)
Exemple #17
0
 def magnetToTorrent(self, magnet):
     try:
         from SkorbaLoader import SkorbaLoader
         torrent = SkorbaLoader(self.storageDirectory, magnet)
         torrent.magnetToTorrent(magnet)
         self.torrentFile = torrent.torrentFile
     except:
         self.torrentFile = magnet
     log('['+author+'Loader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
 def magnetToTorrent(self, magnet):
     try:
         from Libtorrent import Libtorrent
         torrent = Libtorrent(self.storageDirectory, magnet)
         torrent.magnetToTorrent(magnet)
         self.torrentFile = torrent.torrentFile
     except:
         self.torrentFile = magnet
     log('[AnteoLoader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
Exemple #19
0
def bias_invert():
    try:     
        bias = -float(_self.form_data["editBias"])
        _self.ui.editBias.setText(str(bias))
        DEV.yoko.set_voltage(bias)
        DEV.yoko.output(True)
        log("Bias: %f"%(bias))
    except Exception,e:
        log("Failed to set Bias",e)
 def getContentList(self):
     try:
         from SkorbaLoader import SkorbaLoader
         torrent = SkorbaLoader(self.storageDirectory, self.torrentFile)
         return torrent.getContentList()
     except:
         import traceback
         log(traceback.format_exc())
         return self.getContentList_engine()
    def setup_play(self):
        self.next_dling = False
        self.iterator = 0
        self.watchedTime = 0
        self.totalTime = 1
        path = self.torrent.getFilePath(self.contentId)
        label = os.path.basename(path)
        self.basename = label
        self.seeding_run = False
        listitem = xbmcgui.ListItem(label, path=path)

        if self.subs_dl:
            self.setup_subs(label, path)
        try:
            seasonId = self.get("seasonId")
            self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1
            title = urllib.unquote_plus(self.get("title")) if self.get("title") else None

            if self.get("label") and self.episodeId == self.get("episodeId"):
                label = urllib.unquote_plus(self.get("label"))
            elif seasonId and self.episodeId and title:
                label = '%s S%02dE%02d.%s (%s)' % (
                title, int(seasonId), int(self.episodeId), self.basename.split('.')[-1], self.basename)

            if seasonId and self.episodeId and label and title:
                listitem = xbmcgui.ListItem(label, path=path)

                listitem.setInfo(type='video', infoLabels={'title': label,
                                                           'episode': int(self.episodeId),
                                                           'season': int(seasonId),
                                                           'tvshowtitle': title})
        except:
            log('[TorrentPlayer] Operation INFO failed!')

        thumbnail = self.get("thumbnail")
        if thumbnail:
            listitem.setThumbnailImage(urllib.unquote_plus(thumbnail))
        self.display_name = label

        # мегакостыль!
        rpc = ({'jsonrpc': '2.0', 'method': 'Files.GetDirectory', 'params': {
            'media': 'video', 'directory': os.path.dirname(path)}, 'id': 0})
        data = json.dumps(rpc)
        request = xbmc.executeJSONRPC(data)
        response = json.loads(request)
        xbmc.sleep(1000)

        if response:
            # xbmc.Player().play(path, listitem)
            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
            playlist.clear()
            playlist.add(path, listitem)
            xbmc.Player().play(playlist)

            xbmc.sleep(2000)  # very important, do not edit this, podavan
            return True
    def setup_play(self):
        #self.next_dling = False
        #self.iterator = 0
        path = os.path.join(self.userStorageDirectory, self.c._file.path)
        label = os.path.basename(self.c._file.path)
        self.basename = label
        #self.seeding_run = False
        listitem = xbmcgui.ListItem(label)
        info={}

        #if self.subs_dl:
        #    self.setup_subs(label, path)
        try:
            seasonId = self.get("seasonId")
            self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1
            title = urllib.unquote_plus(self.get("title")) if self.get("title") else None

            if self.get("label") and self.episodeId == self.get("episodeId"):
                label = urllib.unquote_plus(self.get("label"))
            elif seasonId and self.episodeId and title:
                label = '%s S%02dE%02d.%s (%s)' % (
                title, int(seasonId), int(self.episodeId), self.basename.split('.')[-1], self.basename)

            if seasonId and self.episodeId and label and title:
                info={'title': label,
                     'episode': int(self.episodeId),
                     'season': int(seasonId),
                     'tvshowtitle': title}
        except:
            log('[BTClientPlayer] Operation INFO failed!')

        thumbnail = self.get("thumbnail")
        listitem.setInfo(type='Video', infoLabels=info)
        if thumbnail:
            listitem.setThumbnailImage(urllib.unquote_plus(thumbnail))
        self.display_name = label

        base = 'http://127.0.0.1:' + str(self.free_port) + '/'
        url = urlparse.urljoin(base, urllib.quote(self.c._file.path))
        # мегакостыль!
        rpc = ({'jsonrpc': '2.0', 'method': 'Files.GetDirectory', 'params': {
            'media': 'video', 'directory': path}, 'id': 0})
        data = json.dumps(rpc)
        request = xbmc.executeJSONRPC(data)
        response = json.loads(request)
        while not response:
            xbmc.sleep(100)
        if response:
            xbmc.sleep(3000)
            #if 1==1:
            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
            playlist.clear()
            playlist.add(url, listitem)
            xbmc.Player().play(playlist)
        log("Serving file on %s" % url)
        return True
Exemple #23
0
def lockin_set_phase():
    try:
        DEV.lockin.set_phases(
            _self.config_data["lockin_phases"][0],
            _self.config_data["lockin_phases"][1],
            _self.config_data["lockin_phases"][2],
            _self.config_data["lockin_phases"][3]
            )
    except Exception,e:
        log("Failed to set phase",e)
def config():
    global _config
    if not _config:
        with shelf("xbmctorrent.immunicity.pac_config", ttl=CACHE) as pac_config:
            log("Fetching Immunicity PAC file")
            pac_data = urllib2.urlopen(PAC_URL).read()
            pac_config["server"] = re.search(r"var proxyserver = '(.*)'", pac_data).group(1)
            pac_config["domains"] = map(lambda x: x.replace(r"\Z(?ms)", ""), map(fnmatch.translate, re.findall(r"\"(.*?)\",", pac_data)))
            _config = pac_config
    return _config
 def checkThread(self):
     if self.threadComplete == True:
         log('checkThread KIIIIIIIIIIILLLLLLLLLLLLLLL')
         try:
             self.session.remove_torrent(self.torrentHandle)
         except:
             log('RuntimeError: invalid torrent handle used')
         self.session.stop_natpmp()
         self.session.stop_upnp()
         self.session.stop_lsd()
         self.session.stop_dht()
    def initSession(self):
        self.session = self.lt.session()
        self.session.set_alert_mask(self.lt.alert.category_t.error_notification | self.lt.alert.category_t.status_notification | self.lt.alert.category_t.storage_notification)
        #self.session.set_alert_mask(self.lt.alert.category_t.all_categories)
        self.session.add_dht_router("router.bittorrent.com", 6881)
        self.session.add_dht_router("router.utorrent.com", 6881)
        self.session.start_dht()
        self.session.start_lsd()
        self.session.start_upnp()
        self.session.start_natpmp()
        try:
            self.session.listen_on(6881, 6891)
        except:
            log('listen_on(6881, 6891) error')

        #tribler example never tested
        #self.session.set_severity_level(self.lt.alert.severity_levels.info)
        #self.session.add_extension("ut_pex")
        #self.session.add_extension("lt_trackers")
        #self.session.add_extension("metadata_transfer")
        #self.session.add_extension("ut_metadata")
        # Ban peers that sends bad data
        #self.session.add_extension("smart_ban")

        # Session settings
        try:
            session_settings = self.session.get_settings()
            #
            session_settings['announce_to_all_tiers'] = True
            session_settings['announce_to_all_trackers'] = True
            session_settings['connection_speed'] = 100
            session_settings['peer_connect_timeout'] = 2
            session_settings['rate_limit_ip_overhead'] = True
            session_settings['request_timeout'] = 1
            session_settings['torrent_connect_boost'] = 100
            session_settings['user_agent'] = 'uTorrent/2200(24683)'
            #session_settings['cache_size'] = 0
            #session_settings['use_read_cache'] = False

        except:
            #0.15 compatibility
            log('[initSession]: Session settings 0.15 compatibility')
            session_settings = self.session.settings()

            session_settings.announce_to_all_tiers = True
            session_settings.announce_to_all_trackers = True
            session_settings.connection_speed = 100
            session_settings.peer_connect_timeout = 2
            session_settings.rate_limit_ip_overhead = True
            session_settings.request_timeout = 1
            session_settings.torrent_connect_boost = 100
            session_settings.user_agent = 'uTorrent/2200(24683)'
        #
        self.session.set_settings(session_settings)
Exemple #27
0
 def checkThread(self):
     if self.threadComplete == True:
         log('checkThread KIIIIIIIIIIILLLLLLLLLLLLLLL')
         try:
             self.session.remove_torrent(self.torrentHandle)
         except:
             log('RuntimeError: invalid torrent handle used')
         self.session.stop_natpmp()
         self.session.stop_upnp()
         self.session.stop_lsd()
         self.session.stop_dht()
Exemple #28
0
    def __init__(self, userStorageDirectory, torrentUrl, params={}):
        self.userStorageDirectory = userStorageDirectory
        self.torrentUrl = torrentUrl
        xbmc.Player.__init__(self)
        log("[TorrentPlayer] Initalized")
        self.params = params
        self.get = self.params.get
        self.contentId = int(self.get("url"))
        self.torrent = Downloader.Torrent(self.userStorageDirectory, self.torrentUrl, self.torrentFilesDirectory).player
        try:
            if self.get("url2"):
                self.ids_video = urllib.unquote_plus(self.get("url2")).split(",")
            else:
                self.ids_video = self.get_ids()
        except:
            pass
        self.init()
        self.setup_torrent()
        if self.buffer():
            while True:
                if self.setup_play():
                    debug("************************************* GOING LOOP")
                    self.torrent.startSession()
                    self.torrent.continueSession(self.contentId)
                    self.loop()
                    WatchedHistoryDB().add(
                        self.basename, self.watchedTime, self.totalTime, self.contentId, self.fullSize / 1024 / 1024
                    )
                else:
                    break
                debug("************************************* GO NEXT?")
                if self.next_dl and self.next_dling and isinstance(self.next_contentId, int) and self.iterator == 100:
                    self.contentId = self.next_contentId
                    continue
                debug("************************************* NO! break")
                break

        self.torrent.stopSession()
        self.torrent.threadComplete = True
        self.torrent.checkThread()
        if "1" != self.__settings__.getSetting("keep_files") and "Saved Files" not in self.userStorageDirectory:
            xbmc.sleep(1000)
            clearStorage(self.userStorageDirectory)
        else:
            if self.seeding_status:
                showMessage(
                    self.localize("Information"),
                    self.localize("Torrent is seeding. To stop it use Download Status."),
                    forced=True,
                )
            else:
                if self.seeding:
                    self.db_delete()
                showMessage(self.localize("Information"), self.localize("Torrent downloading is stopped."), forced=True)
Exemple #29
0
    async def doc(self, ctx):
        functions.log(ctx.guild.name, ctx.author, ctx.command)

        embed=discord.Embed(
            colour=discord.Colour.orange(),
            title = "Unofficial documentation of RecNet API, made by ColinXYZ",
            description = "[Documentation Link](https://documenter.getpostman.com/view/13848200/TVt184DN)"
        )

        functions.embed_footer(ctx, embed) # get default footer from function
        await ctx.send(embed=embed)
 def magnetToTorrent(self, magnet):
     try:
         from Libtorrent import Libtorrent
         torrent = Libtorrent(self.storageDirectory, magnet)
         torrent.magnetToTorrent(magnet)
         self.torrentFile = torrent.torrentFile
         log('[AceStream][magnetToTorrent]: self.torrentFile '+str(self.torrentFile))
         return self.torrentFile
     except:
         magnet_alert()
         exit()
Exemple #31
0
 def init(self):
     self.next_dl = True if self.__settings__.getSetting("next_dl") == "true" and self.ids_video else False
     log("[TorrentPlayer]: init - " + str(self.next_dl))
     self.next_contentId = False
     self.display_name = ""
     self.downloadedSize = 0
     self.dialog = xbmcgui.Dialog()
     self.on_playback_started = []
     self.on_playback_resumed = []
     self.on_playback_paused = []
     self.on_playback_stopped = []
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            self.magnetLink = torrentUrl
            self.magnetToTorrent(torrentUrl)
            self.magnetLink = None
            return self.torrentFile
        else:
            if not xbmcvfs.exists(self.torrentFilesPath):
                xbmcvfs.mkdirs(self.torrentFilesPath)
            torrentFile = self.torrentFilesPath + self.md5(
                torrentUrl) + '.torrent'
            try:
                if not re.match("^http\:.+$", torrentUrl):
                    content = xbmcvfs.File(torrentUrl, "rb").read()
                else:
                    request = urllib2.Request(torrentUrl)
                    request.add_header('Referer', torrentUrl)
                    request.add_header('Accept-encoding', 'gzip')
                    result = urllib2.urlopen(request)
                    if result.info().get('Content-Encoding') == 'gzip':
                        buf = StringIO(result.read())
                        f = gzip.GzipFile(fileobj=buf)
                        content = f.read()
                    else:
                        content = result.read()

                localFile = xbmcvfs.File(torrentFile, "w+b")
                localFile.write(content)
                localFile.close()
            except Exception, e:
                log('Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(e))
                return
            if xbmcvfs.exists(torrentFile):
                try:
                    e=self.lt.bdecode(xbmcvfs.File(torrentFile,'rb').read())
                    self.torrentFileInfo = self.lt.torrent_info(e)
                except Exception, e:
                    log('Exception: ' + str(e))
                    xbmcvfs.delete(torrentFile)
                    return
                baseName = file_encode(os.path.basename(self.getFilePath()))
                if not xbmcvfs.exists(self.torrentFilesPath):
                    xbmcvfs.mkdirs(self.torrentFilesPath)
                newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5(
                    torrentUrl) + '.torrent'  # + '.'+ baseName
                if xbmcvfs.exists(newFile):
                    xbmcvfs.delete(newFile)
                if not xbmcvfs.exists(newFile):
                    try:
                        xbmcvfs.rename(torrentFile, newFile)
                    except Exception, e:
                        print 'Unable to rename torrent file from "' + torrentFile + '" to "' + newFile + '" in Torrent::renameTorrent' + '. Exception: ' + str(
                            e)
                        return
Exemple #33
0
    def __init__(self,
                 storageDirectory='',
                 torrentFile='',
                 torrentFilesDirectory='torrents'):
        try:
            from ASCore import TSengine as tsengine

            log('Imported TSengine from ASCore')
        except Exception, e:
            log('Error importing TSengine from ASCore. Exception: ' + str(e))
            return
Exemple #34
0
    def __init__(self, userStorageDirectory, torrentUrl, params={}):
        self.userStorageDirectory = userStorageDirectory
        self.torrentUrl = torrentUrl
        xbmc.Player.__init__(self)
        log("["+author+"Player] Initalized v"+__version__)
        self.params = params
        self.get = self.params.get
        self.contentId = int(self.get("url"))
        if self.get("seek"):
            self.seek = int(self.get("seek"))
        #self.torrent = AnteoLoader(self.userStorageDirectory, self.torrentUrl, self.torrentFilesDirectory)
        self.init()
        self.setup_engine()
        with closing(self.engine):
            self.engine.start(self.contentId)
            self.setup_nextep()
            while True:
                if self.buffer():
                    log('[AnteoPlayer]: ************************************* GOING LOOP')
                    if self.setup_play():
                        self.setup_subs()
                        self.loop()
                        WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize)
                    else:
                        log('[AnteoPlayer]: ************************************* break')
                        break
                    log('[AnteoPlayer]: ************************************* GO NEXT?')
                    if self.next_dl and self.next_contentId != False and isinstance(self.next_contentId, int) and self.iterator == 100:
                        if not self.next_play:
                            xbmc.sleep(3000)
                            if not xbmcgui.Dialog().yesno(
                                self.localize('[%sPlayer v%s] ' % (author, __version__)),
                                self.localize('Would you like to play next episode?')):
                                break
                        self.contentId = self.next_contentId
                        continue

                    log('[AnteoPlayer]: ************************************* NO! break')
                break

        xbmc.Player().stop()

        if '1' != self.__settings__.getSetting("keep_files") and 'Saved Files' not in self.userStorageDirectory:
            xbmc.sleep(1000)
            clearStorage(self.userStorageDirectory)
        else:
            #if self.seeding_status:
            #showMessage(self.localize('Information'),
            #            self.localize('Torrent is seeding. To stop it use Download Status.'), forced=True)
            #else:
            #if self.seeding: self.db_delete()
            showMessage(self.localize('Information'),
                        self.localize('Torrent downloading is stopped.'), forced=True)
Exemple #35
0
async def execute(ctx, params):
    settings = ctx['settings']
    guild = ctx['guild']
    if settings['enabled']:
        return False, "Already enabled. Use '{}disable' to turn off.".format(
            ctx['print_prefix'])
    else:
        log("Enabling", guild)
        settings['enabled'] = True
        utils.set_serv_settings(guild, settings)
        return True, "Enabling auto voice channels. Turn off with '{}disable'.".format(
            ctx['print_prefix'])
Exemple #36
0
def config():
    shelf = None
    try:
        CONFIG_LOCK.acquire()
        filename = os.path.join(CACHE_DIR, "antizapret.pac_config2")
        try:
            shelf = shelve.open(filename)
        except anydbm.error:
            os.remove(filename)
            shelf = shelve.open(filename)

        created_at = 0
        data = {}

        if 'created_at' in shelf:
            created_at = shelf['created_at']

        if 'data' in shelf:
            data = shelf['data']

        if((time.time() - created_at) <= CACHE_LIFETIME
                and 'domains' in data
                and len(data['domains']) > 0):
            return data

        log("[antizapret]: Fetching Antizapret PAC file on %s" %PAC_URL)
        try:
            pac_data = urllib2.urlopen(PAC_URL).read()
        except:
            pac_data = ""

        r = re.search(r"\"PROXY (.*); DIRECT", pac_data)
        if r:
            data["server"] = r.group(1)
            data["domains"] = map(lambda x: x.replace(r"\Z(?ms)", "").replace("\\", ""), map(fnmatch.translate, re.findall(r"\"(.*?)\",", pac_data)))
        else:
            data["server"] = None
            data["domains"] = []

        shelf.clear()
        shelf.update({
            "created_at": time.time(),
            "data": data,
        })
        return data
    except Exception as ex:
        debug("[antizapret]: " + str(ex))
        raise
    finally:
        if shelf:
            shelf.close()
        if CONFIG_LOCK.locked():
            CONFIG_LOCK.release()
 def init(self):
     self.next_dl = True if self.__settings__.getSetting(
         'next_dl') == 'true' and self.ids_video else False
     log('[TorrentPlayer]: init - ' + str(self.next_dl))
     self.next_contentId = False
     self.display_name = ''
     self.downloadedSize = 0
     self.dialog = xbmcgui.Dialog()
     self.on_playback_started = []
     self.on_playback_resumed = []
     self.on_playback_paused = []
     self.on_playback_stopped = []
Exemple #38
0
def xiaoshou28_moban(conn, cur):
    #2. xiaoshou28
    try:
        sqlstr = """
            insert into dhalldata_temp
            select braid, proid
            from xiaoshou28_res
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("创建门店代码商品代码xiaoshou_moban失败!", logfile)
Exemple #39
0
def cl_moban(conn, cur):
    #3 cl
    try:
        sqlstr = """
            insert into dhalldata_temp
            select mdcode, spcode
            from cl
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("创建门店代码商品代码cl_moban失败!", logfile)
Exemple #40
0
def validSession():
    try:
        userId = session.getSessionUserId()
        if userId is None:
            res = Response(False, '会话已失效', {})
        else:
            res = Response(True, '会话有效', {})
    except Exception as e:
        log('在处理会话验证请求时未能捕获的错误,错误信息:')
        log(e)
        res = Response(False, '服务器错误', {})
    return res.getJson()
 def magnetToTorrent(self, magnet):
     try:
         from Libtorrent import Libtorrent
         torrent = Libtorrent(self.storageDirectory, magnet)
         torrent.magnetToTorrent(magnet)
         self.torrentFile = torrent.torrentFile
         log('[AceStream][magnetToTorrent]: self.torrentFile ' +
             str(self.torrentFile))
         return self.torrentFile
     except:
         magnet_alert()
         exit()
Exemple #42
0
    def loop(self):
        #debug_counter=0
        with closing(
                OverlayText(w=OVERLAY_WIDTH,
                            h=OVERLAY_HEIGHT,
                            alignment=XBFONT_CENTER_X
                            | XBFONT_CENTER_Y)) as overlay:
            with nested(
                    self.attach(overlay.show, self.on_playback_paused),
                    self.attach(overlay.hide, self.on_playback_resumed,
                                self.on_playback_stopped)):
                while True:
                    if xbmc.abortRequested or not self.isPlaying():
                        break

                    #if self.iterator == 100 and debug_counter < 100:
                    #    debug_counter += 1
                    #else:
                    #    self.torrent.debug()
                    #    debug_counter=0
                    status = self.c.status
                    overlay.text = "\n".join(self._get_status_lines(status))
                    self.iterator = int(status.progress * 100)
                    xbmc.sleep(1000)
                    if self.iterator == 100 and self.next_dl:
                        next_contentId_index = self.ids_video.index(
                            str(self.contentId)) + 1
                        if len(self.ids_video) > next_contentId_index:
                            self.next_contentId = int(
                                self.ids_video[next_contentId_index])
                        else:
                            self.next_contentId = False
                            log('[loop] next_contentId: ' +
                                str(self.next_contentId))
                    if not self.seeding_run and self.iterator == 100 and self.seeding:
                        self.seeding_run = True
                        self.seed(self.contentId)
                        self.seeding_status = True
                        # xbmc.sleep(7000)
                    if self.iterator == 100 and self.next_dl and not self.next_dling and isinstance(
                            self.next_contentId,
                            int) and self.next_contentId != False:
                        showMessage(
                            self.localize('Torrent Downloading'),
                            self.localize('Starting download next episode!'),
                            forced=True)
                        self.torrent.stopSession()
                        # xbmc.sleep(1000)
                        path = self.torrent.getFilePath(self.next_contentId)
                        self.basename = self.display_name = os.path.basename(
                            path)
                        self.torrent.continueSession(self.next_contentId)
                        self.next_dling = True
Exemple #43
0
def sugvalue_moban(conn, cur):
    #1. 订货md,sp
    try:
        sqlstr = """
            insert into dhalldata_temp
            select braid, proid
            from  sugvalue
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("创建门店代码商品代码sugvalue_moban失败!", logfile)
Exemple #44
0
def aviser_les_boys_sur_discord(nouvelles_notes, loop):
    if (nouvelles_notes != []):
        msg = "On a une ou des notes de sorties pour les cours suivant \n"
        msg += func.CreateListMessage(nouvelles_notes)
        func.log("New note found")
        try:
            send_fut = asyncio.run_coroutine_threadsafe(
                sendMessage(new_note_channel_id, msg), loop)
            send_fut.result()
        except Exception as ex:
            print("Aviser les boys exception: " + ex.args[0])
            pass
Exemple #45
0
 async def on_message(self, message):
     # ===========================LOG=============================
     ln = '\n'
     n_ln = '\\n'
     # Build a log of this message
     log_msg = ''
     log_dict = {'log': 'message', 'timestamp': now()}
     if message.author.bot:
         log_msg += f'Message logged at {now()} by Bot {message.author}'
         log_dict['bot'] = True
     else:
         log_msg += f'Message logged at {now()} by User {message.author}'
         log_dict['bot'] = False
     log_dict['author'] = {
         'id': message.author.id,
         'name': message.author.name
     }
     if message.guild is not None:
         log_msg += f' in Guild: {message.guild} in Channel {message.channel}:'
         log_dict['guild'] = {
             'id': message.guild.id,
             'name': message.guild.name
         }
         log_dict['channel'] = {
             'id': message.channel.id,
             'name': message.channel.name
         }
     else:
         log_msg += f' in Channel {message.channel}:'
         log_dict['guild'] = {'id': 'private', 'name': message.author.name}
         log_dict['channel'] = {
             'id': message.channel.id,
             'name': message.author.name
         }
     if message.content != "":
         log_msg += f" with Content: {message.system_content.replace(ln, n_ln)}"
         log_dict['content'] = message.content
     if len(message.embeds) > 0:
         log_msg += f' with Embed: {message.embeds[0].to_dict()}'
         log_dict['embed'] = message.embeds[0].to_dict()
     if len(message.attachments) > 0:
         log_msg += f' with Attachment: {message.attachments[0].filename},{message.attachments[0].url}'
         log_dict['attachment'] = {
             'filename': message.attachments[0].filename,
             'url': message.attachments[0].url
         }
     # Log message
     # log(log_dict)
     try:
         log(log_msg, message)
     except AttributeError:
         print(log_msg)
Exemple #46
0
 def __init__(self, information):
     self.title = information['title'].replace('"', "'")
     self.id = information['id']
     self.dircetors = '/'.join(information['directors']).replace('"', "'")
     self.casts = '/'.join(information['casts']).replace('"', "'")
     self.image = information['cover']
     self.rate = information['rate'] if len(information['rate']) != 0 else 0
     self.star = information['star'] if len(information['star']) != 0 else 0
     self.url = information['url']
     try:
         content = requests.get(api[1] + self.id).text
     except (ConnectionRefusedError, ConnectionError,
             ConnectionAbortedError):  # 检测连接是否被拒绝
         log('连接被拒绝 切换ip', 2)
         change_ip()
         content = requests.get(api[1] + self.id).text
     if '检测到' in str(content) or '#info' not in str(content):  # 检测ip是否被ban
         log('ip 被ban 切换ip', 2)
         change_ip()
         content = requests.get(api[1] + self.id).text
     soup = BeautifulSoup(content, "html.parser")
     self.type = '/'.join(
         re.findall(
             '[\u4e00-\u9fa5]{2}',
             str(soup.find_all('span',
                               attrs={'property':
                                      "v:genre"})))).replace('剧情/', '')
     try:
         self.date = soup.find('span',
                               attrs={
                                   'property': 'v:initialReleaseDate'
                               }).text
     except AttributeError:
         self.date = '--'
     try:
         self.plot = str(
             next(
                 soup.find('span', attrs={
                     'property': 'v:summary'
                 }).stripped_strings)).replace('"', "'")
     except (AttributeError, StopIteration):
         self.plot = '--'
     try:
         self.runtime = re.findall(
             r'片长: \d+分钟|片长: \d+分|片长: \d+min|片长: \d+ 分钟|片长: \d+ 分|片长: \d+ min',
             soup.select_one('#info').text)[0][3:]
     except (IndexError, AttributeError):
         self.runtime = '--'
     try:
         self.screenwriter = soup.select('.attrs')[1].text.replace('"', "'")
     except IndexError:
         self.screenwriter = '--'
Exemple #47
0
    def initSession(self):
        self.session = self.lt.session()
        self.session.set_alert_mask(self.lt.alert.category_t.error_notification | self.lt.alert.category_t.status_notification | self.lt.alert.category_t.storage_notification)
        #self.session.set_alert_mask(self.lt.alert.category_t.all_categories)
        self.session.add_dht_router("router.bittorrent.com", 6881)
        self.session.add_dht_router("router.utorrent.com", 6881)
        self.session.add_dht_router("router.bitcomet.com", 6881)
        self.session.start_dht()
        self.session.start_lsd()
        self.session.start_upnp()
        self.session.start_natpmp()
        self.session.listen_on(6881, 6891)

        #tribler example never tested
        #self.session.set_severity_level(self.lt.alert.severity_levels.info)
        #self.session.add_extension("ut_pex")
        #self.session.add_extension("lt_trackers")
        #self.session.add_extension("metadata_transfer")
        #self.session.add_extension("ut_metadata")
        # Ban peers that sends bad data
        #self.session.add_extension("smart_ban")

        # Session settings
        try:
            session_settings = self.session.get_settings()
            #
            session_settings['announce_to_all_tiers'] = True
            session_settings['announce_to_all_trackers'] = True
            session_settings['connection_speed'] = 100
            session_settings['peer_connect_timeout'] = 2
            session_settings['rate_limit_ip_overhead'] = True
            session_settings['request_timeout'] = 1
            session_settings['torrent_connect_boost'] = 100
            session_settings['user_agent'] = 'uTorrent/2200(24683)'
            #session_settings['cache_size'] = 0
            #session_settings['use_read_cache'] = False

        except:
            #0.15 compatibility
            log('[initSession]: Session settings 0.15 compatibility')
            session_settings = self.session.settings()

            session_settings.announce_to_all_tiers = True
            session_settings.announce_to_all_trackers = True
            session_settings.connection_speed = 100
            session_settings.peer_connect_timeout = 2
            session_settings.rate_limit_ip_overhead = True
            session_settings.request_timeout = 1
            session_settings.torrent_connect_boost = 100
            session_settings.user_agent = 'uTorrent/2200(24683)'
        #
        self.session.set_settings(session_settings)
Exemple #48
0
def cuxiao(conn, cur):
    #9.3 cuxiao
    try:
        sqlstr = """
            update dhalldata
            set cuxiao_1 = 'T'
            from pmt as t
            where mdcode = t.braid and spcode = t.proid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("cuxiao更新数据失败!", logfile)
Exemple #49
0
def delivery(conn, cur):
    #9.1 delivery
    try:
        sqlstr = """
            update dhalldata
            set delivery = 'T'
            from delivery as t
            where mdcode = t.braid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("delivery更新数据失败!", logfile)
Exemple #50
0
def packetqty1(conn, cur):
    #7.packetqty1
    try:
        sqlstr = """
            update dhalldata
            set packetqty1 = t.packetqty1
            from product_gl_packetqty as t
            where spcode = t.proid 
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("packetqty1更新数据失败!", logfile)
Exemple #51
0
def yqminlimit(conn, cur):
    #9.yqminlimit
    try:
        sqlstr = """
            update dhalldata
            set yqminlimit = t.yqminlimit
            from dhrules_today_minlimit as t
            where spcode = t.proid and mdcode = t.braid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("yqminlimit更新数据失败!", logfile)
async def on_guild_remove(guild):
    num_members = len([m for m in guild.members if not m.bot])
    if cfg.SAPPHIRE_ID is None:
        settings = utils.get_serv_settings(guild)
        settings['left'] = datetime.now(
            pytz.timezone(
                cfg.CONFIG['log_timezone'])).strftime("%Y-%m-%d %H:%M")
        utils.set_serv_settings(guild, settings)
        log("Left guild {} `{}` with {} members".format(
            guild.name, guild.id, num_members))
    await func.admin_log(
        ":new_moon: Left: **{}** (`{}`) - **{}** members".format(
            func.esc_md(guild.name), guild.id, num_members), client)
Exemple #53
0
def mdsp(conn, cur):
    #6.1 mdsp
    try:
        sqlstr = """
            update dhalldata
            set status = t.status
            from v_com_product as t
            where spcode = t.proid and mdcode = t.braid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("mdsp更新数据失败")
Exemple #54
0
def dhtag(conn, cur):
    #9.2 dhtag
    try:
        sqlstr = """
            update dhalldata
            set dhtag = 'T'
            from dhpauserules_today as t
            where mdcode = t.braid and spcode = t.proid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("dhtag更新数据失败!", logfile)
Exemple #55
0
def dhalldata_update(conn, cur):
    #5. mdcode
    try:
        sqlstr = """
            update dhalldata
            set mdname = t.braname
            from branch as t
            where mdcode = t.braid
        """
        cur.execute(sqlstr)
        conn.commit()
    except:
        functions.log("向dhalldata更新数据失败!", logfile)
Exemple #56
0
 def setup_subs(self):
     if self.subs_dl:
         file_status = self.engine.file_status(self.contentId)
         subs = []
         filename = os.path.basename(file_status.name)
         sub_files = self.engine.list(media_types=[MediaType.SUBTITLES])
         for i in sub_files:
             if isSubtitle(filename, i.name):
                 subs.append(i)
         if subs:
             log("[AnteoPlayer][setup_subs]: Detected subtitles: %s" % str(subs))
             for sub in subs:
                 xbmc.Player().setSubtitles(sub.url)
Exemple #57
0
def make_zipfile(file_path, file_name):
    source_dir = file_path + file_name
    output_filename = file_path + 'archving/' + file_name + '.zip'
    if not os.path.exists(file_path + 'archving'):
        os.makedirs(file_path + 'archving')

    with zipfile.ZipFile(output_filename, 'w') as _z:
        _z.write(source_dir,
                 os.path.basename(source_dir),
                 compress_type=zipfile.ZIP_DEFLATED)
        os.remove(source_dir)

    functions.log('############# SUCCESS #############')
Exemple #58
0
    def __init__(self, userStorageDirectory, torrentUrl, params={}):
        print '!!!!!!!!!!!!!!!!!! BORN ' + self.__class__.__name__
        self.userStorageDirectory = userStorageDirectory
        self.torrentUrl = torrentUrl
        xbmc.Player.__init__(self)
        log("[BTClientPlayer] Initalized")
        self.params = params
        self.get = self.params.get
        self.contentId = int(self.get("url"))
        self.platform = get_platform()
        self.init()

        self.torrent = Downloader.Torrent(self.userStorageDirectory,
                                          self.torrentUrl,
                                          self.torrentFilesDirectory).player
        self.lt = self.torrent.lt
        try:
            if self.get("url2"):
                self.ids_video = urllib.unquote_plus(
                    self.get("url2")).split(',')
            else:
                self.ids_video = self.get_ids()
        except:
            pass

        args = Namespace(
            bt_download_limit=self.download_limit,  #KB
            bt_upload_limit=self.upload_limit,
            choose_subtitles=False,
            clear_older=0,
            debug_log=os.path.join(self.userStorageDirectory, 'log.txt'),
            delete_on_finish=False,
            directory=self.userStorageDirectory,
            listen_port_max=6891,  #
            listen_port_min=6881,
            no_resume=False,
            player='kodi',
            port=5001,
            print_pieces=False,
            quiet=False,
            stdin=False,
            stream=True,
            subtitles=None,
            trace=True,
            content_id=self.contentId,
            url=self.torrentUrl)
        args = main(args)  #config
        self.free_port = args.port
        log('BTClientPlayer: args ' + str(args))

        self.btclient = self.stream(args, BTClient)
Exemple #59
0
    def handle_read(self):
        '''
		Perform the actual socket read attempt. Append anything received to the inbound
		buffer.
		'''
        try:
            self.inbound_frame_buffer.append(self.recv())
            if self.debug:
                #print(f"Grapevine In: {self.inbound_frame_buffer[-1]}")
                #print("")
                log(f"\nGrapevine In: {self.inbound_frame_buffer[-1]}",
                    "debug")
        except:
            pass
async def lingering_secondaries(client):
    await client.wait_until_ready()

    lingering_secondaries.last_run = datetime.now(pytz.utc)
    start_time = time()
    if client.is_ready():
        potentials = None
        with concurrent.futures.ThreadPoolExecutor() as pool:
            potentials = await client.loop.run_in_executor(
                pool, get_potentials)
        potentials = potentials.split('\n')
        if potentials:
            # Sets apparently give better performance. Discard all but last 10k.
            potentials = set(potentials[-10000:])
            for guild in func.get_guilds(client):
                settings = utils.get_serv_settings(guild)
                if not settings['enabled'] or not settings['auto_channels']:
                    continue
                secondaries = func.get_secondaries(guild,
                                                   settings=settings,
                                                   include_jc=True)
                voice_channels = [
                    x for x in guild.channels
                    if isinstance(x, discord.VoiceChannel)
                ]
                for v in voice_channels:
                    if v.id not in secondaries and str(
                            v.id
                    ) in potentials and not func.channel_is_requested(v):
                        if v.name not in ['⌛', '⚠']:
                            try:
                                await v.edit(name='⚠')
                                log("Remembering channel {}".format(v.id),
                                    guild)
                                await func.admin_log(
                                    "⚠ Remembering channel `{}` in guild **{}**"
                                    .format(v.id, guild.name), client)
                            except discord.errors.NotFound:
                                pass
                            except Exception:
                                traceback.print_exc()

                    await asyncio.sleep(0)
                await asyncio.sleep(0)

        end_time = time()
        fn_name = "lingering_secondaries"
        cfg.TIMINGS[fn_name] = end_time - start_time
        if cfg.TIMINGS[fn_name] > 5:
            await func.log_timings(client, fn_name)