Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate_extra_torrents.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?
  2. $ExtraTorrentsInsert = array();
  3. foreach ($ExtraTorrents as $ExtraTorrent) {
  4. $Name = $ExtraTorrent['Name'];
  5. $ExtraTorrentsInsert[$Name] = $ExtraTorrent;
  6. $ThisInsert =& $ExtraTorrentsInsert[$Name];
  7. $ExtraTor = new BencodeTorrent($Name, true);
  8. if (isset($ExtraTor->Dec['encrypted_files'])) {
  9. $Err = 'At least one of the torrents contain an encrypted file list which is not supported here';
  10. break;
  11. }
  12. if (!$ExtraTor->is_private()) {
  13. $ExtraTor->make_private(); // The torrent is now private.
  14. $PublicTorrent = true;
  15. }
  16. // File list and size
  17. list($ExtraTotalSize, $ExtraFileList) = $ExtraTor->file_list();
  18. $ExtraDirName = isset($ExtraTor->Dec['info']['files']) ? Format::make_utf8($ExtraTor->get_name()) : '';
  19. $ExtraTmpFileList = array();
  20. foreach ($ExtraFileList as $ExtraFile) {
  21. list($ExtraSize, $ExtraName) = $ExtraFile;
  22. check_file($Type, $ExtraName);
  23. // Make sure the file name is not too long
  24. if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) {
  25. $Err = "The torrent contained one or more files with too long of a name: <br />$ExtraDirName/$ExtraName";
  26. break;
  27. }
  28. // Add file and size to array
  29. $ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile);
  30. }
  31. // To be stored in the database
  32. $ThisInsert['FilePath'] = db_string($ExtraDirName);
  33. $ThisInsert['FileString'] = db_string(implode("\n", $ExtraTmpFileList));
  34. $ThisInsert['InfoHash'] = pack('H*', $ExtraTor->info_hash());
  35. $ThisInsert['NumFiles'] = count($ExtraFileList);
  36. $ThisInsert['TorEnc'] = db_string($ExtraTor->encode());
  37. $ThisInsert['TotalSize'] = $ExtraTotalSize;
  38. $Debug->set_flag('upload: torrent decoded');
  39. $DB->query("
  40. SELECT ID
  41. FROM torrents
  42. WHERE info_hash = '" . db_string($ThisInsert['InfoHash']) . "'");
  43. if ($DB->has_results()) {
  44. list($ExtraID) = $DB->next_record();
  45. if (file_exists(TORRENT_STORE.$ExtraID.'.torrent')) {
  46. $Err = "<a href=\"torrents.php?torrentid=$ExtraID\">The exact same torrent file already exists on the site!</a>";
  47. } else {
  48. //One of the lost torrents.
  49. file_put_contents(TORRENT_STORE.$ExtraID.'.torrent', $ThisInsert['TorEnc']);
  50. $Err = "<a href=\"torrents.php?torrentid=$ExtraID\">Thank you for fixing this torrent.</a>";
  51. }
  52. }
  53. }
  54. unset($ThisInsert);
  55. ?>