diff options
Diffstat (limited to 'server/tools/import-youtube.ts')
-rw-r--r-- | server/tools/import-youtube.ts | 19 |
1 files changed, 18 insertions, 1 deletions
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' | |||
3 | import * as youtubeDL from 'youtube-dl' | 3 | import * as youtubeDL from 'youtube-dl' |
4 | import { VideoPrivacy } from '../../shared/models/videos' | 4 | import { VideoPrivacy } from '../../shared/models/videos' |
5 | import { unlinkPromise } from '../helpers/core-utils' | 5 | import { unlinkPromise } from '../helpers/core-utils' |
6 | import { doRequestAndSaveToFile } from '../helpers/requests' | ||
6 | import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' | 7 | import { getClient, getVideoCategories, login, searchVideo, uploadVideo } from '../tests/utils' |
7 | 8 | ||
8 | program | 9 | program |
@@ -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 | ||