Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aa24615 committed Dec 27, 2022
1 parent b4e7421 commit ff67daa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 53 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"require": {
"php": ">=7.2|^8.0",
"guzzlehttp/guzzle": "^6|^7.2"
"guzzlehttp/guzzle": "^6|^7.2",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static function post(string $url, $data)
{
$client = self::client();
$response = $client->post($url, $data);

return $response->getBody()->getContents();
}

Expand Down
50 changes: 27 additions & 23 deletions src/Provider/Douyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Php127\Douyin\Provider;

use Php127\Douyin\HttpClient\DouyinHttpClient;
use Php127\Douyin\HttpClient\HttpClient;
use Php127\Douyin\ProviderInterface;

/**
Expand All @@ -36,27 +37,34 @@ public function __construct(string $url)
public function setUrl(string $url)
{
$this->url = $url;
$this->html = DouyinHttpClient::get($url);
$this->data = $this->getDouyin();
}

private function getVideoId()
{
preg_match('/href="(.*?)">Found/', $this->html, $matches);
$url_share = $matches[1];
preg_match('/video\/(.*?)\//', $url_share, $matches);

return $matches[1];
private function getContents(string $url){
stream_context_set_default( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$header = get_headers($url,1);
$location = explode('/',$header['Location']);
$body = HttpClient::get('https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id='.$location[5]);
return $body;
}


private function getDouyin()
{
if (is_null($this->data)) {
$videoId = $this->getVideoId();
$json = DouyinHttpClient::get("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=".$videoId);
$this->data = json_decode($json, true);
$this->html = $this->getContents($this->url);
// var_dump($this->html);
$this->data = json_decode($this->html, true);

//print_r($this->data);
}


return $this->data;
}

Expand All @@ -74,33 +82,25 @@ public function getData()
public function getMusic()
{
$this->getDouyin();
return $this->data['item_list'][0]['music']['play_url']['url_list'][0] ?? '';
return $this->data['aweme_detail']['music']['play_url']['url_list'][0] ?? '';
}

public function getImg()
{
$this->getDouyin();
return $this->data['item_list'][0]['video']['origin_cover']['url_list'][0] ?? '';
return $this->data['aweme_detail']['video']['origin_cover']['url_list'][0] ?? '';
}
public function getTitle()
{
$this->getDouyin();
return $this->data['item_list'][0]['desc'] ?? '';
return $this->data['aweme_detail']['desc'] ?? '';
}

public function getUrl()
{
$this->getDouyin();

$vid = $this->data['item_list'][0]['video']['vid'] ?? "";

if ($vid == '') {
return '';
}

$ratio = $this->data['item_list'][0]['video']['ratio'] ?? '540p';

$link = "https://aweme.snssdk.com/aweme/v1/play/?video_id={$vid}&line=0&ratio={$ratio}&media_type=4&vr_type=0&improve_bitrate=0&is_play_url=1&is_support_h265=0&source=PackSourceEnum_PUBLISH";
$link = $this->data['aweme_detail']['video']['play_addr']['url_list'][0] ?? "";

return $link;
}
Expand All @@ -109,6 +109,10 @@ public function getRaw(){
return json_encode($this->data);
}

public function getHtml(){
return $this->html;
}

public function getImages(){
$data = [];
if(isset($this->data['item_list'][0]['images'])){
Expand Down
26 changes: 0 additions & 26 deletions src/Provider/Duoyin/TuanYouGou.php

This file was deleted.

7 changes: 4 additions & 3 deletions tests/Provider/DouyinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class DouyinTest extends TestCase
{
protected $url;

public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub

$this->url = 'https://v.douyin.com/dj4UA2x/';
}



public function testGetDataImage()
{
$app = new Douyin('https://v.douyin.com/MnHDXhK/');
Expand All @@ -29,6 +29,7 @@ public function testGetData()
{
$app = new Douyin($this->url);
$data = $app->getData();
print_r($data);

$this->assertTrue(!empty($data['url']));
$this->assertTrue(!empty($data['img']));
Expand All @@ -41,7 +42,7 @@ public function testGetData2()
$app = new Douyin('https://v.douyin.com/rv4LF76/');
$data = $app->getData();

var_dump($data);
$this->assertTrue(count($data)>0);
}

public function testGetTitle()
Expand Down

0 comments on commit ff67daa

Please sign in to comment.