From fa27f07637dd941577ab78de528cbef044b46248 Mon Sep 17 00:00:00 2001 From: BRAINS YUM <43896676+McFlat@users.noreply.github.com> Date: Wed, 24 Oct 2018 13:07:51 -0500 Subject: allow peertube-import-videos.ts CLI script to run concurrently (#1334) allows running multiple imports at the same time, whereas previously a concurrent instance of the script deleted another processe's file. --- server/tools/peertube-import-videos.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tools/peertube-import-videos.ts') diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 13090a028..21505b79d 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -10,6 +10,7 @@ import { getClient, getVideoCategories, login, searchVideoWithSort, uploadVideo import { truncate } from 'lodash' import * as prompt from 'prompt' import { remove } from 'fs-extra' +import { sha256 } from '../helpers/core-utils' import { safeGetYoutubeDL } from '../helpers/youtube-dl' import { getSettings, netrc } from './cli' @@ -133,8 +134,7 @@ async function run (user, url: string) { await processVideo(info, program['language'], processOptions.cwd, url, user) } - // https://www.youtube.com/watch?v=2Upx39TBc1s - console.log('I\'m finished!') + console.log('Video/s for user %s imported: %s', program['username'], program['targetUrl']) process.exit(0) }) } @@ -155,7 +155,7 @@ function processVideo (info: any, languageCode: string, cwd: string, url: string return res() } - const path = join(cwd, new Date().getTime() + '.mp4') + const path = join(cwd, sha256(videoInfo.url) + '.mp4') console.log('Downloading video "%s"...', videoInfo.title) @@ -192,7 +192,7 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: st let thumbnailfile if (videoInfo.thumbnail) { - thumbnailfile = join(cwd, 'thumbnail.jpg') + thumbnailfile = join(cwd, sha256(videoInfo.thumbnail) + '.jpg') await doRequestAndSaveToFile({ method: 'GET', -- cgit v1.2.3 From 9639bd175726b73f8fe664b5ced12a72407b1f0b Mon Sep 17 00:00:00 2001 From: buoyantair Date: Mon, 29 Oct 2018 22:18:31 +0530 Subject: Move utils to /shared Move utils used by /server/tools/* & /server/tests/**/* into /shared folder. Issue: #1336 --- server/tools/peertube-import-videos.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tools/peertube-import-videos.ts') diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 21505b79d..1fe0a9348 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -6,7 +6,7 @@ import { join } from 'path' import { VideoPrivacy } from '../../shared/models/videos' import { doRequestAndSaveToFile } from '../helpers/requests' import { CONSTRAINTS_FIELDS } from '../initializers' -import { getClient, getVideoCategories, login, searchVideoWithSort, uploadVideo } from '../tests/utils' +import { getClient, getVideoCategories, login, searchVideoWithSort, uploadVideo } from '../../shared/utils/index' import { truncate } from 'lodash' import * as prompt from 'prompt' import { remove } from 'fs-extra' -- cgit v1.2.3 From ab4dbe36579f6d92511e78cae2762c49a97001fe Mon Sep 17 00:00:00 2001 From: HesioZ Date: Sat, 15 Dec 2018 01:43:04 +0100 Subject: Remove the eventual trailing '/' at the end of urls (see #1453) (#1480) remove eventual trailing '/' at the end of urls in import script (see #1453) --- server/tools/peertube-import-videos.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'server/tools/peertube-import-videos.ts') diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 1fe0a9348..2874a2131 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -58,6 +58,7 @@ getSettings() settings.remotes[settings.default] : settings.remotes[0] } + if (!program['username']) program['username'] = netrc.machines[program['url']].login if (!program['password']) program['password'] = netrc.machines[program['url']].password } @@ -69,6 +70,9 @@ getSettings() process.exit(-1) } + removeEndSlashes(program['url']) + removeEndSlashes(program['targetUrl']) + const user = { username: program['username'], password: program['password'] @@ -321,3 +325,9 @@ function isNSFW (info: any) { return false } + +function removeEndSlashes (url: string) { + while (url.endsWith('/')) { + url.slice(0, -1) + } +} -- cgit v1.2.3 From bb8f7872f5a473c47a688b0c282ff34cd78a9835 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Jan 2019 11:01:40 +0100 Subject: Fix peertube CLI documentation --- server/tools/peertube-import-videos.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'server/tools/peertube-import-videos.ts') diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 2874a2131..f50aafc35 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -78,7 +78,11 @@ getSettings() password: program['password'] } - run(user, program['url']).catch(err => console.error(err)) + run(user, program['url']) + .catch(err => { + console.error(err) + process.exit(-1) + }) }) async function promptPassword () { @@ -112,8 +116,12 @@ async function run (user, url: string) { secret: res.body.client_secret } - const res2 = await login(url, client, user) - accessToken = res2.body.access_token + try { + const res = await login(program[ 'url' ], client, user) + accessToken = res.body.access_token + } catch (err) { + throw new Error('Cannot authenticate. Please check your username/password.') + } const youtubeDL = await safeGetYoutubeDL() -- cgit v1.2.3