.option('-u, --url <url>', 'Server url')
.option('-U, --username <username>', 'Username')
.option('-p, --password <token>', 'Password')
.option('-u, --url <url>', 'Server url')
.option('-U, --username <username>', 'Username')
.option('-p, --password <token>', 'Password')
youtubeDL.getInfo(program['youtubeUrl'], [ '-j', '--flat-playlist' ], async (err, info) => {
if (err) throw err
youtubeDL.getInfo(program['youtubeUrl'], [ '-j', '--flat-playlist' ], async (err, info) => {
if (err) throw err
const videos = info.map(i => {
return { url: 'https://www.youtube.com/watch?v=' + i.id, name: i.title }
})
const videos = info.map(i => {
return { url: 'https://www.youtube.com/watch?v=' + i.id, name: i.title }
})
- const result = await searchVideo(program['url'], videoUrlName.name)
+ const result = await searchVideo(program['url'], video.name)
+
+ console.log('############################################################\n')
+
- let size = 0
- video.on('info', info => {
- videoInfo = info
- size = info.size
+ youtubeDL.exec(video.url, [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]', '-o', path ], {}, async (err, output) => {
+ if (err) return console.error(err)
- videoPath = join(__dirname, size + '.mp4')
- console.log('Creating "%s" of video "%s".', videoPath, videoInfo.title)
+ console.log(output.join('\n'))
- let pos = 0
- video.on('data', chunk => {
- pos += chunk.length
- // `size` should not be 0 here.
- if (size) {
- const percent = (pos / size * 100).toFixed(2)
- writeWaitingPercent(percent)
- }
- })
+ await uploadVideoOnPeerTube(normalizeObject(videoInfo), path)
async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
const category = await getCategory(videoInfo.categories)
const licence = getLicence(videoInfo.license)
async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
const category = await getCategory(videoInfo.categories)
const licence = getLicence(videoInfo.license)
+
+function normalizeObject (obj: any) {
+ const newObj: any = {}
+
+ for (const key of Object.keys(obj)) {
+ // Deprecated key
+ if (key === 'resolution') continue
+
+ const value = obj[key]
+
+ if (typeof value === 'string') {
+ newObj[key] = value.normalize()
+ } else {
+ newObj[key] = value
+ }
+ }
+
+ return newObj
+}