aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-14 15:56:07 +0100
committerChocobozzz <me@florianbigard.com>2018-02-14 16:03:09 +0100
commit1d791a26de648d798df4ee1c04113baf7f1f3b4c (patch)
tree5625ae080768abbba47142dd23930c4f3d818dbf /server
parente3a682a877a10833cb54ac3595e55110bda95647 (diff)
downloadPeerTube-1d791a26de648d798df4ee1c04113baf7f1f3b4c.tar.gz
PeerTube-1d791a26de648d798df4ee1c04113baf7f1f3b4c.tar.zst
PeerTube-1d791a26de648d798df4ee1c04113baf7f1f3b4c.zip
Support thumbnails in youtube import
Diffstat (limited to 'server')
-rw-r--r--server/tests/utils/videos/videos.ts2
-rw-r--r--server/tools/import-youtube.ts19
2 files changed, 19 insertions, 2 deletions
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 9d4267db8..8e58f1f0c 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -3,7 +3,7 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { existsSync, readFile } from 'fs' 4import { existsSync, readFile } from 'fs'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, isAbsolute, join } from 'path' 6import { extname, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { 8import {
9 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath,
diff --git a/server/tools/import-youtube.ts b/server/tools/import-youtube.ts
index ccbc71029..325e9f7ba 100644
--- a/server/tools/import-youtube.ts
+++ b/server/tools/import-youtube.ts
@@ -3,6 +3,7 @@ import { join } from 'path'
3import * as youtubeDL from 'youtube-dl' 3import * as youtubeDL from 'youtube-dl'
4import { VideoPrivacy } from '../../shared/models/videos' 4import { VideoPrivacy } from '../../shared/models/videos'
5import { unlinkPromise } from '../helpers/core-utils' 5import { unlinkPromise } from '../helpers/core-utils'
6import { doRequestAndSaveToFile } from '../helpers/requests'
6import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' 7import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils'
7 8
8program 9program
@@ -98,6 +99,16 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
98 const licence = getLicence(videoInfo.license) 99 const licence = getLicence(videoInfo.license)
99 const language = 13 100 const language = 13
100 101
102 let thumbnailfile
103 if (videoInfo.thumbnail) {
104 thumbnailfile = join(__dirname, 'thumbnail.jpg')
105
106 await doRequestAndSaveToFile({
107 method: 'GET',
108 uri: videoInfo.thumbnail
109 }, thumbnailfile)
110 }
111
101 const videoAttributes = { 112 const videoAttributes = {
102 name: videoInfo.title, 113 name: videoInfo.title,
103 category, 114 category,
@@ -108,12 +119,18 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string) {
108 description: videoInfo.description, 119 description: videoInfo.description,
109 tags: videoInfo.tags.slice(0, 5), 120 tags: videoInfo.tags.slice(0, 5),
110 privacy: VideoPrivacy.PUBLIC, 121 privacy: VideoPrivacy.PUBLIC,
111 fixture: videoPath 122 fixture: videoPath,
123 thumbnailfile
112 } 124 }
113 125
114 console.log('\nUploading on PeerTube video "%s".', videoAttributes.name) 126 console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)
115 await uploadVideo(program['url'], accessToken, videoAttributes) 127 await uploadVideo(program['url'], accessToken, videoAttributes)
128
116 await unlinkPromise(videoPath) 129 await unlinkPromise(videoPath)
130 if (thumbnailfile) {
131 await unlinkPromise(thumbnailfile)
132 }
133
117 console.log('Uploaded video "%s"!\n', videoAttributes.name) 134 console.log('Uploaded video "%s"!\n', videoAttributes.name)
118} 135}
119 136