在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:fent/node-ytdl-core开源软件地址:https://github.com/fent/node-ytdl-core开源编程语言:JavaScript 100.0%开源软件介绍:node-ytdl-coreYet another YouTube downloading module. Written with only Javascript and a node-friendly streaming interface. SupportYou can contact us for support on our chat server Usageconst fs = require('fs');
const ytdl = require('ytdl-core');
// TypeScript: import ytdl from 'ytdl-core'; with --esModuleInterop
// TypeScript: import * as ytdl from 'ytdl-core'; with --allowSyntheticDefaultImports
// TypeScript: import ytdl = require('ytdl-core'); with neither of the above
ytdl('http://www.youtube.com/watch?v=aqz-KE-bpKQ')
.pipe(fs.createWriteStream('video.mp4')); APIytdl(url, [options])Attempts to download a video from the given url. Returns a readable stream.
Event: info
Emitted when the video's Event: progress
Emitted whenever a new chunk is received. Passes values describing the download progress. miniget eventsAll miniget events are forwarded and can be listened to from the returned stream. Stream#destroy()Call to abort and stop downloading a video. async ytdl.getBasicInfo(url, [options])Use this if you only want to get metainfo from a video. async ytdl.getInfo(url, [options])Gets metainfo from a video. Includes additional formats, and ready to download deciphered URL. This is what the
ytdl.downloadFromInfo(info, options)Once you have received metadata from a video with the ytdl.chooseFormat(formats, options)Can be used if you'd like to choose a format yourself. Throws an Error if it fails to find any matching format.
// Example of choosing a video format.
let info = await ytdl.getInfo(videoID);
let format = ytdl.chooseFormat(info.formats, { quality: '134' });
console.log('Format found!', format); ytdl.filterFormats(formats, filter)If you'd like to work with only some formats, you can use the // Example of filtering the formats to audio only.
let info = await ytdl.getInfo(videoID);
let audioFormats = ytdl.filterFormats(info.formats, 'audioonly');
console.log('Formats with only audio: ' + audioFormats.length); ytdl.validateID(id)Returns true if the given string satisfies YouTube's ID format. ytdl.validateURL(url)Returns true if able to parse out a valid video ID. ytdl.getURLVideoID(url)Returns a video ID from a YouTube URL. Throws an Error if it fails to parse an ID. ytdl.getVideoID(str)Same as the above ytdl.versionThe version string taken directly from the package.json. Limitationsytdl cannot download videos that fall into the following
Generated download links are valid for 6 hours, and may only be downloadable from the same IP address. RatelimitsWhen doing to many requests YouTube might block. This will result in your requests getting denied with HTTP-StatusCode 429. The following Steps might help you:
How does using an IPv6 block help?For request-intensive tasks it might be useful to spread your requests across multiple source IP-Addresses. Changing the source IP that you use is similar to using a proxy, except without bypassing restrictions such as a region lock. More IP-Addresses result in less requests per IP and therefor increase your ratelimit. Since IPv4 Addresses are a limited Resource we advise to use IPv6. Using an IPv6 block is essentially having millions of IPv6 addresses at your request. In a /64 IPv6 block (which is usually the Block given to a single Household), there are 18,446,744,073,709,551,616 unique IPv6 addresses. This would allow you to make each request with a different IPv6 address. Even though using an IP-Block does help against ratelimits it requires you to setup your host system to accept http traffic from every message in an IP-Block. We can not help you with the setup for any specific host / hosting provider but searching the internet most likely can. Handling Separate StreamsTypically 1080p or better videos do not have audio encoded with it. The audio must be downloaded separately and merged via an encoding library. What if it stops working?YouTube updates their website all the time, it's not that rare for this to stop working. If it doesn't work for you and you're using the latest version, feel free to open up an issue. Make sure to check if there isn't one already with the same error. Run the tests at
These tests are not mocked, they try to start downloading a few videos. If these fail, then it's time to debug. If the error you're getting is signature deciphering, check Installnpm install ytdl-core@latest Or for Yarn users: yarn add ytdl-core@latest Make sure you're installing the latest version of ytdl-core to keep up with the latest fixes. If you're using a bot or app that uses ytdl-core such as ytdl-core-discord or discord-player, it may be dependent on an older version. To update its ytdl-core version, that library has to update its Look in their repo to see if they already have an active pull request that updates ytdl-core. If they don't, open an issue asking them to update ytdl-core, or better yet, fork the project and submit a pull request with the updated version. While you wait for the pull reques to merge, you can point to its branch in your "ytdl-core-discord": "amishshah/ytdl-core-discord#dependabot/npm_and_yarn/ytdl-core-2.0.1" Update ChecksThe issue of using an outdated version of ytdl-core became so prevalent, that ytdl-core now checks for updates at run time, and every 12 hours. If it finds an update, it will print a warning to the console advising you to update. Due to the nature of this library, it is important to always use the latest version as YouTube continues to update. If you'd like to disable this update check, you can do so by providing the
Related Projects
TestsTests are written with mocha npm test |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论