Support thumbnails in youtube import
authorChocobozzz <me@florianbigard.com>
Wed, 14 Feb 2018 14:56:07 +0000 (15:56 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 14 Feb 2018 15:03:09 +0000 (16:03 +0100)
server/tests/utils/videos/videos.ts
server/tools/import-youtube.ts

index 9d4267db84c00898d5f2ff8f73920c9538dc6078..8e58f1f0c7f4ff1f3b7c15a16fd703e38386252b 100644 (file)
@@ -3,7 +3,7 @@
 import { expect } from 'chai'
 import { existsSync, readFile } from 'fs'
 import * as parseTorrent from 'parse-torrent'
-import { extname, isAbsolute, join } from 'path'
+import { extname, join } from 'path'
 import * as request from 'supertest'
 import {
   buildAbsoluteFixturePath,
index ccbc710299294c2f222d23e80beb6a31c8c74997..325e9f7ba883e85861748d263b7a9b7997e342f3 100644 (file)
@@ -3,6 +3,7 @@ import { join } from 'path'
 import * as youtubeDL from 'youtube-dl'
 import { VideoPrivacy } from '../../shared/models/videos'
 import { unlinkPromise } from '../helpers/core-utils'
+import { doRequestAndSaveToFile } from '../helpers/requests'
 import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils'
 
 program
@@ -98,6 +99,16 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
   const licence = getLicence(videoInfo.license)
   const language = 13
 
+  let thumbnailfile
+  if (videoInfo.thumbnail) {
+    thumbnailfile = join(__dirname, 'thumbnail.jpg')
+
+    await doRequestAndSaveToFile({
+      method: 'GET',
+      uri: videoInfo.thumbnail
+    }, thumbnailfile)
+  }
+
   const videoAttributes = {
     name: videoInfo.title,
     category,
@@ -108,12 +119,18 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
     description: videoInfo.description,
     tags: videoInfo.tags.slice(0, 5),
     privacy: VideoPrivacy.PUBLIC,
-    fixture: videoPath
+    fixture: videoPath,
+    thumbnailfile
   }
 
   console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)
   await uploadVideo(program['url'], accessToken, videoAttributes)
+
   await unlinkPromise(videoPath)
+  if (thumbnailfile) {
+    await unlinkPromise(thumbnailfile)
+  }
+
   console.log('Uploaded video "%s"!\n', videoAttributes.name)
 }