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.

276 lines
12 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. ```bash
  22. pip install prismedia
  23. ```
  24. Upgrade with
  25. ```bash
  26. pip install --upgrade prismedia
  27. ```
  28. ### From source
  29. Get the source:
  30. ```bash
  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. ```
  38. poetry install
  39. ```
  40. ## Configuration
  41. Generate sample files with `python -m prismedia.genconfig`.
  42. Then rename and edit `peertube_secret` and `youtube_secret.json` with your credentials. (see below)
  43. ### Peertube
  44. Set your credentials, peertube server URL.
  45. You can get client_id and client_secret by logging in your peertube website and reaching the URL:
  46. https://domain.example/api/v1/oauth-clients/local
  47. You can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)
  48. ### Youtube
  49. Youtube uses combination of oauth and API access to identify.
  50. **Credentials**
  51. The first time you connect, prismedia will open your browser to ask you to authenticate to
  52. Youtube and allow the app to use your Youtube channel.
  53. **It is here you choose which channel you will upload to**.
  54. Once authenticated, the token is stored inside the file ``.youtube_credentials.json``.
  55. Prismedia will try to use this file at each launch, and re-ask for authentication if it does not exist.
  56. **Oauth**:
  57. The default youtube_secret.json should allow you to upload some videos.
  58. If you plan a larger usage, please consider creating your own youtube_secret file:
  59. - Go to the [Google console](https://console.developers.google.com/).
  60. - Create project.
  61. - Side menu: APIs & auth -> APIs
  62. - Top menu: Enabled API(s): Enable all Youtube APIs.
  63. - Side menu: APIs & auth -> Credentials.
  64. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  65. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  66. - Save this JSON as your youtube_secret.json file.
  67. ## Usage
  68. Support only mp4 for cross compatibility between Youtube and Peertube.
  69. **Note that all options may be specified in a NFO file!** (see [Enhanced NFO](#enhanced-use-of-nfo))
  70. Upload a video:
  71. ```
  72. prismedia --file="yourvideo.mp4"
  73. ```
  74. Specify description and tags:
  75. ```
  76. prismedia --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
  77. ```
  78. Provide a thumbnail:
  79. ```
  80. prismedia --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
  81. ```
  82. Use a NFO file to specify your video options:
  83. (See [Enhanced NFO](#enhanced-use-of-nfo) for more precise example)
  84. ```
  85. prismedia --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  86. ```
  87. Use --help to get all available options:
  88. ```
  89. Options:
  90. -f, --file=STRING Path to the video file to upload in mp4
  91. --name=NAME Name of the video to upload. (default to video filename)
  92. --debug Trigger some debug information like options used (default: no)
  93. -d, --description=STRING Description of the video. (default: default description)
  94. -t, --tags=STRING Tags for the video. comma separated.
  95. WARN: tags with punctuation (!, ', ", ?, ...)
  96. are not supported by Mastodon to be published from Peertube
  97. -c, --category=STRING Category for the videos, see below. (default: Films)
  98. --cca License should be CreativeCommon Attribution (affects Youtube upload only)
  99. -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
  100. --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
  101. --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
  102. --nfo=STRING Configure a specific nfo file to set options for the video.
  103. By default Prismedia search a .txt based on the video name and will
  104. decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
  105. See nfo_example.txt for more details
  106. --platform=STRING List of platform(s) to upload to, comma separated.
  107. Supported platforms are youtube and peertube (default is both)
  108. --language=STRING Specify the default language for video. See below for supported language. (default is English)
  109. --publishAt=DATE Publish the video at the given DATE using local server timezone.
  110. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  111. DATE should be in the future
  112. --peertubeAt=DATE
  113. --youtubeAt=DATE Override publishAt for the corresponding platform. Allow to create preview on specific platform
  114. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
  115. Supported types are jpg and jpeg.
  116. By default, prismedia search for an image based on video name followed by .jpg or .jpeg
  117. --channel=STRING Set the channel to use for the video (Peertube only)
  118. If the channel is not found, spawn an error except if --channelCreate is set.
  119. --channelCreate Create the channel if not exists. (Peertube only, default do not create)
  120. Only relevant if --channel is set.
  121. --playlist=STRING Set the playlist to use for the video.
  122. If the playlist is not found, spawn an error except if --playlistCreate is set.
  123. --playlistCreate Create the playlist if not exists. (default do not create)
  124. Only relevant if --playlist is set.
  125. -h --help Show this help.
  126. --version Show version.
  127. Categories:
  128. Category is the type of video you upload. Default is films.
  129. Here are available categories from Peertube and Youtube:
  130. music, films, vehicles,
  131. sports, travels, gaming, people,
  132. comedy, entertainment, news,
  133. how to, education, activism, science & technology,
  134. science, technology, animals
  135. Languages:
  136. Language of the video (audio track), choose one. Default is English
  137. Here are available languages from Peertube and Youtube:
  138. Arabic, English, French, German, Hindi, Italian,
  139. Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  140. ```
  141. ## Enhanced use of NFO
  142. Since Prismedia v0.9.0, the NFO system has been improved to allow hierarchical loading.
  143. First of all, **if you already used nfo**, either with `--nfo` or by using `videoname.txt`, nothing changes :-)
  144. But you are now able to use a more flexible NFO system, by using priorities. This allow you to set some defaults to avoid recreating a full nfo for each video
  145. Basically, Prismedia will now load options in this order, using the last value found in case of conflict:
  146. `nfo.txt < directory_name.txt < video_name.txt < command line NFO < command line argument`
  147. You'll find a complete set of samples in the [prismedia/samples](prismedia/samples) directory so let's take it as an example:
  148. ```
  149. $ tree Recipes/
  150. Recipes/
  151. ├── cli_nfo.txt
  152. ├── nfo.txt
  153. ├── samples.txt
  154. ├── yourvideo1.mp4
  155. ├── yourvideo1.txt
  156. ├── yourvideo1.jpg
  157. ├── yourvideo2.mp4
  158. └── yourvideo2.txt
  159. ```
  160. By using
  161. ```
  162. prismedia --file=/path/to/Recipes/yourvideo1.mp4 --nfo=/path/to/Recipes/cli_nfo.txt --cca
  163. ```
  164. Prismedia will:
  165. - look for options in `nfo.txt`
  166. - look for options in `samples.txt` (from directory name) and erase any previous conflicting options
  167. - look for options in `yourvideo1.txt` (from video name) and erase any previous conflicting options
  168. - look for options in `cli_nfo.txt` (from the `--nfo` in command line) and erase any previous conflicting options
  169. - erase any previous option regarding CCA as it's specified in cli with `--cca`
  170. - take `yourvideo1.jpg` as thumbnail if no other files has been specified in previous NFO
  171. In other word, Prismedia will now 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
  172. It allows to specify more easily default options for an entire set of video, directory, playlist and so on.
  173. ## Strict check options
  174. Since prismedia v0.10.0, a bunch of special options have been added to force the presence of parameters before uploading.
  175. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  176. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  177. tags, thumbnail, ...
  178. All strict option are optionals and are provided only to avoid errors when uploading :-)
  179. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  180. All strict options are off by default.
  181. Available strict options:
  182. - --withNFO Prevent the upload without a NFO, either specified via cli or found in the directory
  183. - --withThumbnail Prevent the upload without a thumbnail
  184. - --withName Prevent the upload if no name are found
  185. - --withDescription Prevent the upload without description
  186. - --withTags Prevent the upload without tags
  187. - --withPlaylist Prevent the upload if no playlist
  188. - --withPublishAt Prevent the upload if no schedule
  189. - --withPlatform Prevent the upload if at least one platform is not specified
  190. - --withCategory Prevent the upload if no category
  191. - --withLanguage Prevent upload if no language
  192. - --withChannel Prevent upload if no channel
  193. ## Features
  194. - [x] Youtube upload
  195. - [x] Peertube upload
  196. - Support of videos parameters (description, tags, category, licence, ...)
  197. - [x] description
  198. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  199. - [x] categories
  200. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  201. - [x] privacy (between public, unlisted or private)
  202. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  203. - [x] nsfw (Peertube only as Youtube API does not support it)
  204. - [x] set default language
  205. - [x] thumbnail
  206. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  207. - [x] add videos to playlist
  208. - [x] create playlist
  209. - [x] schedule your video with publishAt
  210. - [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.
  211. - [x] Use a config file (NFO) file to retrieve videos arguments
  212. - [x] Allow choosing peertube or youtube upload (to retry a failed upload for example)
  213. - [x] Usable on Desktop (Linux and/or Windows and/or MacOS)
  214. - [x] Different schedules on platforms to prepare preview
  215. - [x] Possibility to force the presence of upload options
  216. - [ ] Copy and forget, eg possibility to copy video in a directory, and prismedia uploads itself (Discussions in [issue 27](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/27))
  217. - [ ] A usable graphical interface
  218. ## Compatibility
  219. - If you still use python2, use the version 0.7.1 (no more updated)
  220. - If you use peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3
  221. ## Inspirations
  222. Inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)
  223. ## Contributors
  224. Thanks to: @Zykino, @meewan, @rigelk 😘