public function getSeedInfos()
 {
     $arr = json_decode($this->query_json, true);
     if (empty($arr)) {
         return false;
     }
     $ids = array_keys($arr);
     $seedRes = Seed::getDb()->cache(function ($db) use(&$ids) {
         return Seed::findAll($ids);
     }, 60);
     $ret = [];
     foreach ($seedRes as $seed) {
         $id = $arr[$seed['seed_id']];
         $ret[$id] = $seed->attributes;
         // 格式:{{100,100,50},{100,50,50}}
         //第一个是up,第二个是down
         $coef = $seed->coefArray;
         $ret[$id]['up_coef'] = $coef[0][0];
         $ret[$id]['down_coef'] = $coef[0][1];
         $expire = intval($coef[0][2]);
         Yii::info($expire);
         $ret[$id]['coef_expire_time'] = $expire == 0 ? 0 : $expire - time();
     }
     return $ret;
 }
Example #2
0
 public function searchSeeds()
 {
     $keywords = explode(' ', $this->search_text);
     array_walk($keywords, function (&$value) {
         $value = strtolower($value);
     });
     $qr = Seed::find()->select('seed_id')->where(['like', 'lower(full_name)', $keywords])->andWhere("coefs_stack[1][1] BETWEEN {$this->upcoe_min} AND {$this->upcoe_max}")->andWhere("coefs_stack[1][2] BETWEEN {$this->downcoe_min} AND {$this->downcoe_max}")->andWhere("pub_time >= 'today'::date - '{$this->date_after} days'::interval");
     $cond = [];
     foreach ($this->type_subtype_assoc as $type => $sub_type) {
         $tmpc = " (\"type_id\"='{$type}' ";
         if (!empty($sub_type)) {
             $tmpc .= " AND \"sub_type_id\"='{$sub_type}') ";
         } else {
             $tmpc .= ")";
         }
         $cond[] = $tmpc;
     }
     if (!empty($cond)) {
         $qr->andWhere(implode('OR', $cond));
     }
     foreach ($this->order_by as $idx => $by) {
         $type = strtolower($this->order_type[$idx]) == 'asc' ? SORT_ASC : SORT_DESC;
         $qr->addOrderBy([$by => $type]);
     }
     if ($this->nodead) {
         $qr->andWhere(['between', 'seeder_count', 1, 100000]);
     }
     Yii::info($qr->where);
     return $qr->limit($this->limit)->offset($this->offset)->all();
 }
 public function actionScrape()
 {
     $infohash = Yii::$app->request->get("info_hash");
     if (!is_array($infohash)) {
         $infohash = [$infohash];
     }
     $res = [];
     foreach ($infohash as $ih) {
         $tmp = Seed::findOne(['info_hash' => strtoupper(bin2hex($ih))]);
         if (!empty($tmp)) {
             $res[] = $tmp;
         }
     }
     return $this->renderPartial("queryScrape", ['seeds' => $res]);
 }
Example #4
0
 public function actionMaintainCoef()
 {
     $now = time();
     $seeds = Seed::find()->where("coefs_stack[1][3] < {$now}")->andWhere('coefs_stack[1][3] != 0')->all();
     foreach ($seeds as $seed) {
         $arr = $seed->getCoefArray();
         var_dump($arr);
         array_shift($arr);
         //无后备选项
         if (empty($arr)) {
             $arr[] = [100, 100, 0];
         }
         $seed->setCoefArray($arr);
         echo '新系数\\n';
         var_dump($seed->getCoefArray());
         $seed->save();
     }
     var_dump(count($seeds));
     return;
 }
