randydev commited on
Commit
f44bab2
·
verified ·
1 Parent(s): 835ea93

Update lib/facebook.js

Browse files
Files changed (1) hide show
  1. lib/facebook.js +44 -53
lib/facebook.js CHANGED
@@ -1,19 +1,19 @@
1
- import got from 'got'
2
- import * as cheerio from 'cheerio'
3
- import { FacebookDlArgsSchema, FacebookDlMediaSchema, FacebookDlSchema } from '../types/facebook-v1.js'
4
- import { DEFAULT_HEADERS } from './constant.js'
5
 
6
  export async function facebookdl(url) {
7
- FacebookDlArgsSchema.parse(arguments)
8
  const html = await got('https://fdownloader.net/en', {
9
  headers: {
10
  ...DEFAULT_HEADERS
11
  }
12
- }).text()
13
- const k_url_search = /k_url_search="(.*?)"/.exec(html)![1]
14
- const k_exp = /k_exp="(.*?)"/.exec(html)![1]
15
- const k_token = /k_token="(.*?)"/.exec(html)![1]
16
- const k_prefix_name = /k_prefix_name="(.*?)"/.exec(html)![1]
17
 
18
  const form = {
19
  k_exp,
@@ -23,77 +23,68 @@ export async function facebookdl(url) {
23
  web: 'fdownloader.net',
24
  v: 'v2',
25
  w: ''
26
- }
27
  const data = await got.post(k_url_search, {
28
  headers: {
29
  ...DEFAULT_HEADERS,
30
  referer: 'https://fdownloader.net/'
31
  },
32
  form
33
- }).json<{ data: string }>()
34
 
35
- const $ = cheerio.load(data.data)
36
 
37
- const k_url_convert = /k_url_convert = "(.*?)"/.exec($.html())![1]
38
- const c_exp = /k_exp = "(.*?)"/.exec($.html())![1]
39
- const c_token = /c_token = "(.*?)"/.exec($.html())![1]
40
 
41
- const thumbnail = $('.thumbnail > .image-fb > img').attr('src')
42
- const duration = $('.content > .clearfix > p').text() || undefined
43
  const video = $('table.table').eq(0).find('tbody > tr').map((_, el) => {
44
- const $el = $(el)
45
- const $td = $el.find('td')
46
- const quality = $td.eq(0).text()
47
- const url = $td.eq(2).find('a').attr('href')
48
  if (url) {
49
  return {
50
  quality,
51
  download: () => Promise.resolve(url)
52
- }
53
  }
54
  // TODO:
55
- return false
56
- const $button = $td.eq(2).find('button')
57
- const ftype = 'mp4'
58
- const v_id = $('#FbId').attr('value')
59
- const videoUrl = $button.attr('data-videourl')
60
- const videoType = $button.attr('data-videotype')
61
- const videoCodec = $button.attr('data-videocodec')
62
- const fquality = $button.attr('data-fquality')
63
- const audioUrl = $('#audioUrl').attr('value')
64
- const audioType = $('#audioType').attr('value')
65
- }).toArray().filter(Boolean)
66
 
67
- const audio: FacebookDlMediaSchema = []
68
- const audioUrl = $('#audioUrl').attr('value')!
69
  audio.push({
70
  quality: '7kbps',
71
  download: () => Promise.resolve(audioUrl)
72
- })
73
 
74
  const result = {
75
  thumbnail,
76
  duration,
77
  video,
78
  audio
79
- }
80
- console.log(result)
81
- return FacebookDlSchema.parse(result)
82
  }
83
 
84
  export async function convert(
85
- url: string,
86
- v_id: string,
87
- ftype: string,
88
- videoUrl: string,
89
- videoType: string,
90
- videoCodec: string,
91
- audioUrl: string,
92
- audioType: string,
93
- fquality: string,
94
- fname: string,
95
- exp: string,
96
- token: string,
97
  ) {
98
  const data = await got.post(url, {
99
  form: {
@@ -110,5 +101,5 @@ export async function convert(
110
  token,
111
  cv: 'v2'
112
  }
113
- })
114
  }
 
1
+ import got from 'got';
2
+ import * as cheerio from 'cheerio';
3
+ import { FacebookDlArgsSchema, FacebookDlMediaSchema, FacebookDlSchema } from '../lib/types/facebook-v1.js';
4
+ import { DEFAULT_HEADERS } from './constant.js';
5
 
6
  export async function facebookdl(url) {
7
+ FacebookDlArgsSchema.parse(arguments);
8
  const html = await got('https://fdownloader.net/en', {
9
  headers: {
10
  ...DEFAULT_HEADERS
11
  }
12
+ }).text();
13
+ const k_url_search = /k_url_search="(.*?)"/.exec(html)[1];
14
+ const k_exp = /k_exp="(.*?)"/.exec(html)[1];
15
+ const k_token = /k_token="(.*?)"/.exec(html)[1];
16
+ const k_prefix_name = /k_prefix_name="(.*?)"/.exec(html)[1];
17
 
18
  const form = {
19
  k_exp,
 
23
  web: 'fdownloader.net',
24
  v: 'v2',
25
  w: ''
26
+ };
27
  const data = await got.post(k_url_search, {
28
  headers: {
29
  ...DEFAULT_HEADERS,
30
  referer: 'https://fdownloader.net/'
31
  },
32
  form
33
+ }).json();
34
 
35
+ const $ = cheerio.load(data.data);
36
 
37
+ const k_url_convert = /k_url_convert = "(.*?)"/.exec($.html())[1];
38
+ const c_exp = /k_exp = "(.*?)"/.exec($.html())[1];
39
+ const c_token = /c_token = "(.*?)"/.exec($.html())[1];
40
 
41
+ const thumbnail = $('.thumbnail > .image-fb > img').attr('src');
42
+ const duration = $('.content > .clearfix > p').text() || undefined;
43
  const video = $('table.table').eq(0).find('tbody > tr').map((_, el) => {
44
+ const $el = $(el);
45
+ const $td = $el.find('td');
46
+ const quality = $td.eq(0).text();
47
+ const url = $td.eq(2).find('a').attr('href');
48
  if (url) {
49
  return {
50
  quality,
51
  download: () => Promise.resolve(url)
52
+ };
53
  }
54
  // TODO:
55
+ return false;
56
+ }).toArray().filter(Boolean);
 
 
 
 
 
 
 
 
 
57
 
58
+ const audio = [];
59
+ const audioUrl = $('#audioUrl').attr('value');
60
  audio.push({
61
  quality: '7kbps',
62
  download: () => Promise.resolve(audioUrl)
63
+ });
64
 
65
  const result = {
66
  thumbnail,
67
  duration,
68
  video,
69
  audio
70
+ };
71
+ console.log(result);
72
+ return FacebookDlSchema.parse(result);
73
  }
74
 
75
  export async function convert(
76
+ url,
77
+ v_id,
78
+ ftype,
79
+ videoUrl,
80
+ videoType,
81
+ videoCodec,
82
+ audioUrl,
83
+ audioType,
84
+ fquality,
85
+ fname,
86
+ exp,
87
+ token
88
  ) {
89
  const data = await got.post(url, {
90
  form: {
 
101
  token,
102
  cv: 'v2'
103
  }
104
+ });
105
  }