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.

225 lines
9.7 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. - [Configuration](#configuration)
  7. - [Peertube](#peertube)
  8. - [Youtube](#youtube)
  9. - [Usage](#usage)
  10. - [Enhanced use of NFO](#enhanced-use-of-nfo)
  11. - [Features](#features)
  12. - [Compatibility](#compatibility)
  13. - [Sources](#sources)
  14. - [Contributors](#contributors)
  15. ## Installation
  16. You may use pip to install requirements: `pip install -r requirements.txt`
  17. (*note:* requirements are generated via `poetry export -f requirements.txt`)
  18. Otherwise, you can use [poetry](https://python-poetry.org):
  19. ```
  20. poetry install # installs the dependency in the current virtualenv,
  21. or creates one specific to the project if no virtualenv is currently active
  22. ```
  23. ## Configuration
  24. Generate sample files with `python -m prismedia.genconfig`.
  25. Then edit `peertube_secret` and `youtube_secret.json` with your credentials. (see below)
  26. ### Peertube
  27. Set your credentials, peertube server URL.
  28. You can get client_id and client_secret by logging in your peertube website and reaching the URL:
  29. https://domain.example/api/v1/oauth-clients/local
  30. You can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)
  31. ### Youtube
  32. Youtube uses combination of oauth and API access to identify.
  33. **Credentials**
  34. The first time you connect, prismedia will open your browser to as you to authenticate to
  35. Youtube and allow the app to use your Youtube channel.
  36. **It is here you choose which channel you will upload to**.
  37. Once authenticated, the token is stored inside the file ``.youtube_credentials.json``.
  38. Prismedia will try to use this file at each launch, and re-ask for authentication if it does not exist.
  39. **Oauth**:
  40. The default youtube_secret.json should allow you to upload some videos.
  41. If you plan an larger usage, please consider creating your own youtube_secret file:
  42. - Go to the [Google console](https://console.developers.google.com/).
  43. - Create project.
  44. - Side menu: APIs & auth -> APIs
  45. - Top menu: Enabled API(s): Enable all Youtube APIs.
  46. - Side menu: APIs & auth -> Credentials.
  47. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  48. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  49. - Save this JSON as your youtube_secret.json file.
  50. ## Usage
  51. Support only mp4 for cross compatibility between Youtube and Peertube
  52. Upload a video:
  53. ```
  54. python -m prismedia --file="yourvideo.mp4"
  55. ```
  56. Specify description and tags:
  57. ```
  58. python -m prismedia --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
  59. ```
  60. Provide a thumbnail:
  61. ```
  62. python -m prismedia --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
  63. ```
  64. Use a NFO file to specify your video options:
  65. (See nfo_example.txt for more precise example)
  66. ```
  67. python -m prismedia --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  68. ```
  69. Use --help to get all available options:
  70. ```
  71. Options:
  72. -f, --file=STRING Path to the video file to upload in mp4
  73. --name=NAME Name of the video to upload. (default to video filename)
  74. --debug Trigger some debug information like options used (default: no)
  75. -d, --description=STRING Description of the video. (default: default description)
  76. -t, --tags=STRING Tags for the video. comma separated.
  77. WARN: tags with punctuation (!, ', ", ?, ...)
  78. are not supported by Mastodon to be published from Peertube
  79. -c, --category=STRING Category for the videos, see below. (default: Films)
  80. --cca License should be CreativeCommon Attribution (affects Youtube upload only)
  81. -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
  82. --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
  83. --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
  84. --nfo=STRING Configure a specific nfo file to set options for the video.
  85. By default Prismedia search a .txt based on the video name and will
  86. decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
  87. See nfo_example.txt for more details
  88. --platform=STRING List of platform(s) to upload to, comma separated.
  89. Supported platforms are youtube and peertube (default is both)
  90. --language=STRING Specify the default language for video. See below for supported language. (default is English)
  91. --publishAt=DATE Publish the video at the given DATE using local server timezone.
  92. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  93. DATE should be in the future
  94. --peertubeAt=DATE
  95. --youtubeAt=DATE Override publishAt for the corresponding platform. Allow to create preview on specific platform
  96. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
  97. Supported types are jpg and jpeg.
  98. By default, prismedia search for an image based on video name followed by .jpg or .jpeg
  99. --channel=STRING Set the channel to use for the video (Peertube only)
  100. If the channel is not found, spawn an error except if --channelCreate is set.
  101. --channelCreate Create the channel if not exists. (Peertube only, default do not create)
  102. Only relevant if --channel is set.
  103. --playlist=STRING Set the playlist to use for the video.
  104. If the playlist is not found, spawn an error except if --playlistCreate is set.
  105. --playlistCreate Create the playlist if not exists. (default do not create)
  106. Only relevant if --playlist is set.
  107. -h --help Show this help.
  108. --version Show version.
  109. Categories:
  110. Category is the type of video you upload. Default is films.
  111. Here are available categories from Peertube and Youtube:
  112. music, films, vehicles,
  113. sports, travels, gaming, people,
  114. comedy, entertainment, news,
  115. how to, education, activism, science & technology,
  116. science, technology, animals
  117. Languages:
  118. Language of the video (audio track), choose one. Default is English
  119. Here are available languages from Peertube and Youtube:
  120. Arabic, English, French, German, Hindi, Italian,
  121. Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  122. ```
  123. ## Enhanced use of NFO
  124. Since Prismedia v0.9.0, the NFO system has been improved to allow hierarchical loading.
  125. First of all, **if you already used nfo**, either with `--nfo` or by using `videoname.txt`, nothing changes :-)
  126. 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
  127. Basically, Prismedia will now load options in this order, using the last value found in case of conflict:
  128. `nfo.txt < directory_name.txt < video_name.txt < command line NFO < command line argument`
  129. You'll find a complete set of samples in the [prismedia/samples](prismedia/samples) directory so let's take it as an example:
  130. ```
  131. $ tree Recipes/
  132. Recipes/
  133. ├── cli_nfo.txt
  134. ├── nfo.txt
  135. ├── samples.txt
  136. ├── yourvideo1.mp4
  137. ├── yourvideo1.txt
  138. ├── yourvideo1.jpg
  139. ├── yourvideo2.mp4
  140. └── yourvideo2.txt
  141. ```
  142. By using
  143. ```
  144. prismedia --file=/path/to/Recipes/yourvideo1.mp4 --nfo=/path/to/Recipes/cli_nfo.txt --cca
  145. ```
  146. Prismedia will:
  147. - look for options in `nfo.txt`
  148. - look for options in `samples.txt` (from directory name) and erase any previous conflicting options
  149. - look for options in `yourvideo1.txt` (from video name) and erase any previous conflicting options
  150. - look for options in `cli_nfo.txt` (from the `--nfo` in command line) and erase any previous conflicting options
  151. - erase any previous option regarding CCA as it's specified in cli with `--cca`
  152. - take `yourvideo1.jpg` as thumbnail if no other files has been specified in previous NFO
  153. 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
  154. It allows to specify more easily default options for an entire set of video, directory, playlist and so on.
  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 to choose peertube or youtube upload (to resume 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. ## Compatibility
  178. - If you still use python2, use the version 0.7.1 (no more updated)
  179. - peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3
  180. ## Sources
  181. inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)
  182. ## Contributors
  183. Thanks to: @Zykino, @meewan, @rigelk 😘