/** * Regenerate a torrent's file list from its meta data, * update the database record and clear relevant cache keys * * @param int $TorrentID */ public static function regenerate_filelist($TorrentID) { $QueryID = G::$DB->get_query_id(); G::$DB->query("\n\t\t\tSELECT tg.ID,\n\t\t\t\ttf.File\n\t\t\tFROM torrents_files AS tf\n\t\t\t\tJOIN torrents AS t ON t.ID = tf.TorrentID\n\t\t\t\tJOIN torrents_group AS tg ON tg.ID = t.GroupID\n\t\t\tWHERE tf.TorrentID = {$TorrentID}"); if (G::$DB->has_results()) { list($GroupID, $Contents) = G::$DB->next_record(MYSQLI_NUM, false); if (Misc::is_new_torrent($Contents)) { $Tor = new BencodeTorrent($Contents); $FilePath = isset($Tor->Dec['info']['files']) ? Format::make_utf8($Tor->get_name()) : ''; } else { $Tor = new TORRENT(unserialize(base64_decode($Contents)), true); $FilePath = isset($Tor->Val['info']->Val['files']) ? Format::make_utf8($Tor->get_name()) : ''; } list($TotalSize, $FileList) = $Tor->file_list(); foreach ($FileList as $File) { $TmpFileList[] = self::filelist_format_file($File); } $FileString = implode("\n", $TmpFileList); G::$DB->query("\n\t\t\t\tUPDATE torrents\n\t\t\t\tSET Size = {$TotalSize}, FilePath = '" . db_string($FilePath) . "', FileList = '" . db_string($FileString) . "'\n\t\t\t\tWHERE ID = {$TorrentID}"); G::$Cache->delete_value("torrents_details_{$GroupID}"); } G::$DB->set_query_id($QueryID); }
// F*****g btjunkie piece of shit if(!empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'btjunkie.org')) { $DB->query("UPDATE users_main SET Cursed='1' WHERE ID='$UserID'"); $DB->query("UPDATE users_info SET AdminComment=CONCAT('".sqltime()." - Account cursed at $LoggedUser[BytesDownloaded] bytes downloaded for accessing the site from ".db_string($_SERVER['HTTP_REFERER'])." ', AdminComment) WHERE UserID='$LoggedUser[ID]'"); } $DB->query("INSERT INTO users_downloads (UserID, TorrentID, Time) VALUES ('$UserID', '$TorrentID', '".sqltime()."') ON DUPLICATE KEY UPDATE Time=VALUES(Time)"); $DB->query("SELECT File FROM torrents_files WHERE TorrentID='$TorrentID'"); list($Contents) = $DB->next_record(MYSQLI_NUM, array(0)); $Contents = unserialize(base64_decode($Contents)); $Tor = new TORRENT($Contents, true); // New TORRENT object // Set torrent announce URL $Tor->set_announce_url(ANNOUNCE_URL.'/'.$TorrentPass.'/announce'); // Remove multiple trackers from torrent unset($Tor->Val['announce-list']); // Remove web seeds (put here for old torrents not caught by previous commit unset($Tor->Val['url-list']); // Torrent name takes the format of Artist - Album - YYYY (Media - Format - Encoding) $TorrentName=''; $TorrentInfo=''; $TorrentName = $Artists; $TorrentName.=$Name;
$DB->query("SELECT DATE_FORMAT(t.Time,'%b \'%y') AS Month, t.GroupID, t.Media, t.Format, t.Encoding, IF(t.RemasterYear=0,tg.Year,t.RemasterYear), tg.Name, t.Size, f.File FROM torrents as t JOIN torrents_group AS tg ON t.GroupID=tg.ID LEFT JOIN torrents_files AS f ON t.ID=f.TorrentID ".$SQL); $Downloads = $DB->to_array(false,MYSQLI_NUM,false); $Artists = get_artists($DB->collect('GroupID')); list($UserID, $Username) = array_values(user_info($UserID)); $Zip = new ZIP($Username.'\'s '.ucfirst($_GET['type'])); foreach($Downloads as $Download) { list($Month, $GroupID, $Media, $Format, $Encoding, $Year, $Album, $Size, $Contents) = $Download; $Artist = display_artists($Artists[$GroupID],false); $Contents = unserialize(base64_decode($Contents)); $Tor = new TORRENT($Contents, true); $Tor->set_announce_url(ANNOUNCE_URL.'/'.$LoggedUser['torrent_pass'].'/announce'); unset($Tor->Val['announce-list']); $Zip->add_file($Tor->enc(), file_string($Month).'/'.file_string($Artist.$Album).' - '.file_string($Year).' ('.file_string($Media).' - '.file_string($Format).' - '.file_string($Encoding).').torrent'); } $Zip->close_stream();
/** * Convert a stored torrent into a binary file that can be loaded in a torrent client * * @param mixed $TorrentData bencoded torrent without announce URL (new format) or TORRENT object (old format) * @return bencoded string */ public static function get_file(&$TorrentData, $AnnounceURL) { if (Misc::is_new_torrent($TorrentData)) { return BencodeTorrent::add_announce_url($TorrentData, $AnnounceURL); } $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true); $Tor->set_announce_url($AnnounceURL); unset($Tor->Val['announce-list']); unset($Tor->Val['url-list']); unset($Tor->Val['libtorrent_resume']); return $Tor->enc(); }
public function download($id = -1) { $this->utility->enforce_perm('site_torrents_download'); $this->load->model('usermodel'); require APPPATH . '/libraries/torrent.php'; if (!($data = $this->torrentmodel->getData($id))) { show_404(); } $tor = new TORRENT($data['data']->bin); //$tor->set_announce_url($this->config->item('announce_url').'/'.$this->session->userdata('torrent_pass').'/announce'); if (!$this->utility->user_setting('download_as_txt')) { header('Content-Disposition: attachment; filename="' . $this->utility->torrent_name($id, false) . '.torrent"'); header('Content-Type: application/x-bittorrent'); } else { header('Content-Disposition: attachment; filename="' . $this->utility->torrent_name($id, false) . '.txt"'); header('Content-Type: text/plain'); } echo $tor->enc(); $this->utility->log($this->utility->current_user('username') . ' (' . $this->utility->current_user('_id') . ') downloaded torrent ' . $id); exit; }