当前位置: 首页>>代码示例>>Python>>正文


Python TorrentDef.TorrentDef类代码示例

本文整理汇总了Python中BaseLib.Core.TorrentDef.TorrentDef的典型用法代码示例。如果您正苦于以下问题:Python TorrentDef类的具体用法?Python TorrentDef怎么用?Python TorrentDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TorrentDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_torrent

def create_torrent(file, port, try_vod = True):
    '''
    Creates a torrent for the given file. Returns a string representing the
    path to the torrent file.
    If try_vod is True try to add the playtime to the torrent making it "streamable".
    '''
    
    # generate torrent    
    tdef = TorrentDef()
    url = "http://localhost:%s/announce/" % port
    tdef.set_tracker(url)
    #tdef.set_create_merkle_torrent(True)
    #tdef.set_piece_length(self._pieceSize)
    
    if try_vod:
        torrent_name = FileUtils.get_relative_filename(file) + constants.TORRENT_VOD_EXT
        # set playtime
        playtime = videostats_via_ffmpeg(file)['playtime']
        print "playtime", playtime
    else:
        torrent_name = FileUtils.get_relative_filename(file) + constants.TORRENT_DOWNLOAD_EXT
        playtime = None
        print "Create a non-streamable torrent"
            
    tdef.add_content(file, playtime=playtime)
    tdef.finalize()
    
    torrent_dir = os.getcwd()
    torrent = os.path.join(torrent_dir, torrent_name)
    tdef.save(torrent)
    
    print "created torrent file: %s" % torrent
    print "Tracker uses the announce URL: %s" % tdef.get_tracker()

    return tdef
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:35,代码来源:create_torrent.py

示例2: addTorrentToDB

    def addTorrentToDB(self, filename, torrent_hash, metadata, source='BC', extra_info={}, hack=False):
        """ Arno: no need to delegate to olbridge, this is already run by OverlayThread """
        # 03/02/10 Boudewijn: addExternalTorrent now requires a
        # torrentdef, consequently we provide the filename through the
        # extra_info dictionary
        torrentdef = TorrentDef.load(filename)
        if not 'filename' in extra_info:
            extra_info['filename'] = filename
        torrent = self.torrent_db.addExternalTorrent(torrentdef, source, extra_info)
        if torrent is None:
            return

        # Arno, 2008-10-20: XXX torrents are filtered out in the final display stage
        self.launchmany.set_activity(NTFY_ACT_GOT_METADATA,unicode('"'+torrent['name']+'"'),torrent['category'])

        if self.initialized:
            self.num_torrents += 1 # for free disk limitation
        
            if not extra_info:
                self.refreshTrackerStatus(torrent)
            
            if len(self.recently_collected_torrents) < 50:    # Queue of 50
                self.recently_collected_torrents.append(torrent_hash)
            else:
                self.recently_collected_torrents.pop(0)
                self.recently_collected_torrents.append(torrent_hash)
开发者ID:Anaconda84,项目名称:Anaconda,代码行数:26,代码来源:MetadataHandler.py

示例3: testRetrieveLocalPeersForActiveTorrents

 def testRetrieveLocalPeersForActiveTorrents(self):
     tdef = TorrentDef.load("torrents/ubuntu.torrent")
     infohash_hex = common_utils.get_id(tdef)
     torrent_dict = self.wsclient.retrieve_local_peers_for_active_torrents(list_of_torrent_ids=[infohash_hex],
                                                            maximum_number_of_peers=10,
                                                            include_seeds=False)
     assert len(torrent_dict) >= 0, torrent_dict
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:7,代码来源:TestIoP_WSClient.py

示例4: start_torrent

 def start_torrent(self, torrent):
     tdef = TorrentDef.load(torrent)
     
     if not os.access(self._directory, os.F_OK):
         os.makedirs(self._directory)
     
     dscfg = DownloadStartupConfig()
     dscfg.set_dest_dir(self._directory)
     dscfg.set_video_events([simpledefs.VODEVENT_START,
                             simpledefs.VODEVENT_PAUSE,
                             simpledefs.VODEVENT_RESUME])
     dscfg.set_max_speed(simpledefs.DOWNLOAD, self._max_dl_rate)
     dscfg.set_max_speed(simpledefs.UPLOAD, self._max_ul_rate)
     dscfg.set_peer_type("S")
     #dscfg.set_video_event_callback(self.video_callback) # supporter should not play the files !
     
     d = self._session.start_download(tdef, dscfg)
     d.set_state_callback(self.state_callback)
     
     time.sleep(1) # give the download some time to fully initialize
     d.sd.dow.choker.set_supporter_server(True)
     
     
     self._tracker_url = tdef.get_tracker()[:tdef.get_tracker().find("announce")]
     self._id = d.sd.peerid
     self._choke_objects.append(d.sd.dow.choker)
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:26,代码来源:Supporter.py

示例5: isValidRemoteVal

def isValidRemoteVal(d,selversion):
    if not isinstance(d,dict):
        if DEBUG:
            print >>sys.stderr,"rqmh: reply: a: value not dict"
        return False
    if selversion >= OLPROTO_VER_TWELFTH:
        if not ('content_name' in d and 'length' in d and 'leecher' in d and 'seeder' in d and 'category' in d and 'torrent_size' in d and 'channel_permid' in d and 'channel_name' in d):
            if DEBUG:
                print >>sys.stderr,"rqmh: reply: torrentrec12: key missing, got",d.keys()
            return False
        if 'metatype' in d and 'metadata' in d:
            try:
                metatype = d['metatype']
                metadata = d['metadata']
                if metatype == URL_MIME_TYPE:
                    tdef = TorrentDef.load_from_url(metadata)
                else:
                    metainfo = bdecode(metadata)
                    tdef = TorrentDef.load_from_dict(metainfo)
            except:
                if DEBUG:
                    print >>sys.stderr,"rqmh: reply: torrentrec12: metadata invalid"
                    print_exc()
                return False

    elif selversion >= OLPROTO_VER_ELEVENTH:
        if not ('content_name' in d and 'length' in d and 'leecher' in d and 'seeder' in d and 'category' in d and 'torrent_size' in d and 'channel_permid' in d and 'channel_name' in d):
            if DEBUG:
                print >>sys.stderr,"rqmh: reply: torrentrec11: key missing, got",d.keys()
            return False
        
    elif selversion >= OLPROTO_VER_NINETH:
        if not ('content_name' in d and 'length' in d and 'leecher' in d and 'seeder' in d and 'category' in d and 'torrent_size' in d):
            if DEBUG:
                print >>sys.stderr,"rqmh: reply: torrentrec9: key missing, got",d.keys()
            return False
    else:
        if not ('content_name' in d and 'length' in d and 'leecher' in d and 'seeder' in d and 'category' in d):
            if DEBUG:
                print >>sys.stderr,"rqmh: reply: torrentrec6: key missing, got",d.keys()
            return False
        
#    if not (isinstance(d['content_name'],str) and isinstance(d['length'],int) and isinstance(d['leecher'],int) and isinstance(d['seeder'],int)):
#        return False
#    if len(d) > 4: # no other keys
#        return False
    return True
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:47,代码来源:RemoteQueryMsgHandler.py

示例6: setUpPostSession

    def setUpPostSession(self):
        """ override TestAsServer """
        TestAsServer.setUpPostSession(self)

        self.mypermid = str(self.my_keypair.pub().get_der())
        self.hispermid = str(self.his_keypair.pub().get_der()) 

        # Create URL compat torrents and save in Torrent database.
        self.tdef1 = TorrentDef.load_from_url(P2PURL_SCHEME+'://127.2.3.42:7764/announce?SjaakCam.mpegts&k=MHowDQYJKoZIhvcNAQEBBQADaQAwZgJhAN0Khlp5ZhWC7VfLynCkKts71b8h8tZXH87PkDtJUTJaX_SS1Cddxkv63PRmKOvtAHhkTLSsWOZbSeHkOlPIq_FGg2aDLDJ05g3lQ-8mSmo05ff4SLqNUTShWO2CR2TPhQIBAw&l=HCAAAA&s=15&a=RSA&b=AAIAAA')
        self.torrentfn1 = os.path.join(self.session.get_torrent_collecting_dir(),"live.torrent")
        self.tdef1.save(self.torrentfn1)

        self.tdef2 = TorrentDef.load_from_url(P2PURL_SCHEME+'://127.1.0.10:6969/announce?trailer.mkv&r=TTgcifG0Ot7STCY2JL8SUOxROFo&l=AKK35A&s=15&b=AAFnGg')
        self.torrentfn2 = os.path.join(self.session.get_torrent_collecting_dir(),"vod.torrent")
        self.tdef2.save(self.torrentfn2)

        self.torrent_db = self.session.open_dbhandler(NTFY_TORRENTS)
        extra_info = {'status':'good'}
        self.torrent_db.addExternalTorrent(self.torrentfn1, source='',extra_info=extra_info)
        self.torrent_db.addExternalTorrent(self.torrentfn2, source='',extra_info=extra_info)
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:20,代码来源:test_url_metadata.py

示例7: setUpPostSession

    def setUpPostSession(self):
        """ override TestAsServer """
        TestAsServer.setUpPostSession(self)
        self.hispermid = str(self.his_keypair.pub().get_der())
        self.my_permid = str(self.my_keypair.pub().get_der())

        self.content_name = 'Hallo S22E44'
        self.tdef = TorrentDef()
        self.tdef.set_tracker('http://localhost:0/announce')
        self.tdef.set_piece_length(2 ** 15)
        self.tdef.create_live(self.content_name,2 ** 16)
        self.tdef.finalize()
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:12,代码来源:test_rquery_reply_active.py

示例8: read_and_send_metadata

    def read_and_send_metadata(self, permid, infohash, torrent_path, selversion):
        torrent_data = self.read_torrent(torrent_path)
        if torrent_data:
            # Arno: Don't send private torrents
            try:
                metainfo = bdecode(torrent_data)
                if 'info' in metainfo and 'private' in metainfo['info'] and metainfo['info']['private']:
                    if DEBUG:
                        print >> sys.stderr,"metadata: Not sending torrent", `torrent_path`,"because it is private"
                    return 0
            except:
                print_exc()
                return 0
            

            if DEBUG:
                print >> sys.stderr,"metadata: sending torrent", `torrent_path`, len(torrent_data)
                
            torrent = {}
            torrent['torrent_hash'] = infohash
            # P2PURLs: If URL compat then send URL
            tdef = TorrentDef.load_from_dict(metainfo)
            if selversion >= OLPROTO_VER_ELEVENTH and tdef.get_url_compat():
                torrent['metatype'] = URL_MIME_TYPE
                torrent['metadata'] = tdef.get_url()
            else:
                torrent['metatype'] = TSTREAM_MIME_TYPE
                torrent['metadata'] = torrent_data
                
            if selversion >= OLPROTO_VER_FOURTH:
                data = self.torrent_db.getTorrent(infohash)
                if data is None:
                    # DB inconsistency
                    return 0
                nleechers = data.get('leecher', -1)
                nseeders = data.get('seeder', -1)
                last_check_ago = int(time()) - data.get('last_check_time', 0)    # relative time
                if last_check_ago < 0:
                    last_check_ago = 0
                status = data.get('status', 'unknown')
                
                torrent.update({'leecher':nleechers,
                                'seeder':nseeders,
                                'last_check_time':last_check_ago,
                                'status':status})


            return self.do_send_metadata(permid, torrent, selversion)
        else:    # deleted before sending it
            self.torrent_db.deleteTorrent(infohash, delete_file=True, updateFlag=True)
            if DEBUG:
                print >> sys.stderr,"metadata: GET_METADATA: no torrent data to send"
            return 0
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:53,代码来源:MetadataHandler.py

示例9: valid_metadata

 def valid_metadata(self, infohash, metadata):
     try:
         metainfo = bdecode(metadata)
         tdef = TorrentDef.load_from_dict(metainfo)
         got_infohash = tdef.get_infohash()
         if infohash != got_infohash:
             print >> sys.stderr, "metadata: infohash doesn't match the torrent " + \
             "hash. Required: " + `infohash` + ", but got: " + `got_infohash`
             return False
         return True
     except:
         print_exc()
         #print >> sys.stderr, "problem metadata:", repr(metadata)
         return False
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:14,代码来源:MetadataHandler.py

示例10: main

def main():
    global __TORRENT__, __TORRENT_NEW__, __DOWNLOAD__, active_procs
    
    if len(sys.argv[1:]) != 1:
        print >>sys.stderr, 'Usage: %s <full download>' % sys.argv[0]
        sys.exit(1)
        
    __DOWNLOAD__ = sys.argv[1]
    __TORRENT__ = FileUtils.get_relative_filename(__DOWNLOAD__) + constants.TORRENT_DOWNLOAD_EXT
    __TORRENT_NEW__ = __TORRENT__ + '-new'
    
    check_dependencies()
    prepare_scenario()
    
    start_ts = time.time()
    last_vodclient_spawned = time.time()-30.0
    print >>sys.stderr, 'Spawning tracker process...'
    spawn_tracker()
    time.sleep(10)
    print >>sys.stderr, 'Fetching torrent from tracker...'
    shutil.copyfile(os.path.join('basic_scenario_tracker', __TORRENT__), __TORRENT__)
    print >>sys.stderr, 'Adding playtime information to %s' % __TORRENT__
    add_playtime_to_torrent(__TORRENT__)
    tdef = TorrentDef.load(__TORRENT_NEW__)
    bitrate = tdef.get_bitrate()
    print >>sys.stderr, 'Bitrate is: %i' % bitrate
    print >>sys.stderr, 'Spawning seeder process...'
    spawn_headless(bitrate*4)
    FINISH_TIME = 90 # experiment duration in seconds
    count = 0
    while (time.time() - start_ts <= FINISH_TIME):
        if count == 10:
            count = 0
            print >>sys.stderr, 'Scenario progress '+str(time.time() - start_ts)
        count+=1
        # remove finished vodclient processes
        active_procs = [p for p in active_procs if p.poll() == None]
        # check if we have to spawn a new vodclient
        ts = time.time()
        if ts - last_vodclient_spawned >= 30.0 and len(active_procs) < 2:
            print >>sys.stderr, '%s: Spawning new vod client... experiment progress is %f' % (str(ts), ts/start_ts*100)
            spawn_vodclient(bitrate/4, bitrate)
            last_vodclient_spawned = ts
        time.sleep(1.0)
    print >>sys.stderr, 'Emulation finished, finish and exit...'
    cleanup()
    os._exit(0)
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:47,代码来源:basic_scenario.py

示例11: setUpPostSession

    def setUpPostSession(self):
        """ override TestAsServer """
        TestAsServer.setUpPostSession(self)

        # Let Tribler start downloading an non-functioning torrent, so
        # we can talk to a normal download engine.
        
        self.torrentfn = os.path.join('extend_hs_dir','dummydata.merkle.torrent')
        tdef = TorrentDef.load(self.torrentfn)

        dscfg = self.setUpDownloadConfig()
        
        self.session.start_download(tdef,dscfg)

        # This is the infohash of the torrent in test/extend_hs_dir
        self.infohash = '\xccg\x07\xe2\x9e!]\x16\xae{\xb8\x10?\xf9\xa5\xf9\x07\xfdBk'
        self.mylistenport = 4810
开发者ID:Swizec,项目名称:IJS-stuff,代码行数:17,代码来源:test_extend_hs.py

示例12: setUp

 def setUp(self):
     """ override TestAsServer """
     TestAsServer.setUp(self)
     print >>sys.stderr,time.asctime(),'-', "test: Giving MyLaunchMany time to startup"
     time.sleep(5)
     print >>sys.stderr,time.asctime(),'-', "test: MyLaunchMany should have started up"
 
     # the metadata that we want to transfer
     self.tdef = TorrentDef()
     self.tdef.add_content(os.path.join(os.getcwd(), "API", "file.wmv"))
     self.tdef.set_tracker(self.session.get_internal_tracker_url())
     # we use a small piece length to obtain multiple pieces
     self.tdef.set_piece_length(1) 
     self.tdef.finalize()
     # self.tdef.save(os.path.join(self.session.get_state_dir(), "gen.torrent"))
     
     MagnetHelpers.__init__(self, self.tdef)
开发者ID:Anaconda84,项目名称:Anaconda,代码行数:17,代码来源:test_magnetlink.py

示例13: pretest_q

 def pretest_q(self,queryprefix,keyword):
     
     query = queryprefix+' '+keyword
     
     self.content_name = keyword.upper()+' S22E44'
     self.tdef = TorrentDef()
     self.tdef.set_tracker('http://localhost:0/announce')
     self.tdef.set_piece_length(2 ** 15)
     self.tdef.create_live(self.content_name,2 ** 16)
     self.tdef.finalize()
     
     # 1. First connect to Tribler
     self.openconn = OLConnection(self.my_keypair,'localhost',self.hisport)
     sleep(3)
     
     # 2. Make Tribler send query
     self.query = query
     self.session.query_connected_peers(query,self.query_usercallback,max_peers_to_query=10)
开发者ID:Swizec,项目名称:IJS-stuff,代码行数:18,代码来源:test_rquery_reply_active.py

示例14: get_torrents

def get_torrents(folder): 
    ''' Returns the dictionary {infohash : (torrent_definition, file_name)}
    for all torrent files in the given directory.
    '''
    fileObjects = os.listdir(folder)
    torrent_files = []
    for file in fileObjects:
        if str(file).endswith(constants.TORRENT_DOWNLOAD_EXT) or str(file).endswith(constants.TORRENT_VOD_EXT):
            torrent_files.append(os.path.join(folder, str(file)))
    files = sorted(torrent_files)
    
    torrents = dict()
    
    for file in files:
        
        tdef = TorrentDef.load(file)
        id = get_id(tdef)
        torrents[id] = (tdef, file)
    return torrents
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:19,代码来源:common_utils.py

示例15: search_torrents

 def search_torrents(self,kws,maxhits=None,sendtorrents=False):
     
     if DEBUG:
         print >>sys.stderr,"rquery: search for torrents matching",`kws`
     
     allhits = self.torrent_db.searchNames(kws,local=False)
     
     print >>sys.stderr,"rquery: got matches",`allhits`
     
     if maxhits is None:
         hits = allhits
     else:
         hits = allhits[:maxhits]
         
     colltorrdir = self.session.get_torrent_collecting_dir()
     if sendtorrents:
         
         print >>sys.stderr,"rqmh: search_torrents: adding torrents"
         for hit in hits:
             filename = os.path.join(colltorrdir,hit['torrent_file_name'])
             try:
                 tdef = TorrentDef.load(filename)
                 if tdef.get_url_compat():
                     metatype = URL_MIME_TYPE
                     metadata = tdef.get_url()
                 else:
                     metatype = TSTREAM_MIME_TYPE
                     metadata = bencode(tdef.get_metainfo())
             except:
                 print_exc()
                 metadata = None
             hit['metatype'] = metatype
             hit['metadata'] = metadata
             
         # Filter out hits for which we could not read torrent file (rare)
         newhits = []
         for hit in hits:
             if hit['metadata'] is not None:
                 newhits.append(hit)
         hits = newhits
         
     return hits
开发者ID:gvsurenderreddy,项目名称:smoothit-client,代码行数:42,代码来源:RemoteQueryMsgHandler.py


注:本文中的BaseLib.Core.TorrentDef.TorrentDef类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。