yt-downloadify 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/publish.yml +20 -0
- package/README.md +20 -0
- package/index.js +75 -0
- package/package.json +13 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
name: "publish npm"
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
publish:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- name: checkout
|
10
|
+
uses: actions/checkout@v2
|
11
|
+
- name: node
|
12
|
+
uses: actions/setup-node@v2
|
13
|
+
with:
|
14
|
+
node-version: 14
|
15
|
+
registry-url: https://registry.npmjs.org
|
16
|
+
- name: publish
|
17
|
+
run: npm publish --access public
|
18
|
+
# working-directory: package.json
|
19
|
+
env:
|
20
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
|
package/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# YT-DOWNLOADIFY
|
2
|
+
## UNOFFICIAL YT VIDEO/AUDIO DOWNLOAD API MADE BY MARYAM RAJPUT
|
3
|
+
### Downloading Audio/Video
|
4
|
+
|
5
|
+
```js
|
6
|
+
// Copyright Maryam All Rights Reserved
|
7
|
+
// You Can Get Api Key From: Facebook.com/naugh7y.dev
|
8
|
+
const { downloadMedia } = require('youtube-media-downloader');
|
9
|
+
const song = 'Bado Badi'; // Enter A Song Video Name
|
10
|
+
const type = 'video'; // You Can Use "audio" or "video" Depends On You
|
11
|
+
async function fetchMedia() {
|
12
|
+
try {
|
13
|
+
const result = await downloadMedia({ song, type, apikey: 'YOUR_API_KEY' });
|
14
|
+
console.log('Downloaded Sucessfully:', result);
|
15
|
+
} catch (chabli) {
|
16
|
+
console.error('Error fetching media:', chabli.message);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
fetchMedia();
|
20
|
+
```
|
package/index.js
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
const ytSearch = require('yt-search');
|
2
|
+
const CobaltAPI = require('cobalt-api');
|
3
|
+
const tinyurl = require('tinyurl');
|
4
|
+
|
5
|
+
const API_KEY = 'maryam-youtube-api';
|
6
|
+
async function shortenUrl(longUrl) {
|
7
|
+
try {
|
8
|
+
const shortUrl = await tinyurl.shorten(longUrl);
|
9
|
+
return shortUrl;
|
10
|
+
} catch (error) {
|
11
|
+
console.error('Error shortening URL:', error.message);
|
12
|
+
return longUrl;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
async function downloadMedia({ song, type = 'audio', apikey }) {
|
16
|
+
if (apikey !== API_KEY) {
|
17
|
+
throw new Error('Wrong Api Key If You Dont Know Contact Author');
|
18
|
+
}
|
19
|
+
|
20
|
+
if (!song) {
|
21
|
+
throw new Error('Please Write A Song/Video Name');
|
22
|
+
}
|
23
|
+
|
24
|
+
const searchType = type;
|
25
|
+
try {
|
26
|
+
const searchResults = await ytSearch(song);
|
27
|
+
const video = searchResults.videos[0];
|
28
|
+
|
29
|
+
if (!video) {
|
30
|
+
throw new Error('Video Not Found');
|
31
|
+
}
|
32
|
+
|
33
|
+
const videoId = video.videoId;
|
34
|
+
const youtubeUrl = `https://www.youtube.com/watch?v=${videoId}`;
|
35
|
+
const cobalt = new CobaltAPI(youtubeUrl);
|
36
|
+
|
37
|
+
let downloadResponse;
|
38
|
+
|
39
|
+
if (searchType === 'audio') {
|
40
|
+
cobalt.setAFormat('best');
|
41
|
+
cobalt.enableAudioOnly();
|
42
|
+
downloadResponse = await cobalt.sendRequest();
|
43
|
+
} else if (searchType === 'video') {
|
44
|
+
const qualities = await cobalt.getAvailableQualities();
|
45
|
+
cobalt.setQuality(qualities.includes('360') ? '360' : (qualities.includes('480') ? '480' : qualities[0]));
|
46
|
+
downloadResponse = await cobalt.sendRequest();
|
47
|
+
} else {
|
48
|
+
throw new Error('Use mp4 or mp3');
|
49
|
+
}
|
50
|
+
|
51
|
+
const downloadUrl = downloadResponse.status ? downloadResponse.data.url || downloadResponse.data : '';
|
52
|
+
const shortUrl = await shortenUrl(downloadUrl);
|
53
|
+
|
54
|
+
if (downloadResponse.status) {
|
55
|
+
return {
|
56
|
+
creator: 'Maryam (Ñaughty Queen)',
|
57
|
+
creator_contact: "facebook.com/naugh7y.dev",
|
58
|
+
type: searchType,
|
59
|
+
title: video.title,
|
60
|
+
description: video.description,
|
61
|
+
duration: video.timestamp,
|
62
|
+
views: video.views,
|
63
|
+
authorName: video.author.name,
|
64
|
+
uploadDate: video.ago,
|
65
|
+
downloadUrl: downloadUrl,
|
66
|
+
shortUrl: shortUrl,
|
67
|
+
};
|
68
|
+
} else {
|
69
|
+
throw new Error(`Download Failed: ${downloadResponse.text}`);
|
70
|
+
}
|
71
|
+
} catch (error) {
|
72
|
+
throw new Error(`An error occurred: ${error.message}`);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
module.exports = { downloadMedia };
|
package/package.json
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"name": "yt-downloadify",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "Download audio and video from YouTube based With Name Via yt-downloadify",
|
5
|
+
"main": "index.js",
|
6
|
+
"author": "Maryam (Ñaughty Queen)",
|
7
|
+
"license": "MIT",
|
8
|
+
"dependencies": {
|
9
|
+
"yt-search": "^2.10.3",
|
10
|
+
"cobalt-api": "^1.0.0",
|
11
|
+
"tinyurl": "^1.0.0"
|
12
|
+
}
|
13
|
+
}
|