Skip to content

Commit 6e5cb4c

Browse files
committed
Add Magnet Link by Hash Only #1090
Added the possiblity of add a magnet only by the hash.
1 parent 6e19127 commit 6e5cb4c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

main.pas

+20-1
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,21 @@ function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LR
945945

946946
{$endif windows}
947947

948+
function IsHash(Hash: String): boolean;
949+
var i: integer;
950+
begin
951+
if Hash = '' then exit;
952+
if Length(Hash) = 32 then // possible base32 encoded hash
953+
try
954+
Hash:=StrToHex(Base32Decode(UpperCase(Hash)));
955+
except
956+
exit;
957+
end;
958+
if Length(Hash) <> 40 then exit;
959+
Result := true;
960+
for i := 1 to 40 do if not (Hash[i] in ['a' .. 'f', 'A'..'F', '0'..'9']) then Result := false;
961+
end;
962+
948963
procedure TMainForm.ReadLocalFolderWatch;
949964
var
950965
sr: TSearchRec;
@@ -2213,7 +2228,10 @@ procedure TMainForm.acAddLinkExecute(Sender: TObject);
22132228
try
22142229
AppNormal;
22152230
if ShowModal = mrOk then
2216-
DoAddTorrent(edLink.Text);
2231+
begin
2232+
if isHash(edLink.Text) then edLink.Text := 'magnet:?xt=urn:btih:'+ edLink.Text;
2233+
DoAddTorrent(edLink.Text);
2234+
end;
22172235
finally
22182236
Free;
22192237
end;
@@ -7608,6 +7626,7 @@ procedure TMainForm.CheckClipboardLink;
76087626
if s = FLastClipboardLink then
76097627
exit;
76107628
FLastClipboardLink:=s;
7629+
if isHash(s) then s := 'magnet:?xt=urn:btih:' + s;
76117630
if not IsProtocolSupported(s) then
76127631
exit;
76137632
if (Pos('magnet:', LazUTF8.UTF8LowerCase(s)) <> 1) and (LazUTF8.UTF8LowerCase(Copy(s, Length(s) - Length(strTorrentExt) + 1, MaxInt)) <> strTorrentExt) then

0 commit comments

Comments
 (0)