From 35501c0fa7be9cb71e992c37e06f3cd01afc510b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 19 Feb 2018 11:12:58 +0100 Subject: [PATCH] Add ability to import just one video from youtube --- README.md | 8 ++++++-- server/tools/import-youtube.ts | 12 +++++++++--- support/doc/dependencies.md | 4 ++-- support/doc/import-youtube.md | 24 ++++++++++++++---------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f3a754d54..5ff05fcb8 100644 --- a/README.md +++ b/README.md @@ -147,11 +147,11 @@ See the [docker guide](/support/doc/docker.md) See the [production guide](/support/doc/production.md). -## Contributing +## Contributing/Test See the [contributing guide](/.github/CONTRIBUTING.md) -to see how to contribute to PeerTube. Spoiler alert: you don't need to be a +to see how to test or contribute to PeerTube. Spoiler alert: you don't need to be a coder to help! ## API REST documentation @@ -161,6 +161,10 @@ For now only on Github: * HTML version: [/support/doc/api/html/index.html](/support/doc/api/html/index.html) * Swagger/OpenAPI schema: [/support/doc/api/openapi.yaml](/support/doc/api/openapi.yaml) +## Tools + + * [YouTube import](/support/doc/import-youtube.md) + ## Architecture See [ARCHITECTURE.md](/ARCHITECTURE.md) for a more detailed explanation. diff --git a/server/tools/import-youtube.ts b/server/tools/import-youtube.ts index 68893306f..e51a66e5f 100644 --- a/server/tools/import-youtube.ts +++ b/server/tools/import-youtube.ts @@ -52,10 +52,16 @@ async function run () { youtubeDL.getInfo(program['youtubeUrl'], options, processOptions, async (err, info) => { if (err) throw err - // Normalize utf8 fields - info = info.map(i => normalizeObject(i)) + let infoArray: any[] - const videos = info.map(i => { + // Normalize utf8 fields + if (Array.isArray(info) === true) { + infoArray = info.map(i => normalizeObject(i)) + } else { + infoArray = [ normalizeObject(info) ] + } + + const videos = infoArray.map(i => { return { url: 'https://www.youtube.com/watch?v=' + i.id, name: i.title } }) diff --git a/support/doc/dependencies.md b/support/doc/dependencies.md index a4a30374c..4ced42b8b 100644 --- a/support/doc/dependencies.md +++ b/support/doc/dependencies.md @@ -10,7 +10,7 @@ ``` $ sudo apt update -$ sudo apt install nginx ffmpeg postgresql openssl g++ make redis-server git +$ sudo apt install nginx ffmpeg postgresql openssl g++ make redis-server ``` ## Arch Linux @@ -36,7 +36,7 @@ $ sudo pacman -S nodejs yarn ffmpeg postgresql openssl redis $ sudo yum update $ sudo yum install epel-release $ sudo yum update -$ sudo yum install nginx postgresql postgresql-server openssl gcc make redis git +$ sudo yum install nginx postgresql postgresql-server openssl gcc make redis ``` ## Other distributions diff --git a/support/doc/import-youtube.md b/support/doc/import-youtube.md index 3b8b515a7..39f01b85b 100644 --- a/support/doc/import-youtube.md +++ b/support/doc/import-youtube.md @@ -11,19 +11,20 @@ Be sure you own the videos or have the author's authorization to do so. ## Prerequisites You need at least 512MB RAM to run the script. -Importation can be launched directly from a peertube server (in this case you already have dependencies installed :+1:) or from a separate server, even a dekstop PC. +Importation can be launched directly from a PeerTube server (in this case you already have dependencies installed :+1:) or from a separate server, even a dekstop PC. ### Dependencies -If you do not run the script from a Peertube server, you need to follow the steps of the [dependencies guide](dependencies.md). + * [PeerTube dependencies](dependencies.md) + * git ### Installation -Clone the Peertube repo to get the latest version inside your server: +Clone the PeerTube repo to get the latest version: ``` git clone https://github.com/Chocobozzz/PeerTube.git -CLONE="$(pwd)/Peertube" +CLONE="$(pwd)/PeerTube" ``` Run ``yarn install`` @@ -48,10 +49,13 @@ cd ${CLONE} node dist/server/tools/import-youtube.js -u "PEERTUBE_URL" -U "PEERTUBE_USER" --password "PEERTUBE_PASSWORD" -y "YOUTUBE_URL" ``` - - PEERTUBE_URL : the full URL of your peertube server where you want to import, eg: https://peertube.cpy.re/ - - PEERTUBE_USER : your peertube account where videos will be uploaded - - PEERTUBE_PASSWORD : password of your peertube account - - YOUTUBE_URL : the youtube channel you want to import. Supports Youtube channel (eg https://www.youtube.com/channel/ChannelId) or Youtube user (eg: https://www.youtube.com/c/UserName or https://www.youtube.com/user/UserName) + * PEERTUBE_URL : the full URL of your PeerTube server where you want to import, eg: https://peertube.cpy.re/ + * PEERTUBE_USER : your PeerTube account where videos will be uploaded + * PEERTUBE_PASSWORD : password of your PeerTube account + * YOUTUBE_URL : the youtube video/user/channel/playlist you want to import. Examples: + * Channel: https://www.youtube.com/channel/ChannelId + * User https://www.youtube.com/c/UserName or https://www.youtube.com/user/UserName + * Video https://www.youtube.com/watch?v=blabla - The script will get all public videos from Youtube, download them, then upload to Peertube. - Already downloaded videos will not be uploaded twice, so you can run and re-run the script in case of crash, disconnection, ... without problem. \ No newline at end of file + The script will get all public videos from Youtube, download them and upload to PeerTube. + Already downloaded videos will not be uploaded twice, so you can run and re-run the script in case of crash, disconnection...