该模块用于从 patreon rss feed 下载每个 mp3 文件。
它目前处于 alpha 状态,对于我的特定用例功能非常好,对于其他用例也有一定的作用。下一次更新将提供更好的选项对象来根据您的喜好控制各个方面。现在,它只会将 rss feed 中的每个音频/mpeg 类型文件下载到当前目录。
您需要从 patreon 活动网站获取您的个人 rss 链接(patreon.com -> “会员资格”下的侧边栏 -> 个人活动 -> 会员选项卡 -> 快速链接 -> “收听其他播客应用程序”)
import getRssItems from 'patreon-mp3-downloader' ;
const items = await getRssItems ( 'https://www.patreon.com/rss/PATREONCAMPAIGN?auth=PATREON_PROVIDED_AUTH_TOKEN_STRING' ) ;
// this will be an array of Item objects, that has a title and a url
// as well as a download() method that you can use to trigger the download of
// an individual file.
console . log ( items ) ;
// since you have an array of objects that each contains it's own download method,
// you are free to download them as you like.
// download the latest item in the rss feed:
await items [ 0 ] . download ( ) ;
// download each item in sequence, starting with the latest, prepending a number to the file name:
let counter = items . length ;
for ( const item of items ) {
console . log ( `downloading ${ counter } - ${ item . fileName } ` ) ;
await item . download ( ` ${ counter } - ` ) ;
counter -- ;
}
// download every item in the feed at once (do not recommend for larger feeds):
await Promise . all ( items . map ( i => await i . download ( ) ) )
// you could also chunk the array with lodash, and Promise.all each chunk:
import _ from 'lodash' ;
const chunks = _ . chunk ( items , 5 ) ;
for ( const chunk of chunks ) {
await Promise . all ( chunk . map ( i => await i . download ( ) ) ) ;
}
同样,下一次更新将提供一个更加用户友好的界面,内置上述方法。
用?和 ?