Example #5
0
 public function rules()
 {
     return [[['info_hash', 'peer_id', 'port', 'left', 'downloaded', 'uploaded'], 'required'], [['passkey', 'info_hash', 'event', 'ip', 'port', 'left', 'no_peer_id', 'uploaded', 'downloaded', 'ipv6', 'numwant', 'compact'], 'trim'], [['passkey', 'info_hash', 'ip', 'ipv6'], 'default'], ['event', 'default', 'value' => 'regular'], [['port', 'left', 'uploaded', 'downloaded', 'compact', 'numwant'], 'default', 'value' => 0], [['compact', 'no_peer_id'], 'filter', 'filter' => function ($val) {
         return (bool) $val;
     }], [['port', 'left', 'uploaded', 'downloaded', 'numwant'], 'integer'], ['info_hash', 'string', 'length' => [40, 40]], ['peer_id', 'string', 'length' => [4, 30]], [['info_hash', 'passkey'], 'filter', 'filter' => 'strtoupper'], ['event', 'filter', 'filter' => 'strtolower'], ['ipv6', function ($attr, $params) {
         if (!empty($this->{$attr})) {
             self::rfc2732Convert($this->{$attr}, $ipv6, $port);
             if ($port == null) {
                 $port = $this->port;
             }
             if (filter_var($ipv6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && $port != null) {
                 $this->ipv6 = $ipv6;
                 $this->ipv6port = $port;
             }
         }
     }], ['ip', function ($attr, $param) {
         $this->ipv4 = $this->ip;
         $this->ipv4port = $this->port;
     }], ['info_hash', function ($attr, $param) {
         $this->_seed = Seed::findOne(['info_hash' => $this->{$attr}]);
         if (empty($this->_seed)) {
             $this->addError('info_hash', 'no such seed');
         } elseif (!$this->_seed->is_valid) {
             $this->addError('info_hash', 'seed is invalid');
         }
     }]];
 }
Example #6
0
 public function actionPeerInfo($seed_id)
 {
     /** @var Seed $seed */
     $seed = Seed::findOne($seed_id);
     if (empty($seed)) {
         return ['result' => 'failed', 'extra' => 'no such seed'];
     }
     $peers = $seed->peers;
     $leechers = [];
     $seeders = [];
     $all = [];
     foreach ($peers as $peer) {
         $peer->update_time = strtotime($peer->update_time);
         $peer->create_time = strtotime($peer->create_time);
         $peer->client_tag = substr(base64_decode($peer->client_tag), 0, 3);
         if ($peer->status == 'Seeder') {
             $seeders[] = $peer->attributes;
         } else {
             $leechers[] = $peer->attributes;
         }
         $all[] = $peer->attributes;
     }
     return ['result' => 'succeed', 'extra' => ['all' => $all, 'leechers' => $leechers, 'seeders' => $seeders]];
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSeed()
 {
     return $this->hasOne(Seed::className(), ['seed_id' => 'seed_id']);
 }
Example #8
0
 private function replace(&$retval)
 {
     $retval = 'failed';
     if (!empty($this->torrentFile)) {
         return $this->handleTorrent($this->torrentFile->tempName, $retval);
     } else {
         /** @var Seed $seed */
         $seed = Seed::findOne($this->seed_id);
         if (empty($seed)) {
             $this->addError('seed_id', 'seed being edited not exists');
             return $seed;
         } else {
             $seed->detail_info = $this->proc_obj->getDetail();
             $seed->full_name = $this->proc_obj->generateSubject();
             $seed->is_valid = true;
             $seed->type_id = $this->type_id;
             $seed->sub_type_id = $this->sub_type_id;
             $seed->save();
             $retval = 'succeed';
             return $seed;
         }
     }
 }
Example #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPublishedSeed()
 {
     return $this->hasMany(Seed::className(), ['publisher_user_id' => 'user_id']);
 }
    public function actionOperation()
    {
        SeedOperationRecord::deleteAll();
        $offset = 0;
        $limit = 1000;
        QUERY:
        $sql = <<<SQL
        SELECT * FROM `ngpt_ngpt_seed_op_records` LIMIT {$limit} OFFSET {$offset};
SQL;
        $res = $this->fdb->createCommand($sql)->queryAll();
        foreach ($res as $oop) {
            var_dump($oop);
            $op = new SeedOperationRecord();
            /** @var User $admin */
            $admin = User::findOne(['discuz_user_id' => $oop['uid']]);
            /** @var Seed $seed */
            $seed = Seed::findOne(['info_hash' => strtoupper($oop['infohash'])]);
            if (empty($seed)) {
                continue;
            }
            $op->admin_id = $admin->user_id;
            $op->seed_id = $seed->seed_id;
            $op->operation_type = $oop['reason'];
            $op->detail_info = json_encode(['reason' => $oop['info']]);
            $op->publisher_id = $seed->publisher_user_id;
            $op->create_time = $this->date($oop['opdate']);
            var_dump($op->attributes);
            if (!$op->insert()) {
                var_dump($op->errors);
                return;
            }
        }
        if (count($res)) {
            $offset += $limit;
            goto QUERY;
        }
        return;
    }