Browse Source

Add name metadata to magnet links

spaghetti 8 years ago
parent
commit
368b3ca589
2 changed files with 24 additions and 3 deletions
  1. 16
    2
      sections/torrents/browse.php
  2. 8
    1
      sections/torrents/details.php

+ 16
- 2
sections/torrents/browse.php View File

@@ -581,7 +581,14 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr
581 581
 
582 582
       $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
583 583
       $TorrentDL = "torrents.php?action=download&id=".$TorrentID."&authkey=".$LoggedUser['AuthKey']."&torrent_pass=".$LoggedUser['torrent_pass'];
584
-      $TorrentMG = "magnet:?xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
584
+      if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
585
+        $DB->query("SELECT File FROM torrents_files WHERE TorrentID=".$TorrentID);
586
+        list($TorrentFile) = $DB->next_record(MYSQLI_NUM, false);
587
+        $Tor = new BencodeTorrent($TorrentFile);
588
+        $TorrentFileName = $Tor->Dec['info']['name'];
589
+        $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
590
+      }
591
+      $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
585 592
 
586 593
 ?>
587 594
   <tr class="group_torrent groupid_<?=$GroupID?> <?=$SnatchedTorrentClass . $SnatchedGroupClass . (!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1 ? ' hidden' : '')?>">
@@ -647,7 +654,14 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr
647 654
     }
648 655
     $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
649 656
     $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
650
-    $TorrentMG = "magnet:?xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
657
+    if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
658
+      $DB->query("SELECT File FROM torrents_files WHERE TorrentID=".$TorrentID);
659
+      list($TorrentFile) = $DB->next_record(MYSQLI_NUM, false);
660
+      $Tor = new BencodeTorrent($TorrentFile);
661
+      $TorrentFileName = $Tor->Dec['info']['name'];
662
+      $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
663
+    }
664
+    $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
651 665
 ?>
652 666
   <tr class="torrent<?=$SnatchedTorrentClass . $SnatchedGroupClass?>">
653 667
 <?    if ($GroupResults) { ?>

+ 8
- 1
sections/torrents/details.php View File

@@ -515,7 +515,14 @@ foreach ($TorrentList as $Torrent) {
515 515
   if (!empty($BadFiles)) { $ExtraInfo.=$AddExtra. Format::torrent_label('Bad File Names'); $AddExtra=' / '; }
516 516
 
517 517
   $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
518
-  $TorrentMG = "magnet:?xt=urn:btih:".$InfoHash."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Size;
518
+  if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
519
+    $DB->query("SELECT File FROM torrents_files WHERE TorrentID=".$TorrentID);
520
+    list($TorrentFile) = $DB->next_record(MYSQLI_NUM, false);
521
+    $Tor = new BencodeTorrent($TorrentFile);
522
+    $TorrentFileName = $Tor->Dec['info']['name'];
523
+    $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
524
+  }
525
+  $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$InfoHash."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Size;
519 526
 ?>
520 527
 
521 528
       <tr class="torrent_row groupid_<?=$GroupID?> group_torrent<?=($IsSnatched ? ' snatched_torrent' : '')?>" style="font-weight: normal;" id="torrent<?=$TorrentID?>">

Loading…
Cancel
Save