Scripting way to upload videos to peertube and youtube
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
9.5 KiB

6 years ago
6 years ago
  1. # Prismedia
  2. Scripting your way to upload videos to peertube and youtube. Works with Python 3.5+.
  3. [TOC]: #
  4. ## Table of Contents
  5. - [Installation](#installation-and-upgrade)
  6. - [From pip](#from-pip)
  7. - [From source](#from-source)
  8. - [Configuration](#configuration)
  9. - [Peertube](#peertube)
  10. - [Youtube](#youtube)
  11. - [Usage](#usage)
  12. - [Enhanced use of NFO](#enhanced-use-of-nfo)
  13. - [Strict check options](#strict-check-options)
  14. - [Features](#features)
  15. - [Compatibility](#compatibility)
  16. - [Inspirations](#inspirations)
  17. - [Contributors](#contributors)
  18. ## Installation and upgrade
  19. ### From pip
  20. Simply install with
  21. ```sh
  22. pip install prismedia
  23. ```
  24. Upgrade with
  25. ```sh
  26. pip install --upgrade prismedia
  27. ```
  28. ### From source
  29. Get the source:
  30. ```sh
  31. git clone https://git.lecygnenoir.info/LecygneNoir/prismedia.git prismedia
  32. ```
  33. You may use pip to install requirements: `pip install -r requirements.txt` if you want to use the script directly.
  34. (**note:** requirements are generated via `poetry export -f requirements.txt`)
  35. Otherwise, you can use [poetry](https://python-poetry.org), which create a virtualenv for the project directly
  36. (Or use the existing virtualenv if one is activated)
  37. ```sh
  38. poetry install
  39. ```
  40. ## Configuration
  41. Generate configuration files by running `prismedia-init`.
  42. Then, edit them to fill your credential as explained below.
  43. ### Peertube
  44. Configuration is in **peertube_secret** file.
  45. You need your usual credentials and Peertube instance URL, in addition with API client_id and client_secret.
  46. You can get client_id and client_secret by logging in your peertube instance and reaching the URL:
  47. https://domain.example/api/v1/oauth-clients/local
  48. *Alternatively, you can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)*
  49. ### Youtube
  50. Configuration is in **youtube_secret.json** file.
  51. Youtube uses combination of oauth and API access to identify.
  52. **Credentials**
  53. The first time you connect, prismedia will open your browser to ask you to authenticate to
  54. Youtube and allow the app to use your Youtube channel.
  55. **It is here you choose which channel you will upload to**.
  56. Once authenticated, the token is stored inside the file `.youtube_credentials.json`.
  57. Prismedia will try to use this file at each launch, and re-ask for authentication if it does not exist.
  58. **Oauth**:
  59. The default youtube_secret.json should allow you to upload some videos.
  60. If you plan a larger usage, please consider creating your own youtube_secret file:
  61. - Go to the [Google console](https://console.developers.google.com/).
  62. - Create project.
  63. - Side menu: APIs & auth -> APIs
  64. - Top menu: Enabled API(s): Enable all Youtube APIs.
  65. - Side menu: APIs & auth -> Credentials.
  66. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  67. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  68. - Save this JSON as your youtube_secret.json file.
  69. ## Usage
  70. Support only mp4 for cross compatibility between Youtube and Peertube.
  71. **Note that all options may be specified in a NFO file!** (see [Enhanced NFO](#enhanced-use-of-nfo))
  72. Here are some demonstration of main usage:
  73. Upload a video:
  74. ```sh
  75. prismedia --file="yourvideo.mp4"
  76. ```
  77. Specify description and tags:
  78. ```sh
  79. prismedia --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
  80. ```
  81. Provide a thumbnail:
  82. ```sh
  83. prismedia --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
  84. ```
  85. Publish on Peertube only, while using a channel and a playlist, creating them if they do not exist:
  86. ```sh
  87. prismedia --file="yourvideo.mp4" --platform=peertube --channel="Cooking recipes" --playlist="Cake recipes" --channelCreate --playlistCreate
  88. ```
  89. Use a NFO file to specify your video options:
  90. (See [Enhanced NFO](#enhanced-use-of-nfo) for more precise example)
  91. ```sh
  92. prismedia --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  93. ```
  94. Use some credits to show some activity for you apikey so the platform know it is used and would not put your quota to 0 (only Youtube currently).
  95. To prevent Youtube from inactivating your apikey after 90days of inactivity it is recommended to launch this command automatically from a script around once a month. It will mwke a call to use a few credits from your daily quota.
  96. On Linux and MacOS, you can use cron, on Windows the "Task Scheduler".
  97. ```sh
  98. prismedia --hearthbeat
  99. ```
  100. Take a look at all available options with `--help`!
  101. ```sh
  102. prismedia --help
  103. ```
  104. ## Enhanced use of NFO
  105. Since Prismedia v0.9.0, the NFO system has been improved to allow hierarchical loading.
  106. First, **if you already used nfo**, either with `--nfo` or by using `videoname.txt`, nothing changes :-)
  107. But you are now able to use a more flexible NFO system, by using priorities. This allows you to set some defaults to avoid recreating a full nfo for each video
  108. Basically, Prismedia will now load options in this order, using the last value found in case of conflict:
  109. `nfo.txt < directory_name.txt < video_name.txt < command line NFO < command line argument`
  110. You'll find a complete set of samples in the [prismedia/samples](prismedia/samples) directory so let's take it as an example:
  111. ```sh
  112. $ tree Recipes/
  113. Recipes/
  114. ├── cli_nfo.txt
  115. ├── nfo.txt
  116. ├── samples.txt
  117. ├── yourvideo1.mp4
  118. ├── yourvideo1.txt
  119. ├── yourvideo1.jpg
  120. ├── yourvideo2.mp4
  121. └── yourvideo2.txt
  122. ```
  123. By using
  124. ```sh
  125. prismedia --file=/path/to/Recipes/yourvideo1.mp4 --nfo=/path/to/Recipes/cli_nfo.txt --cca
  126. ```
  127. Prismedia will:
  128. - look for options in `nfo.txt`
  129. - look for options in `samples.txt` (from directory name) and erase any previous conflicting options
  130. - look for options in `yourvideo1.txt` (from video name) and erase any previous conflicting options
  131. - look for options in `cli_nfo.txt` (from the `--nfo` in command line) and erase any previous conflicting options
  132. - erase any previous option regarding CCA as it's specified in cli with `--cca`
  133. - take `yourvideo1.jpg` as thumbnail if no other files has been specified in previous NFO
  134. In other word, Prismedia will use option given in cli, then look for option in cli_nfo.txt, then complete with video_name.txt, then directory_name.txt, and finally complete with nfo.txt
  135. It allows to specify more easily default options for an entire set of video, directory, playlist and so on.
  136. ## Strict check options
  137. Since prismedia v0.10.0, a bunch of special options have been added to force the presence of parameters before uploading.
  138. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  139. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  140. tags, thumbnail, ...
  141. All strict option are optionals and are provided only to avoid errors when uploading :-)
  142. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  143. All strict options are off by default.
  144. Available strict options:
  145. - --withNFO Prevent the upload without a NFO, either specified via cli or found in the directory
  146. - --withThumbnail Prevent the upload without a thumbnail
  147. - --withName Prevent the upload if no name are found
  148. - --withDescription Prevent the upload without description
  149. - --withTags Prevent the upload without tags
  150. - --withPlaylist Prevent the upload if no playlist
  151. - --withPublishAt Prevent the upload if no schedule
  152. - --withPlatform Prevent the upload if at least one platform is not specified
  153. - --withCategory Prevent the upload if no category
  154. - --withLanguage Prevent upload if no language
  155. - --withChannel Prevent upload if no channel
  156. ## Features
  157. - [x] Youtube upload
  158. - [x] Peertube upload
  159. - Support of videos parameters (description, tags, category, licence, ...)
  160. - [x] description
  161. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  162. - [x] categories
  163. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  164. - [x] privacy (between public, unlisted or private)
  165. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  166. - [x] nsfw (Peertube only as Youtube API does not support it)
  167. - [x] set default language
  168. - [x] thumbnail
  169. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  170. - [x] add videos to playlist
  171. - [x] create playlist
  172. - [x] schedule your video with publishAt
  173. - [x] combine channel and playlist (Peertube only as channel is Peertube feature). See [issue 40](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/40) for detailed usage.
  174. - [x] Use a config file (NFO) file to retrieve videos arguments
  175. - [x] Allow choosing peertube or youtube upload (to retry a failed upload for example)
  176. - [x] Usable on Desktop (Linux and/or Windows and/or MacOS)
  177. - [x] Different schedules on platforms to prepare preview
  178. - [x] Possibility to force the presence of upload options
  179. - [ ] Copy and forget, eg possibility to copy video in a directory, and prismedia uploads itself: [Work in progress](https://git.lecygnenoir.info/Zykino/prismedia-autoupload) thanks to @Zykino 🎉 (Discussions in [issue 27](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/27))
  180. - [ ] A usable graphical interface
  181. ## Compatibility
  182. - If you still use python2, use the version 0.7.1 (no more updated)
  183. - If you use peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3
  184. ## Inspirations
  185. Inspired by peeror (First peertube mirror by Rigelk) and [youtube-upload](https://github.com/tokland/youtube-upload)
  186. ## Contributors
  187. Thanks to: @LecygneNoir, @Zykino, @meewan, @rigelk 😘