Spaces:
Running
Running
Update lib/urlebird.js
Browse files- lib/urlebird.js +57 -49
lib/urlebird.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
class Urlebird {
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
const $ = cheerio.load(html);
|
14 |
const obj = { author: {}, video: {} };
|
15 |
|
@@ -29,7 +29,7 @@ class Urlebird {
|
|
29 |
obj.video.likes = statsElements.eq(1).text().trim();
|
30 |
obj.video.comments = statsElements.eq(2).text().trim();
|
31 |
obj.video.share = statsElements.eq(3).text().trim();
|
32 |
-
|
33 |
// Extracting video metadata
|
34 |
obj.video.post = authorElement.find('h6').text().trim();
|
35 |
obj.video.music = $('.music a').text().trim();
|
@@ -38,43 +38,51 @@ class Urlebird {
|
|
38 |
obj.video.url2 = `https://tiktok.com/${obj.author.username}/video/${url.split('-').pop()}`;
|
39 |
|
40 |
return obj;
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
|
80 |
-
|
|
|
1 |
+
import axios from 'axios';
|
2 |
+
import cheerio from 'cheerio';
|
3 |
|
4 |
class Urlebird {
|
5 |
+
#get = async (param) => {
|
6 |
+
const html = (await axios.get(`https://urlebird.com/${encodeURI(param)}/`)).data;
|
7 |
+
const $ = cheerio.load(html);
|
8 |
+
return $('div.thumb').get().map(x => encodeURI($(x).find('a').eq(2).attr('href')));
|
9 |
+
};
|
10 |
+
|
11 |
+
detailVideo = async (url) => {
|
12 |
+
const { data: html } = await axios.get(url);
|
13 |
const $ = cheerio.load(html);
|
14 |
const obj = { author: {}, video: {} };
|
15 |
|
|
|
29 |
obj.video.likes = statsElements.eq(1).text().trim();
|
30 |
obj.video.comments = statsElements.eq(2).text().trim();
|
31 |
obj.video.share = statsElements.eq(3).text().trim();
|
32 |
+
|
33 |
// Extracting video metadata
|
34 |
obj.video.post = authorElement.find('h6').text().trim();
|
35 |
obj.video.music = $('.music a').text().trim();
|
|
|
38 |
obj.video.url2 = `https://tiktok.com/${obj.author.username}/video/${url.split('-').pop()}`;
|
39 |
|
40 |
return obj;
|
41 |
+
};
|
42 |
+
|
43 |
+
latest = async () => {
|
44 |
+
const arr = [];
|
45 |
+
for (const data of await this.#get('videos')) {
|
46 |
+
arr.push(await this.detailVideo(data));
|
47 |
+
}
|
48 |
+
return arr;
|
49 |
+
};
|
50 |
+
|
51 |
+
popular = async () => {
|
52 |
+
const arr = [];
|
53 |
+
for (const data of await this.#get('videos/popular')) {
|
54 |
+
arr.push(await this.detailVideo(data));
|
55 |
+
}
|
56 |
+
return arr;
|
57 |
+
};
|
58 |
+
|
59 |
+
trending = async () => {
|
60 |
+
const arr = [];
|
61 |
+
for (const data of await this.#get('trending')) {
|
62 |
+
arr.push(await this.detailVideo(data));
|
63 |
+
}
|
64 |
+
return arr;
|
65 |
+
};
|
66 |
+
|
67 |
+
user = async (username) => {
|
68 |
+
const html = (await axios.get(`https://urlebird.com/user/${username}/`)).data;
|
69 |
+
const $ = cheerio.load(html);
|
70 |
+
const obj = {};
|
71 |
+
const img = $('img.user-image');
|
72 |
+
const stats = $('div.content').find('div.row > div').get().map(x => $(x).text());
|
73 |
+
obj.name = img.attr('alt').split(' - ')?.[1];
|
74 |
+
obj.username = img.attr('alt').split(' - ')?.[0];
|
75 |
+
obj.likes = stats?.[0];
|
76 |
+
obj.followers = stats?.[1]?.replace(' followers', '');
|
77 |
+
obj.following = stats?.[2]?.replace(' following', '');
|
78 |
+
obj.description = $('div.content > p').text();
|
79 |
+
obj.avatar = img.attr('src');
|
80 |
+
obj.videos = [];
|
81 |
+
for (const x of await this.#get(`user/${username}`)) {
|
82 |
+
obj.videos.push(await this.detailVideo(x));
|
83 |
+
}
|
84 |
+
return obj;
|
85 |
+
};
|
86 |
}
|
87 |
|
88 |
+
export default new Urlebird();
|