mirror of
https://github.com/YGGverse/parser-php.git
synced 2026-04-02 02:05:29 +00:00
Compare commits
No commits in common. "main" and "0.1.0" have entirely different histories.
4 changed files with 2 additions and 160 deletions
119
src/Magnet.php
119
src/Magnet.php
|
|
@ -1,119 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Yggverse\Parser;
|
|
||||||
|
|
||||||
class Magnet {
|
|
||||||
|
|
||||||
public static function is(string $link) : bool
|
|
||||||
{
|
|
||||||
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:1220'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function filterInfoHash(string $value) : string
|
|
||||||
{
|
|
||||||
return trim(
|
|
||||||
str_replace(
|
|
||||||
[
|
|
||||||
'urn:',
|
|
||||||
'btih:',
|
|
||||||
'btmh:1220',
|
|
||||||
],
|
|
||||||
false,
|
|
||||||
$value
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function parse(string $link) : mixed
|
|
||||||
{
|
|
||||||
$result =
|
|
||||||
[
|
|
||||||
'dn' => null,
|
|
||||||
'xl' => 0,
|
|
||||||
'xt' => [],
|
|
||||||
'tr' => [],
|
|
||||||
'ws' => [],
|
|
||||||
'as' => [],
|
|
||||||
'xs' => [],
|
|
||||||
'kt' => [],
|
|
||||||
'mt' => [],
|
|
||||||
'so' => [],
|
|
||||||
'x.pe' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!self::is($link))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$link = urldecode($link);
|
|
||||||
|
|
||||||
$link = str_replace(
|
|
||||||
[
|
|
||||||
'magnet:',
|
|
||||||
'?',
|
|
||||||
'xt=',
|
|
||||||
'tr=',
|
|
||||||
'ws=',
|
|
||||||
'as=',
|
|
||||||
'xs=',
|
|
||||||
'mt=',
|
|
||||||
'x.pe=',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
'xt[]=',
|
|
||||||
'tr[]=',
|
|
||||||
'ws[]=',
|
|
||||||
'as[]=',
|
|
||||||
'xs[]=',
|
|
||||||
'mt[]=',
|
|
||||||
'x.pe[]=',
|
|
||||||
],
|
|
||||||
$link
|
|
||||||
);
|
|
||||||
|
|
||||||
parse_str($link, $attributes);
|
|
||||||
|
|
||||||
switch (true)
|
|
||||||
{
|
|
||||||
case empty($attributes['xt']):
|
|
||||||
case empty($attributes['tr']):
|
|
||||||
// ...
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ((array) $attributes as $key => $value)
|
|
||||||
{
|
|
||||||
|
|
||||||
switch ($key)
|
|
||||||
{
|
|
||||||
case 'kt':
|
|
||||||
|
|
||||||
foreach ((array) explode(' ', $value) as $keyword)
|
|
||||||
{
|
|
||||||
$result[$key][] = trim($keyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
|
|
||||||
$result[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (object) $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Yggverse\Parser;
|
namespace YGGverse\Parser;
|
||||||
|
|
||||||
class Url {
|
class Url {
|
||||||
|
|
||||||
|
|
|
||||||
39
src/Urn.php
39
src/Urn.php
|
|
@ -1,39 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Yggverse\Parser;
|
|
||||||
|
|
||||||
class Urn {
|
|
||||||
|
|
||||||
public static function is(string $urn) : bool
|
|
||||||
{
|
|
||||||
return ('urn' == parse_url($urn, PHP_URL_SCHEME));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function parse(string $urn) : mixed
|
|
||||||
{
|
|
||||||
if (!self::is($urn))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($part = explode(':', $urn))
|
|
||||||
{
|
|
||||||
if (empty($part[0]) || empty($part[1]) || empty($part[2]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($part[0]);
|
|
||||||
|
|
||||||
$result =
|
|
||||||
[
|
|
||||||
'urn' => implode(':', $part),
|
|
||||||
'parts' => $part,
|
|
||||||
];
|
|
||||||
|
|
||||||
return (object) $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Yggverse\Parser\Tests;
|
namespace YGGverse\Parser\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue