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.

251 lines
10 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)
  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. - [Features](#features)
  14. - [Compatibility](#compatibility)
  15. - [Sources](#sources)
  16. - [Contributors](#contributors)
  17. ## Installation an upgrade
  18. ### From pip
  19. Simply install with
  20. ```bash
  21. pip install prismedia
  22. ```
  23. Upgrade with
  24. ```bash
  25. pip install --upgrade prismedia
  26. ```
  27. ### From source
  28. Get the source:
  29. ```bash
  30. git clone https://git.lecygnenoir.info/LecygneNoir/prismedia.git prismedia
  31. ```
  32. You may use pip to install requirements: `pip install -r requirements.txt` if you want to use the script directly.
  33. (*note:* requirements are generated via `poetry export -f requirements.txt`)
  34. Otherwise, you can use [poetry](https://python-poetry.org), which create a virtualenv for the project directly
  35. (Or use the existing virtualenv if one is activated)
  36. ```
  37. poetry install
  38. ```
  39. ## Configuration
  40. Generate sample files with `python -m prismedia.genconfig`.
  41. Then rename and edit `peertube_secret` and `youtube_secret.json` with your credentials. (see below)
  42. ### Peertube
  43. Set your credentials, peertube server URL.
  44. You can get client_id and client_secret by logging in your peertube website and reaching the URL:
  45. https://domain.example/api/v1/oauth-clients/local
  46. You can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)
  47. ### Youtube
  48. Youtube uses combination of oauth and API access to identify.
  49. **Credentials**
  50. The first time you connect, prismedia will open your browser to ask you to authenticate to
  51. Youtube and allow the app to use your Youtube channel.
  52. **It is here you choose which channel you will upload to**.
  53. Once authenticated, the token is stored inside the file ``.youtube_credentials.json``.
  54. Prismedia will try to use this file at each launch, and re-ask for authentication if it does not exist.
  55. **Oauth**:
  56. The default youtube_secret.json should allow you to upload some videos.
  57. If you plan a larger usage, please consider creating your own youtube_secret file:
  58. - Go to the [Google console](https://console.developers.google.com/).
  59. - Create project.
  60. - Side menu: APIs & auth -> APIs
  61. - Top menu: Enabled API(s): Enable all Youtube APIs.
  62. - Side menu: APIs & auth -> Credentials.
  63. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  64. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  65. - Save this JSON as your youtube_secret.json file.
  66. ## Usage
  67. Support only mp4 for cross compatibility between Youtube and Peertube.
  68. **Note that all options may be specified in a NFO file!** (see [Enhanced NFO](#enhanced-use-of-nfo))
  69. Upload a video:
  70. ```
  71. prismedia --file="yourvideo.mp4"
  72. ```
  73. Specify description and tags:
  74. ```
  75. prismedia --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
  76. ```
  77. Provide a thumbnail:
  78. ```
  79. prismedia --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
  80. ```
  81. Use a NFO file to specify your video options:
  82. (See [Enhanced NFO](#enhanced-use-of-nfo) for more precise example)
  83. ```
  84. prismedia --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  85. ```
  86. Use --help to get all available options:
  87. ```
  88. Options:
  89. -f, --file=STRING Path to the video file to upload in mp4
  90. --name=NAME Name of the video to upload. (default to video filename)
  91. --debug Trigger some debug information like options used (default: no)
  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. Categories:
  127. Category is the type of video you upload. Default is films.
  128. Here are available categories from Peertube and Youtube:
  129. music, films, vehicles,
  130. sports, travels, gaming, people,
  131. comedy, entertainment, news,
  132. how to, education, activism, science & technology,
  133. science, technology, animals
  134. Languages:
  135. Language of the video (audio track), choose one. Default is English
  136. Here are available languages from Peertube and Youtube:
  137. Arabic, English, French, German, Hindi, Italian,
  138. Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  139. ```
  140. ## Enhanced use of NFO
  141. Since Prismedia v0.9.0, the NFO system has been improved to allow hierarchical loading.
  142. First of all, **if you already used nfo**, either with `--nfo` or by using `videoname.txt`, nothing changes :-)
  143. 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
  144. Basically, Prismedia will now load options in this order, using the last value found in case of conflict:
  145. `nfo.txt < directory_name.txt < video_name.txt < command line NFO < command line argument`
  146. You'll find a complete set of samples in the [prismedia/samples](prismedia/samples) directory so let's take it as an example:
  147. ```
  148. $ tree Recipes/
  149. Recipes/
  150. ├── cli_nfo.txt
  151. ├── nfo.txt
  152. ├── samples.txt
  153. ├── yourvideo1.mp4
  154. ├── yourvideo1.txt
  155. ├── yourvideo1.jpg
  156. ├── yourvideo2.mp4
  157. └── yourvideo2.txt
  158. ```
  159. By using
  160. ```
  161. prismedia --file=/path/to/Recipes/yourvideo1.mp4 --nfo=/path/to/Recipes/cli_nfo.txt --cca
  162. ```
  163. Prismedia will:
  164. - look for options in `nfo.txt`
  165. - look for options in `samples.txt` (from directory name) and erase any previous conflicting options
  166. - look for options in `yourvideo1.txt` (from video name) and erase any previous conflicting options
  167. - look for options in `cli_nfo.txt` (from the `--nfo` in command line) and erase any previous conflicting options
  168. - erase any previous option regarding CCA as it's specified in cli with `--cca`
  169. - take `yourvideo1.jpg` as thumbnail if no other files has been specified in previous NFO
  170. 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
  171. It allows to specify more easily default options for an entire set of video, directory, playlist and so on.
  172. ## Features
  173. - [x] Youtube upload
  174. - [x] Peertube upload
  175. - Support of videos parameters (description, tags, category, licence, ...)
  176. - [x] description
  177. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  178. - [x] categories
  179. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  180. - [x] privacy (between public, unlisted or private)
  181. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  182. - [x] nsfw (Peertube only as Youtube API does not support it)
  183. - [x] set default language
  184. - [x] thumbnail
  185. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  186. - [x] add videos to playlist
  187. - [x] create playlist
  188. - [x] schedule your video with publishAt
  189. - [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.
  190. - [x] Use a config file (NFO) file to retrieve videos arguments
  191. - [x] Allow to choose peertube or youtube upload (to resume failed upload for example)
  192. - [x] Usable on Desktop (Linux and/or Windows and/or MacOS)
  193. - [x] Different schedules on platforms to prepare preview
  194. - [ ] A usable graphical interface
  195. ## Compatibility
  196. - If you still use python2, use the version 0.7.1 (no more updated)
  197. - If you use peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3
  198. ## Sources
  199. inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)
  200. ## Contributors
  201. Thanks to: @Zykino, @meewan, @rigelk 😘