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.

304 lines
14 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. This is the only mandatory option.
  91. --name=NAME Name of the video to upload. (default to video filename)
  92. -d, --description=STRING Description of the video. (default: default description)
  93. -t, --tags=STRING Tags for the video. comma separated.
  94. WARN: tags with punctuation (!, ', ", ?, ...)
  95. are not supported by Mastodon to be published from Peertube
  96. -c, --category=STRING Category for the videos, see below. (default: Films)
  97. --cca License should be CreativeCommon Attribution (affects Youtube upload only)
  98. -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
  99. --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
  100. --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
  101. --nfo=STRING Configure a specific nfo file to set options for the video.
  102. By default Prismedia search a .txt based on the video name and will
  103. decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
  104. See nfo_example.txt for more details
  105. --platform=STRING List of platform(s) to upload to, comma separated.
  106. Supported platforms are youtube and peertube (default is both)
  107. --language=STRING Specify the default language for video. See below for supported language. (default is English)
  108. --publishAt=DATE Publish the video at the given DATE using local server timezone.
  109. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  110. DATE should be in the future
  111. --peertubeAt=DATE
  112. --youtubeAt=DATE Override publishAt for the corresponding platform. Allow to create preview on specific platform
  113. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
  114. Supported types are jpg and jpeg.
  115. By default, prismedia search for an image based on video name followed by .jpg or .jpeg
  116. --channel=STRING Set the channel to use for the video (Peertube only)
  117. If the channel is not found, spawn an error except if --channelCreate is set.
  118. --channelCreate Create the channel if not exists. (Peertube only, default do not create)
  119. Only relevant if --channel is set.
  120. --playlist=STRING Set the playlist to use for the video.
  121. If the playlist is not found, spawn an error except if --playlistCreate is set.
  122. --playlistCreate Create the playlist if not exists. (default do not create)
  123. Only relevant if --playlist is set.
  124. -h --help Show this help.
  125. --version Show version.
  126. Logging options
  127. -q --quiet Suppress any log except Critical (alias for --log=critical).
  128. --log=STRING Log level, between debug, info, warning, error, critical. Ignored if --quiet is set (default to info)
  129. -u --url-only Display generated URL after upload directly on stdout, implies --quiet
  130. --batch Display generated URL after upload with platform information for easier parsing. Implies --quiet
  131. Be careful --batch and --url-only are mutually exclusives.
  132. --debug (Deprecated) Alias for --log=debug. Ignored if --log is set
  133. Strict options:
  134. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  135. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  136. tags, thumbnail, ...
  137. All strict option are optionals and are provided only to avoid errors when uploading :-)
  138. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  139. All strict options are off by default
  140. --withNFO Prevent the upload without a NFO, either specified via cli or found in the directory
  141. --withThumbnail Prevent the upload without a thumbnail
  142. --withName Prevent the upload if no name are found
  143. --withDescription Prevent the upload without description
  144. --withTags Prevent the upload without tags
  145. --withPlaylist Prevent the upload if no playlist
  146. --withPublishAt Prevent the upload if no schedule
  147. --withPlatform Prevent the upload if at least one platform is not specified
  148. --withCategory Prevent the upload if no category
  149. --withLanguage Prevent upload if no language
  150. --withChannel Prevent upload if no channel
  151. Categories:
  152. Category is the type of video you upload. Default is films.
  153. Here are available categories from Peertube and Youtube:
  154. music, films, vehicles,
  155. sports, travels, gaming, people,
  156. comedy, entertainment, news,
  157. how to, education, activism, science & technology,
  158. science, technology, animals
  159. Languages:
  160. Language of the video (audio track), choose one. Default is English
  161. Here are available languages from Peertube and Youtube:
  162. Arabic, English, French, German, Hindi, Italian,
  163. Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  164. ```
  165. ## Enhanced use of NFO
  166. Since Prismedia v0.9.0, the NFO system has been improved to allow hierarchical loading.
  167. First of all, **if you already used nfo**, either with `--nfo` or by using `videoname.txt`, nothing changes :-)
  168. 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
  169. Basically, Prismedia will now load options in this order, using the last value found in case of conflict:
  170. `nfo.txt < directory_name.txt < video_name.txt < command line NFO < command line argument`
  171. You'll find a complete set of samples in the [prismedia/samples](prismedia/samples) directory so let's take it as an example:
  172. ```
  173. $ tree Recipes/
  174. Recipes/
  175. ├── cli_nfo.txt
  176. ├── nfo.txt
  177. ├── samples.txt
  178. ├── yourvideo1.mp4
  179. ├── yourvideo1.txt
  180. ├── yourvideo1.jpg
  181. ├── yourvideo2.mp4
  182. └── yourvideo2.txt
  183. ```
  184. By using
  185. ```
  186. prismedia --file=/path/to/Recipes/yourvideo1.mp4 --nfo=/path/to/Recipes/cli_nfo.txt --cca
  187. ```
  188. Prismedia will:
  189. - look for options in `nfo.txt`
  190. - look for options in `samples.txt` (from directory name) and erase any previous conflicting options
  191. - look for options in `yourvideo1.txt` (from video name) and erase any previous conflicting options
  192. - look for options in `cli_nfo.txt` (from the `--nfo` in command line) and erase any previous conflicting options
  193. - erase any previous option regarding CCA as it's specified in cli with `--cca`
  194. - take `yourvideo1.jpg` as thumbnail if no other files has been specified in previous NFO
  195. 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
  196. It allows to specify more easily default options for an entire set of video, directory, playlist and so on.
  197. ## Strict check options
  198. Since prismedia v0.10.0, a bunch of special options have been added to force the presence of parameters before uploading.
  199. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  200. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  201. tags, thumbnail, ...
  202. All strict option are optionals and are provided only to avoid errors when uploading :-)
  203. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  204. All strict options are off by default.
  205. Available strict options:
  206. - --withNFO Prevent the upload without a NFO, either specified via cli or found in the directory
  207. - --withThumbnail Prevent the upload without a thumbnail
  208. - --withName Prevent the upload if no name are found
  209. - --withDescription Prevent the upload without description
  210. - --withTags Prevent the upload without tags
  211. - --withPlaylist Prevent the upload if no playlist
  212. - --withPublishAt Prevent the upload if no schedule
  213. - --withPlatform Prevent the upload if at least one platform is not specified
  214. - --withCategory Prevent the upload if no category
  215. - --withLanguage Prevent upload if no language
  216. - --withChannel Prevent upload if no channel
  217. ## Features
  218. - [x] Youtube upload
  219. - [x] Peertube upload
  220. - Support of videos parameters (description, tags, category, licence, ...)
  221. - [x] description
  222. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  223. - [x] categories
  224. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  225. - [x] privacy (between public, unlisted or private)
  226. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  227. - [x] nsfw (Peertube only as Youtube API does not support it)
  228. - [x] set default language
  229. - [x] thumbnail
  230. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  231. - [x] add videos to playlist
  232. - [x] create playlist
  233. - [x] schedule your video with publishAt
  234. - [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.
  235. - [x] Use a config file (NFO) file to retrieve videos arguments
  236. - [x] Allow choosing peertube or youtube upload (to retry a failed upload for example)
  237. - [x] Usable on Desktop (Linux and/or Windows and/or MacOS)
  238. - [x] Different schedules on platforms to prepare preview
  239. - [x] Possibility to force the presence of upload options
  240. - [ ] 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))
  241. - [ ] A usable graphical interface
  242. ## Compatibility
  243. - If you still use python2, use the version 0.7.1 (no more updated)
  244. - If you use peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3
  245. ## Inspirations
  246. Inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)
  247. ## Contributors
  248. Thanks to: @Zykino, @meewan, @rigelk 😘