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.

189 lines
7.8 KiB

6 years ago
6 years ago
6 years ago
  1. # Prismedia
  2. Scripting your way to upload videos to peertube and youtube. Works with Python 2.7 and 3.3+.
  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. - configparser
  16. - future
  17. Otherwise, you can use the requirements file with `pip install -r requirements.txt`. (*note:* requirements are generated via `poetry export -f requirements.txt`)
  18. Otherwise, you can use [poetry](https://poetry.eustace.io/):
  19. ```
  20. poetry install # installs the dependency in the current virtualenv, or creates one specific to the project if no virtualenv is currently active
  21. ```
  22. ## Configuration
  23. Generate sample files with `python -m prismedia.genconfig`. Edit
  24. `peertube_secret` and `youtube_secret.json` with your credentials.
  25. ### Peertube
  26. Set your credentials, peertube server URL.
  27. 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
  28. You can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)
  29. ### Youtube
  30. 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).
  31. **Credentials:** the first time you connect, prismedia will open your browser
  32. to as you to authenticate to Youtube and allow the app to use your Youtube
  33. channel.
  34. **It is here you choose which channel you will upload to:** once authenticated,
  35. the token is stored inside the file `.youtube_credentials.json`. Prismedia will
  36. try to use this file at each launch, and re-ask for authentication if it does
  37. not exist.
  38. **OAuth 2.0**: the default `youtube_secret.json` should allow you to upload
  39. some videos. If you plan a more frequent usage, please consider creating your
  40. own `youtube_secret` file:
  41. - Go to the [Google console](https://console.developers.google.com/).
  42. - Create project.
  43. - Side menu: APIs & auth -> APIs
  44. - Top menu: Enabled API(s): Enable all Youtube APIs.
  45. - Side menu: APIs & auth -> Credentials.
  46. - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK
  47. - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system.
  48. - Save this JSON as your youtube_secret.json file.
  49. ## How To
  50. >> Currently in heavy development
  51. Supports only mp4 for cross compatibility between Youtube and Peertube.
  52. Simply 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. ```
  66. python -m prismedia --file="yourvideo.mp4" --nfo /path/to/your/nfo.txt
  67. ```
  68. Use --help to get all available options:
  69. ```
  70. Options:
  71. -f, --file=STRING Path to the video file to upload in mp4
  72. --name=NAME Name of the video to upload. (default to video filename)
  73. -d, --description=STRING Description of the video. (default: default description)
  74. -t, --tags=STRING Tags for the video. comma separated.
  75. WARN: tags with space and special characters (!, ', ", ?, ...)
  76. are not supported by Mastodon to be published from Peertube
  77. use mastodon compatibility below
  78. --mt Force Mastodon compatibility for tags (drop every incompatible characters inside tags)
  79. This option requires --tags
  80. -c, --category=STRING Category for the videos, see below. (default: Films)
  81. --cca License should be CreativeCommon Attribution (affects Youtube upload only)
  82. -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
  83. --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
  84. --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
  85. --nfo=STRING Configure a specific nfo file to set options for the video.
  86. By default Prismedia search a .txt based on the video name and will
  87. decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
  88. See nfo_example.txt for more details
  89. --platform=STRING List of platform(s) to upload to, comma separated.
  90. Supported platforms are youtube and peertube (default is both)
  91. --language=STRING Specify the default language for video. See below for supported language. (default is English)
  92. --publishAt=DATE Publish the video at the given DATE using local server timezone.
  93. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  94. DATE should be in the future
  95. For Peertube, requires the "atd" and "curl utilities installed on the system
  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. --playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube.
  100. If the playlist is not found, spawn an error except if --playlist-create is set.
  101. --playlistCreate Create the playlist if not exists. (default do not create)
  102. Only relevant if --playlist is set.
  103. -h --help Show this help.
  104. --version Show version.
  105. Categories:
  106. Category is the type of video you upload. Default is films.
  107. Here are available categories from Peertube and Youtube:
  108. music, films, vehicles,
  109. sports, travels, gaming, people,
  110. comedy, entertainment, news,
  111. how to, education, activism, science & technology,
  112. science, technology, animals
  113. Languages:
  114. Language of the video (audio track), choose one. Default is English
  115. Here are available languages from Peertube and Youtube:
  116. Arabic, English, French, German, Hindi, Italian,
  117. Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  118. ```
  119. ## Features
  120. - [x] Youtube upload
  121. - [x] Peertube upload
  122. - Support of all videos arguments (description, tags, category, licence, ...)
  123. - [x] description
  124. - [x] tags (no more than 30 characters per tag as Peertube does not support it)
  125. - [x] Option to force tags to be compatible with Mastodon publication
  126. - [x] categories
  127. - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
  128. - [x] privacy (between public, unlisted or private)
  129. - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
  130. - [x] nsfw (Peertube only as Youtube API does not support it)
  131. - [x] set default language
  132. - [x] thumbnail/preview
  133. - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
  134. - [x] add videos to playlist
  135. - [x] create playlist
  136. - [x] Use a config file (NFO) file to retrieve videos arguments
  137. - [x] Allow to choose peertube or youtube upload (to resume failed upload for example)
  138. - [x] Add publishAt option to plan your videos
  139. - [ ] Record and forget: put the video in a directory, and the script uploads it for you
  140. - [ ] Usable on Desktop (Linux and/or Windows and/or MacOS)
  141. - [ ] Graphical User Interface
  142. ## Compatibility
  143. ### Compatibility with PeerTube
  144. If your server uses PeerTube before `1.0.0-beta4`, use the version inside tag `1.0.0-beta3` of prismedia!
  145. ### Compatibility with Operating Systems
  146. The script has been tested on Linux and Windows platforms.
  147. ## Sources
  148. Prismedia has been inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload).