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.

234 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 --output 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. ### Youtube
  49. Configuration is in **youtube_secret.json** file.
  50. Youtube uses combination of oauth and API access to identify.
  51. **Credentials**
  52. The first time you connect, prismedia will open your browser to ask you to authenticate to
  53. Youtube and allow the app to use your Youtube channel.
  54. **It is here you choose which channel you will upload to**.
  55. Once authenticated, the token is stored inside the file `.youtube_credentials.json`.
  56. Prismedia will try to use this file at each launch, and re-ask for authentication if it does not exist.
  57. **Oauth**:
  58. The default youtube_secret.json should allow you to upload some videos.
  59. If you plan a larger usage, please consider creating your own youtube_secret file:
  60. - Go to the [Google console](https://console.developers.google.com/).
  61. - Create project.
  62. - Side menu: APIs & auth -> APIs
  63. - Top menu: Enabled API(s): Enable all Youtube APIs.
  64. - Side menu: APIs & auth -> Credentials.
  65. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  66. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  67. - Save this JSON as your youtube_secret.json file.
  68. ## Usage
  69. Support only mp4 for cross compatibility between Youtube and Peertube.
  70. **Note that all options may be specified in a NFO file!** (see [Enhanced NFO](#enhanced-use-of-nfo))
  71. Here are some demonstration of main usage:
  72. Upload a video:
  73. ```sh
  74. prismedia --file="yourvideo.mp4"
  75. ```
  76. Specify description and tags:
  77. ```sh
  78. prismedia --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
  79. ```
  80. Provide a thumbnail:
  81. ```sh
  82. prismedia --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
  83. ```
  84. Publish on Peertube only, while using a channel and a playlist, creating them if they do not exist:
  85. ```sh
  86. prismedia --file="yourvideo.mp4" --platform=peertube --channel="Cooking recipes" --playlist="Cake recipes" --channelCreate --playlistCreate
  87. ```
  88. Use a NFO file to specify your video options:
  89. (See [Enhanced NFO](#enhanced-use-of-nfo) for more precise example)
  90. ```sh
  91. prismedia --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  92. ```
  93. 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).
  94. 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.
  95. On Linux and MacOS, you can use cron, on Windows the "Task Scheduler".
  96. ```sh
  97. prismedia --hearthbeat
  98. ```
  99. Take a look at all available options with `--help`!
  100. ```sh
  101. prismedia --help
  102. ```
  103. ## Enhanced use of NFO
  104. Since Prismedia v0.9.0, the NFO system has been improved to allow hierarchical loading.
  105. First, **if you already used nfo**, either with `--nfo` or by using `videoname.txt`, nothing changes :-)
  106. 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
  107. Basically, Prismedia will now load options in this order, using the last value found in case of conflict:
  108. `nfo.txt < directory_name.txt < video_name.txt < command line NFO < command line argument`
  109. You'll find a complete set of samples in the [prismedia/samples](prismedia/samples) directory so let's take it as an example:
  110. ```sh
  111. $ tree Recipes/
  112. Recipes/
  113. ├── cli_nfo.txt
  114. ├── nfo.txt
  115. ├── samples.txt
  116. ├── yourvideo1.mp4
  117. ├── yourvideo1.txt
  118. ├── yourvideo1.jpg
  119. ├── yourvideo2.mp4
  120. └── yourvideo2.txt
  121. ```
  122. By using
  123. ```sh
  124. prismedia --file=/path/to/Recipes/yourvideo1.mp4 --nfo=/path/to/Recipes/cli_nfo.txt --cca
  125. ```
  126. Prismedia will:
  127. - look for options in `nfo.txt`
  128. - look for options in `samples.txt` (from directory name) and erase any previous conflicting options
  129. - look for options in `yourvideo1.txt` (from video name) and erase any previous conflicting options
  130. - look for options in `cli_nfo.txt` (from the `--nfo` in command line) and erase any previous conflicting options
  131. - erase any previous option regarding CCA as it's specified in cli with `--cca`
  132. - take `yourvideo1.jpg` as thumbnail if no other files has been specified in previous NFO
  133. 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
  134. It allows to specify more easily default options for an entire set of video, directory, playlist and so on.
  135. ## Strict check options
  136. Since prismedia v0.10.0, a bunch of special options have been added to force the presence of parameters before uploading.
  137. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  138. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  139. tags, thumbnail, ...
  140. All strict option are optionals and are provided only to avoid errors when uploading :-)
  141. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  142. All strict options are off by default.
  143. Available strict options:
  144. - --withNFO Prevent the upload without a NFO, either specified via cli or found in the directory
  145. - --withThumbnail Prevent the upload without a thumbnail
  146. - --withName Prevent the upload if no name are found
  147. - --withDescription Prevent the upload without description
  148. - --withTags Prevent the upload without tags
  149. - --withPlaylist Prevent the upload if no playlist
  150. - --withPublishAt Prevent the upload if no schedule
  151. - --withPlatform Prevent the upload if at least one platform is not specified
  152. - --withCategory Prevent the upload if no category
  153. - --withLanguage Prevent upload if no language
  154. - --withChannel Prevent upload if no channel
  155. ## Features
  156. - [x] Youtube upload
  157. - [x] Peertube upload
  158. - Support of videos parameters (description, tags, category, licence, ...)
  159. - [x] description
  160. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  161. - [x] categories
  162. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  163. - [x] privacy (between public, unlisted or private)
  164. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  165. - [x] nsfw (Peertube only as Youtube API does not support it)
  166. - [x] set default language
  167. - [x] thumbnail
  168. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  169. - [x] add videos to playlist
  170. - [x] create playlist
  171. - [x] schedule your video with publishAt
  172. - [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.
  173. - [x] Use a config file (NFO) file to retrieve videos arguments
  174. - [x] Allow choosing peertube or youtube upload (to retry a failed upload for example)
  175. - [x] Usable on Desktop (Linux and/or Windows and/or MacOS)
  176. - [x] Different schedules on platforms to prepare preview
  177. - [x] Possibility to force the presence of upload options
  178. - [ ] 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))
  179. - [ ] A usable graphical interface
  180. ## Compatibility
  181. - If you still use python2, use the version 0.7.1 (no more updated)
  182. - If you use peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3
  183. ## Inspirations
  184. Inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)
  185. ## Contributors
  186. Thanks to: @LecygneNoir, @Zykino, @meewan, @rigelk 😘