-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_sync_firebase_function.ts
59 lines (42 loc) · 1.76 KB
/
media_sync_firebase_function.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
const youtubedl = require('youtube-dl');
const os = require('os');
const tmpFilePath = os.tmpdir();
const path = require('path');
const customBinaryPath = path.resolve(tmpFilePath);
admin.initializeApp()
// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript
export const getDownloadLinks = functions.region('us-central1').https.onCall((data, context) => {
const playlists = data.playlists;
const vidsToDownload:string[] = [];
const downloadLinks:string[] = ['dhdh','dudu'];
const authorNames:string[] = ['ahah','auau'];
const fileNames:string[] = ['fhfh','fifi'];
console.log(getVidsInPlaylist(playlists[0]));
return {
"playlists":playlists,
"vidsToDownload": vidsToDownload,
"downloadLinks": downloadLinks,
"fileNames": fileNames,
"authorNames": authorNames,
};
});
function getVidsInPlaylist(plist:string): string[]{
const videos:string[] = [plist];
console.log(tmpFilePath);
youtubedl.setYtdlBinary(customBinaryPath)
//code that was previously here to get the videos in the playlist kept giving an error I couldn't find a solution to. The code below was simply just my attempts to debug the problem.
youtubedl.getInfo(plist, [], function(err:any, info:any) {
if (err) throw err
console.log('id:', info.id)
console.log('title:', info.title)
console.log('url:', info.url)
console.log('thumbnail:', info.thumbnail)
console.log('description:', info.description)
console.log('filename:', info._filename)
console.log('format id:', info.format_id)
})
return videos;
}