public function __construct(User $user) { $this->user = $user; $torrentDB = new TorrentDB(); $fileDB = new FileDB(); foreach ($this->user->torrentHashes as $hash) { $torrent = $torrentDB->get($hash); $files = $fileDB->getTorrentFiles($torrent); foreach ($files as $file) { // If file is a "music" file if ($file->type == File::MUSIC_TYPE) { $this->process($file); } } } }
public function __construct($username) { $this->userDB = new UserDB(); $this->torrentDB = new TorrentDB(); $user = $this->userDB->get($username); foreach ($user as $property => $value) { switch ($property) { case UserDB::TORRENT_HASHES: $this->torrentHashes = $value; $torrentDB = new TorrentDB(); $torrents = $torrentDB->get($this->torrentHashes); $this->torrents = array(); foreach ($torrents as $torrent) { $this->torrents[$torrent->hashString] = $torrent; } break; default: $this->{$property} = $value; } } }
#!/usr/bin/php <?php ini_set("log_errors", 1); ini_set("extension", "mongo.so"); ini_set("error_log", "/tmp/php-error.log"); require_once '/var/www/torrentcloud/models/FileDB.php'; require_once '/var/www/torrentcloud/models/TorrentDB.php'; require_once '/var/www/torrentcloud/models/Torrent.php'; require_once '/var/www/torrentcloud/models/Helper.php'; require_once '/var/www/torrentcloud/models/File.php'; require_once '/var/www/torrentcloud/models/TorrentFile.php'; require_once '/var/www/torrentcloud/models/getid3/getid3.php'; $fileDB = new FileDB(); $torrentDB = new TorrentDB(); $torrentHash = getenv('TR_TORRENT_HASH'); $torrentData = $torrentDB->get($torrentHash); $torrent = new Torrent($torrentData); foreach ($torrent->files as $file) { $name = basename($file['name']); $extension = pathinfo($name, PATHINFO_EXTENSION); $path = $torrent->downloadDir . '/' . $file['name']; $finfo = finfo_open(FILEINFO_MIME_TYPE); $MIME_type = finfo_file($finfo, $path); $fileData = array(FileDB::TORRENT_HASH => $torrent->hashString, FileDB::NAME => $name, FileDB::EXTENSION => $extension, FileDB::SIZE => $file['length'], FileDB::PATH => $path, FileDB::MIME_TYPE => $MIME_type); $torrentFile = new TorrentFile($fileData); $torrentFile->analyze(); $fileDB->add($torrentFile); }