NekonekoID commited on
Commit
978c238
·
verified ·
1 Parent(s): 603c108

Update lib/urlebird.js

Browse files
Files changed (1) hide show
  1. lib/urlebird.js +57 -49
lib/urlebird.js CHANGED
@@ -1,15 +1,15 @@
1
- const axios = require('axios')
2
- const cheerio = require('cheerio')
3
 
4
  class Urlebird {
5
- #get = async (param) => {
6
- let html = (await axios.get(`https://urlebird.com/${encodeURI(param)}/`)).data
7
- let $ = 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,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
- latest = async () => {
44
- let arr = []
45
- for (let data of await this.#get('videos')) arr.push(await this.detailVideo(data))
46
- return arr
47
- }
48
-
49
- popular = async () => {
50
- let arr = []
51
- for (let data of await this.#get('videos/popular')) arr.push(await this.detailVideo(data))
52
- return arr
53
- }
54
-
55
- trending = async () => {
56
- let arr = []
57
- for (let data of await this.#get('trending')) arr.push(await this.detailVideo(data))
58
- return arr
59
- }
60
-
61
- user = async (username) => {
62
- let html = (await axios.get(`https://urlebird.com/user/${username}/`)).data
63
- let $ = cheerio.load(html), obj = {}
64
- let img = $('img.user-image')
65
- let stats = $('div.content').find('div.row > div').get().map(x => $(x).text())
66
- obj.name = img.attr('alt').split(' - ')?.[1]
67
- obj.username = img.attr('alt').split(' - ')?.[0]
68
- obj.likes = stats?.[0]
69
- obj.followers = stats?.[1]?.replace(' followers', '')
70
- obj.following = stats?.[2]?.replace(' following', '')
71
- obj.description = $('div.content > p').text()
72
- obj.avatar = img.attr('src')
73
- obj.videos = []
74
- for (let x of await this.#get(`user/${username}`)) obj.videos.push(await this.detailVideo(x))
75
- return obj
76
- }
77
-
 
 
 
 
 
 
 
 
78
  }
79
 
80
- module.exports = new Urlebird()
 
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();