From 6c73a6802494ab5ee7dcd2dcbdc8bb7f71bb1b4c Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 4 Sep 2023 00:16:37 +0300 Subject: [PATCH 1/6] add info hash v2 support --- src/Magnet.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Magnet.php b/src/Magnet.php index 949c887..2f4198c 100644 --- a/src/Magnet.php +++ b/src/Magnet.php @@ -9,13 +9,36 @@ class Magnet { return ('magnet' == parse_url($link, PHP_URL_SCHEME)); } + public static function isXTv1(string $xt) : bool + { + return ('urn' == parse_url($xt, PHP_URL_SCHEME) && false !== strpos($xt, ':btih:')); + } + + public static function isXTv2(string $xt) : bool + { + return ('urn' == parse_url($xt, PHP_URL_SCHEME) && false !== strpos($xt, ':btmh:')); + } + + public static function filterInfoHash(string $value) : string + { + return str_replace( + [ + 'urn:', + 'btih:', + 'btmh:', + ], + false, + $value + ); + } + public static function parse(string $link) : mixed { $result = [ - 'xt' => null, 'dn' => null, 'xl' => 0, + 'xt' => [], 'tr' => [], 'ws' => [], 'as' => [], @@ -37,6 +60,7 @@ class Magnet { [ 'magnet:', '?', + 'xt=', 'tr=', 'ws=', 'as=', @@ -47,6 +71,7 @@ class Magnet { [ false, false, + 'xt[]=', 'tr[]=', 'ws[]=', 'as[]=', From c32a3b5f7d76c9d6c74c9fd9b7d472ac3d3454c3 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 4 Sep 2023 01:38:55 +0300 Subject: [PATCH 2/6] add trim to filterInfoHash method --- src/Magnet.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Magnet.php b/src/Magnet.php index 2f4198c..3dfd588 100644 --- a/src/Magnet.php +++ b/src/Magnet.php @@ -21,14 +21,16 @@ class Magnet { public static function filterInfoHash(string $value) : string { - return str_replace( - [ - 'urn:', - 'btih:', - 'btmh:', - ], - false, - $value + return trim( + str_replace( + [ + 'urn:', + 'btih:', + 'btmh:', + ], + false, + $value + ) ); } From 81f019be7a275d631fb87d89274a89ac36ca2052 Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 5 Sep 2023 19:15:29 +0300 Subject: [PATCH 3/6] fix 0x1220 multihash prefix for v2 btmh part --- src/Magnet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magnet.php b/src/Magnet.php index 3dfd588..0abbfe9 100644 --- a/src/Magnet.php +++ b/src/Magnet.php @@ -16,7 +16,7 @@ class Magnet { public static function isXTv2(string $xt) : bool { - return ('urn' == parse_url($xt, PHP_URL_SCHEME) && false !== strpos($xt, ':btmh:')); + return ('urn' == parse_url($xt, PHP_URL_SCHEME) && false !== strpos($xt, ':btmh:1220')); } public static function filterInfoHash(string $value) : string @@ -26,7 +26,7 @@ class Magnet { [ 'urn:', 'btih:', - 'btmh:', + 'btmh:1220', ], false, $value From 47c7d13697a5a51db3178ebe9f4e3c09b7c1c584 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 20 Sep 2023 14:28:52 +0300 Subject: [PATCH 4/6] add neitanod/forceutf8 dependency --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 37db3f5..4f2a68d 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "description": "Parser toolkit written on PHP", "type": "library", "require": { - "php": ">=8.1" + "php": ">=8.1", + "neitanod/forceutf8": "~2.0" }, "require-dev": { "phpunit/phpunit": ">=10" From 26111fce289df15bd6babb7831898437c2894133 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 20 Sep 2023 15:18:16 +0300 Subject: [PATCH 5/6] remove neitanod/forceutf8 dependency --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4f2a68d..37db3f5 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,7 @@ "description": "Parser toolkit written on PHP", "type": "library", "require": { - "php": ">=8.1", - "neitanod/forceutf8": "~2.0" + "php": ">=8.1" }, "require-dev": { "phpunit/phpunit": ">=10" From 74de022cd5175a5d5ec176e9668cf8470679a98a Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 9 Oct 2023 04:52:01 +0300 Subject: [PATCH 6/6] fix namespace --- src/Magnet.php | 2 +- src/Url.php | 2 +- src/Urn.php | 2 +- tests/UrlTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Magnet.php b/src/Magnet.php index 0abbfe9..f90a59a 100644 --- a/src/Magnet.php +++ b/src/Magnet.php @@ -1,6 +1,6 @@