コード例 #1
0
    def test_parse_dict_sha1(self) -> None:
        uri = (f"magnet:?xt=urn:btih:{self.info_hash_sha1}&"
               "dn=test.txt&"
               "tr=http://example.com/tr&"
               "ws=http://example.com/ws&"
               "so=0-2,4&"
               "x.pe=0.1.2.3:4567&"
               "dht=1.2.3.4:5678")
        with self.assertWarns(DeprecationWarning):
            params = lt.parse_magnet_uri_dict(uri)
        self.assertEqual(
            params,
            {
                "dht_nodes": [("1.2.3.4", 5678)],
                "flags": lt.add_torrent_params_flags_t.default_flags,
                "info_hash": bytes.fromhex(self.info_hash_sha1),
                "info_hashes": bytes.fromhex(self.info_hash_sha1),
                "name": "test.txt",
                "save_path": "",
                "storage_mode": lt.storage_mode_t.storage_mode_sparse,
                "trackers": ["http://example.com/tr"],
                "url": "",
            },
        )

        # The dict is intended to be usable as argument to session.add_torrent()
        session = lt.session(lib.get_isolated_settings())
        with tempfile.TemporaryDirectory() as path:
            params["save_path"] = path
            with self.assertWarns(DeprecationWarning):
                handle = session.add_torrent(params)
            self.assertEqual(str(handle.info_hashes().v1), self.info_hash_sha1)
            self.assertEqual(handle.status().name, "test.txt")
            self.assertEqual([t["url"] for t in handle.trackers()],
                             ["http://example.com/tr"])
コード例 #2
0
ファイル: test.py プロジェクト: SteveShaw/libtorrent
 def test_parse_magnet_uri_dict(self):
     ses = lt.session({})
     magnet = 'magnet:?xt=urn:btih:C6EIF4CCYDBTIJVG3APAGM7M4NDONCTI'
     p = lt.parse_magnet_uri_dict(magnet)
     self.assertEqual(binascii.hexlify(p['info_hash']), b'178882f042c0c33426a6d81e0333ece346e68a68')
     p['save_path'] = '.'
     h = ses.add_torrent(p)
     self.assertEqual(str(h.info_hash()), '178882f042c0c33426a6d81e0333ece346e68a68')
コード例 #3
0
ファイル: test.py プロジェクト: aldenml/libtorrent
 def test_parse_magnet_uri_dict(self):
     ses = lt.session({})
     magnet = 'magnet:?xt=urn:btih:C6EIF4CCYDBTIJVG3APAGM7M4NDONCTI'
     p = lt.parse_magnet_uri_dict(magnet)
     self.assertEqual(binascii.hexlify(p['info_hash']), b'178882f042c0c33426a6d81e0333ece346e68a68')
     p['save_path'] = '.'
     h = ses.add_torrent(p)
     self.assertEqual(str(h.info_hash()), '178882f042c0c33426a6d81e0333ece346e68a68')
コード例 #4
0
    def test_parse_dict_sha256_broken(self) -> None:
        uri = (
            f"magnet:?xt=urn:btmh:1220{self.info_hash_sha256}&"
            "dn=test.txt&"
            "tr=http://example.com/tr&"
            "ws=http://example.com/ws&"
            "so=0-2,4&"
            "x.pe=0.1.2.3:4567&"
            "dht=1.2.3.4:5678"
        )
        params = lt.parse_magnet_uri_dict(uri)
        self.assertEqual(
            params,
            {
                "dht_nodes": [("1.2.3.4", 5678)],
                "file_priorities": [4, 4, 4, 0, 4],
                "flags": lt.add_torrent_params_flags_t.default_flags,
                "info_hash": bytes.fromhex(self.info_hash_sha256)[:20],
                "info_hashes": bytes.fromhex(self.info_hash_sha256),
                "name": "test.txt",
                "peers": [("0.1.2.3", 4567)],
                "save_path": "",
                "storage_mode": lt.storage_mode_t.storage_mode_sparse,
                "trackers": ["http://example.com/tr"],
                "url": "",
                "url_seeds": "http://example.com/ws",
            },
        )

        # The dict is intended to be usable as argument to session.add_torrent()
        session = lt.session(lib.get_isolated_settings())
        with tempfile.TemporaryDirectory() as path:
            params["save_path"] = path
            handle = session.add_torrent(params)
            self.assertEqual(
                str(handle.info_hashes().v2),  # type: ignore
                self.info_hash_sha256,
            )
            self.assertEqual(handle.name(), "test.txt")
            self.assertEqual(
                [t["url"] for t in handle.trackers()], ["http://example.com/tr"]
            )
            self.assertEqual(handle.url_seeds(), ["http://example.com/ws"])
            self.assertEqual(handle.file_priorities(), [4, 4, 4, 0, 4])
コード例 #5
0
ファイル: client.py プロジェクト: cyb3rpunk452/aos-libtorrent
def add_torrent(ses, filename, options):
    atp = {}
    if filename.startswith('magnet:'):
        atp = lt.parse_magnet_uri_dict(filename)
    else:
        atp['ti'] = lt.torrent_info(filename)
        try:
            atp["resume_data"] = open(
                os.path.join(options.save_path,
                             info.name() + '.fastresume'), 'rb').read()
        except:
            pass

    atp["save_path"] = options.save_path
    atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse
    atp["paused"] = False
    atp["auto_managed"] = True
    atp["duplicate_is_error"] = True
    ses.async_add_torrent(atp)
コード例 #6
0
 def test_parse_dict_deprecated(self) -> None:
     uri = f"magnet:?xt=urn:btih:{self.info_hash_sha1}"
     with self.assertWarns(DeprecationWarning):
         lt.parse_magnet_uri_dict(uri)
コード例 #7
0
 def test_parse_dict_error(self) -> None:
     with self.assertWarns(DeprecationWarning):
         with self.assertRaises(RuntimeError):
             lt.parse_magnet_uri_dict("magnet:?")
コード例 #8
0
 def test_parse_dict_error(self) -> None:
     with self.assertRaises(RuntimeError):
         lt.parse_magnet_uri_dict("magnet:?")