Skip to content

Commit

Permalink
[RutubeBridge] New option to fetch video from search results
Browse files Browse the repository at this point in the history
  • Loading branch information
em92 committed Jul 26, 2024
1 parent da8cfdf commit 3c846ac
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion bridges/RutubeBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class RutubeBridge extends BridgeAbstract
'required' => true
],
],
'По результатам поиска' => [
's' => [
'name' => 'Запрос',
'exampleValue' => 'SUREN',
'required' => true,
]
]
];

protected $title;
Expand All @@ -34,6 +41,8 @@ public function getURI()
return self::URI . '/channel/' . strval($this->getInput('c')) . '/videos/';
} elseif ($this->getInput('p')) {
return self::URI . '/plst/' . strval($this->getInput('p')) . '/';
} elseif ($this->getInput('s')) {
return self::URI . '/search/?suggest=1&query=' . strval($this->getInput('s'));
} else {
return parent::getURI();
}
Expand All @@ -60,7 +69,7 @@ private function getJSONData($html)
return json_decode(str_replace('\x', '\\\x', $matches[1]));
}

public function collectData()
private function getVideosFromReduxState()
{
$link = $this->getURI();

Expand All @@ -73,6 +82,26 @@ public function collectData()
} elseif ($this->getInput('p')) {
$videos = $reduxState->playlist->data->results;
$this->title = $reduxState->playlist->title;
} elseif ($this->getInput('s')) {
$this->title = 'Поиск ' . $this->getInput('s');
}

return $videos;
}

private function getVideosFromSearchAPI()
{
$contents = getContents(self::URI . '/api/search/video/?suggest=1&client=wdp&query=' . $this->getInput('s'));
$json = json_decode($contents);
return $json->results;
}

public function collectData()
{
if ($this->getInput('c') || $this->getInput('p')) {
$videos = $this->getVideosFromReduxState();
} else {
$videos = $this->getVideosFromSearchAPI();
}

foreach ($videos as $video) {
Expand Down

0 comments on commit 3c846ac

Please sign in to comment.