抖音解析
抖音视频解析接口,支持解析抖音视频链接,返回视频信息。
API接口稳定可用 · 支持高并发请求
API接口信息
接口地址
https://yutangxiaowu.cn:4001/douyin/parse
请求方法
POST
请求参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| 基础视频信息 | - | 视频核心元数据 |
| title | string | 标题 |
| image | string | 视频封面 |
| 视频数据统计 | - | 视频互动数据 |
| video_data.collect_data | number | 视频收藏量 |
| video_data.comment_count | number | 视频评论量 |
| video_data.like_count | number | 视频点赞量 |
| video_data.recommand_count | number | 视频推荐量 |
| video_data.share_count | number | 视频分享量 |
| 作者信息 | - | 视频发布者信息 |
| author.name | string | 作者名称 |
| author.avatar | string | 作者头像 |
| author.douyin_number | string | 抖音号 |
| 音乐信息 | - | 视频使用的音乐素材信息 |
| music.name | string | 音乐名称 |
| music.author | string | 音乐作者 |
| music.image | string | 音乐封面 |
| music.file_url | string | 音乐地址 |
代码示例
JavaScript (Axios)
const axios = require('axios');
const config = {
apiUrl: "http://yutangxiaowu.cn:4001/douyin/parse",
douyinLink: "https://v.douyin.com/cGLJwtOClZo/"
};
try {
const response = await axios.post(config.apiUrl, {
content: config.douyinLink
}, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
withCredentials: true
});
console.log("请求成功:", response.data);
} catch (error) {
console.error("请求出错:", error);
}
JavaScript (Fetch)
const config = {
apiUrl: "http://yutangxiaowu.cn:4001/douyin/parse",
douyinLink: "https://v.douyin.com/cGLJwtOClZo/"
};
try {
const requestBody = {
content: config.douyinLink
};
const response = await fetch(config.apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(requestBody),
credentials: "include"
});
if (!response.ok) {
throw new Error(`接口请求失败,状态码: ${response.status}`);
}
const result = await response.json();
console.log("请求成功:", result);
} catch (error) {
console.error("请求出错:", error);
}
Python
import requests
import json
config = {
"apiUrl": "http://yutangxiaowu.cn:4001/douyin/parse",
"douyinLink": "https://v.douyin.com/cGLJwtOClZo/"
}
try:
request_body = {
"content": config["douyinLink"]
}
response = requests.post(
config["apiUrl"],
data=json.dumps(request_body),
headers={
"Content-Type": "application/json",
"Accept": "application/json"
},
cookies={} # 如果有cookie相关,可在此设置
)
response.raise_for_status()
result = response.json()
print("请求成功:", result)
except requests.exceptions.RequestException as e:
print("请求出错:", e)
PHP
"http://yutangxiaowu.cn:4001/douyin/parse",
"douyinLink" => "https://v.douyin.com/cGLJwtOClZo/"
];
$requestBody = [
"content" => $config["douyinLink"]
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config["apiUrl"]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Accept: application/json"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); // 用于存储cookie
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); // 用于读取cookie
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
echo "接口请求失败,状态码: " . $httpCode;
} else {
$result = json_decode($response, true);
echo "请求成功: " . json_encode($result);
}
curl_close($ch);
?>
Java
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class HttpPostRequest {
public static void main(String[] args) {
String apiUrl = "http://yutangxiaowu.cn:4001/douyin/parse";
String douyinLink = "https://v.douyin.com/cGLJwtOClZo/";
try {
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
String requestBody = "{\"content\": \"" + douyinLink + "\"}";
try (DataOutputStream dos = new DataOutputStream(connection.getOutputStream())) {
dos.writeBytes(requestBody);
dos.flush();
}
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new Exception("接口请求失败,状态码: " + responseCode);
}
BufferedReader br = new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
br.close();
System.out.println("请求成功: " + response.toString());
} catch (Exception e) {
System.err.println("请求出错: " + e.getMessage());
}
}
}
C#
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiUrl = "http://yutangxiaowu.cn:4001/douyin/parse";
string douyinLink = "https://v.douyin.com/cGLJwtOClZo/";
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var requestBody = new
{
content = douyinLink
};
var json = Newtonsoft.Json.JsonConvert.SerializeObject(requestBody);
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(apiUrl, content);
response.EnsureSuccessStatusCode();
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine("请求成功: " + result);
}
}
catch (Exception e)
{
Console.WriteLine("请求出错: " + e.Message);
}
}
}
Ruby
require 'net/http'
require 'json'
config = {
apiUrl: "http://yutangxiaowu.cn:4001/douyin/parse",
douyinLink: "https://v.douyin.com/cGLJwtOClZo/"
}
uri = URI(config[:apiUrl])
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path, {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
})
request.body = { content: config[:douyinLink] }.to_json
begin
response = http.request(request)
if response.code != '200'
raise "接口请求失败,状态码: #{response.code}"
end
result = JSON.parse(response.body)
puts "请求成功: #{result}"
rescue Exception => e
puts "请求出错: #{e.message}"
end
Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type RequestBody struct {
Content string `json:"content"`
}
func main() {
apiUrl := "http://yutangxiaowu.cn:4001/douyin/parse"
douyinLink := "https://v.douyin.com/cGLJwtOClZo/"
requestBody := RequestBody{
Content: douyinLink,
}
jsonData, err := json.Marshal(requestBody)
if err != nil {
fmt.Println("请求出错:", err)
return
}
req, err := http.NewRequest("POST", apiUrl, bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("请求出错:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("请求出错:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Println("接口请求失败,状态码:", resp.StatusCode)
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("请求出错:", err)
return
}
fmt.Println("请求成功:", string(body))
}
Swift
import Foundation
let apiUrl = URL(string: "http://yutangxiaowu.cn:4001/douyin/parse")!
let douyinLink = "https://v.douyin.com/cGLJwtOClZo/"
struct RequestBody: Encodable {
let content: String
}
var request = URLRequest(url: apiUrl)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
do {
let requestBody = RequestBody(content: douyinLink)
request.httpBody = try JSONEncoder().encode(requestBody)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("请求出错:", error)
return
}
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
if let httpResponse = response as? HTTPURLResponse {
print("接口请求失败,状态码:", httpResponse.statusCode)
} else {
print("接口请求失败")
}
return
}
if let data = data {
do {
let result = try JSONSerialization.jsonObject(with: data, options: [])
print("请求成功:", result)
} catch {
print("解析响应出错:", error)
}
}
}
task.resume()
} catch {
print("请求体编码出错:", error)
}
Kotlin
import java.net.HttpURLConnection
import java.net.URL
import java.io.BufferedReader
import java.io.DataOutputStream
import java.io.InputStreamReader
fun main() {
val apiUrl = "http://yutangxiaowu.cn:4001/douyin/parse"
val douyinLink = "https://v.douyin.com/cGLJwtOClZo/"
try {
val url = URL(apiUrl)
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "POST"
connection.setRequestProperty("Content-Type", "application/json")
connection.setRequestProperty("Accept", "application/json")
connection.doOutput = true
val requestBody = "{\"content\": \"$douyinLink\"}"
val dos = DataOutputStream(connection.outputStream)
dos.writeBytes(requestBody)
dos.flush()
dos.close()
val responseCode = connection.responseCode
if (responseCode != HttpURLConnection.HTTP_OK) {
throw Exception("接口请求失败,状态码: $responseCode")
}
val br = BufferedReader(InputStreamReader(connection.inputStream))
val response = StringBuilder()
var line: String?
while (br.readLine().also { line = it } != null) {
response.append(line)
}
br.close()
println("请求成功: $response")
} catch (e: Exception) {
println("请求出错: ${e.message}")
}
}