scripting your 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.

188 lines
7.9 KiB

6 years ago
6 years ago
6 years ago
  1. # Prismedia
  2. Scripting your way to upload videos to peertube and youtube. Works only with Python 2 so far.
  3. ## Dependencies
  4. Search in your system package manager, otherwise use ``pip install --upgrade`` for the following packages:
  5. - google-auth
  6. - google-auth-oauthlib
  7. - google-auth-httplib2
  8. - google-api-python-client
  9. - docopt
  10. - schema
  11. - python-magic
  12. - python-magic-bin
  13. - requests-toolbelt
  14. - tzlocal
  15. Otherwise, you can use the requirements file with `pip install -r requirements.txt`. (*note:* requirements are generated via `poetry export -f requirements.txt`)
  16. Otherwise, you can use [pyenv](https://github.com/pyenv/pyenv) and [poetry](https://poetry.eustace.io/):
  17. ```
  18. pyenv install # installs the python version specified in .python-version
  19. pyenv shell # activates the python version for the session
  20. poetry install # installs the dependency in a virtualenv specific to the project
  21. ```
  22. ## Configuration
  23. Edit `peertube_secret` and `youtube_secret.json` with your credentials.
  24. ### Peertube
  25. Set your credentials, peertube server URL.
  26. You can get client_id and client_secret by logging in your peertube website and reaching the URL: https://domain.example/api/v1/oauth-clients/local
  27. You can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)
  28. ### Youtube
  29. Youtube uses OAuth 2.0 to restrict its API access to identified users. Registering a client is documented [here](https://developers.google.com/youtube/v3/guides/uploading_a_video).
  30. **Credentials:** the first time you connect, prismedia will open your browser
  31. to as you to authenticate to Youtube and allow the app to use your Youtube
  32. channel.
  33. **It is here you choose which channel you will upload to:** once authenticated,
  34. the token is stored inside the file `.youtube_credentials.json`. Prismedia will
  35. try to use this file at each launch, and re-ask for authentication if it does
  36. not exist.
  37. **OAuth 2.0**: the default `youtube_secret.json` should allow you to upload
  38. some videos. If you plan a more frequent usage, please consider creating your
  39. own `youtube_secret` file:
  40. - Go to the [Google console](https://console.developers.google.com/).
  41. - Create project.
  42. - Side menu: APIs & auth -> APIs
  43. - Top menu: Enabled API(s): Enable all Youtube APIs.
  44. - Side menu: APIs & auth -> Credentials.
  45. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  46. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  47. - Save this JSON as your youtube_secret.json file.
  48. ## How To
  49. >> Currently in heavy development
  50. Supports only mp4 for cross compatibility between Youtube and Peertube.
  51. Simply upload a video:
  52. ```
  53. python -m prismedia.upload --file="yourvideo.mp4"
  54. ```
  55. Specify description and tags:
  56. ```
  57. python -m prismedia.upload --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
  58. ```
  59. Provide a thumbnail:
  60. ```
  61. python -m prismedia.upload --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
  62. ```
  63. Use a NFO file to specify your video options:
  64. ```
  65. python -m prismedia.upload --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  66. ```
  67. Use --help to get all available options:
  68. ```
  69. Options:
  70. -f, --file=STRING Path to the video file to upload in mp4
  71. --name=NAME Name of the video to upload. (default to video filename)
  72. -d, --description=STRING Description of the video. (default: default description)
  73. -t, --tags=STRING Tags for the video. comma separated.
  74. WARN: tags with space and special characters (!, ', ", ?, ...)
  75. are not supported by Mastodon to be published from Peertube
  76. use mastodon compatibility below
  77. --mt Force Mastodon compatibility for tags (drop every incompatible characters inside tags)
  78. This option requires --tags
  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. For Peertube, requires the "atd" and "curl utilities installed on the system
  95. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
  96. Supported types are jpg and jpeg.
  97. By default, prismedia search for an image based on video name followed by .jpg or .jpeg
  98. --playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube.
  99. If the playlist is not found, spawn an error except if --playlist-create is set.
  100. --playlistCreate Create the playlist if not exists. (default do not create)
  101. Only relevant if --playlist is set.
  102. -h --help Show this help.
  103. --version Show version.
  104. Categories:
  105. Category is the type of video you upload. Default is films.
  106. Here are available categories from Peertube and Youtube:
  107. music, films, vehicles,
  108. sports, travels, gaming, people,
  109. comedy, entertainment, news,
  110. how to, education, activism, science & technology,
  111. science, technology, animals
  112. Languages:
  113. Language of the video (audio track), choose one. Default is English
  114. Here are available languages from Peertube and Youtube:
  115. Arabic, English, French, German, Hindi, Italian,
  116. Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  117. ```
  118. ## Features
  119. - [x] Youtube upload
  120. - [x] Peertube upload
  121. - Support of all videos arguments (description, tags, category, licence, ...)
  122. - [x] description
  123. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  124. - [x] Option to force tags to be compatible with Mastodon publication
  125. - [x] categories
  126. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  127. - [x] privacy (between public, unlisted or private)
  128. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  129. - [x] nsfw (Peertube only as Youtube API does not support it)
  130. - [x] set default language
  131. - [x] thumbnail/preview
  132. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  133. - [x] add videos to playlist
  134. - [x] create playlist
  135. - [x] Use a config file (NFO) file to retrieve videos arguments
  136. - [x] Allow to choose peertube or youtube upload (to resume failed upload for example)
  137. - [x] Add publishAt option to plan your videos
  138. - [ ] Record and forget: put the video in a directory, and the script uploads it for you
  139. - [ ] Usable on Desktop (Linux and/or Windows and/or MacOS)
  140. - [ ] Graphical User Interface
  141. ## Compatibility
  142. ### Compatibility with PeerTube
  143. If your server uses PeerTube before `1.0.0-beta4`, use the version inside tag `1.0.0-beta3` of prismedia!
  144. ### Compatibility with Operating Systems
  145. The script has been tested on Linux and Windows platforms.
  146. ## Sources
  147. Prismedia has been inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload).