Browse Source

Merge branch 'feature/pt-channel' into develop

pull/45/head
LecygneNoir 4 years ago
parent
commit
9c72a563bd
4 changed files with 80 additions and 16 deletions
  1. +8
    -6
      README.md
  2. +58
    -5
      lib/pt_upload.py
  3. +5
    -3
      nfo_example.txt
  4. +9
    -2
      prismedia_upload.py

+ 8
- 6
README.md View File

@ -91,8 +91,6 @@ Options:
WARN: tags with space and special characters (!, ', ", ?, ...) WARN: tags with space and special characters (!, ', ", ?, ...)
are not supported by Mastodon to be published from Peertube are not supported by Mastodon to be published from Peertube
use mastodon compatibility below use mastodon compatibility below
--mt Force Mastodon compatibility for tags (drop every incompatible characters inside tags)
This option requires --tags
-c, --category=STRING Category for the videos, see below. (default: Films) -c, --category=STRING Category for the videos, see below. (default: Films)
--cca License should be CreativeCommon Attribution (affects Youtube upload only) --cca License should be CreativeCommon Attribution (affects Youtube upload only)
-p, --privacy=STRING Choose between public, unlisted or private. (default: private) -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
@ -112,8 +110,12 @@ Options:
--thumbnail=STRING Path to a file to use as a thumbnail for the video. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
Supported types are jpg and jpeg. Supported types are jpg and jpeg.
By default, prismedia search for an image based on video name followed by .jpg or .jpeg By default, prismedia search for an image based on video name followed by .jpg or .jpeg
--channel=STRING Set the channel to use for the video (Peertube only)
If the channel is not found, spawn an error except if --channelCreate is set.
--channelCreate Create the channel if not exists. (Peertube only, default do not create)
Only relevant if --channel is set.
--playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube. --playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube.
If the playlist is not found, spawn an error except if --playlist-create is set.
If the playlist is not found, spawn an error except if --playlistCreate is set.
--playlistCreate Create the playlist if not exists. (default do not create) --playlistCreate Create the playlist if not exists. (default do not create)
Only relevant if --playlist is set. Only relevant if --playlist is set.
-h --help Show this help. -h --help Show this help.
@ -139,10 +141,9 @@ Languages:
- [x] Youtube upload - [x] Youtube upload
- [x] Peertube upload - [x] Peertube upload
- Support of all videos arguments (description, tags, category, licence, ...)
- Support of videos parameters (description, tags, category, licence, ...)
- [x] description - [x] description
- [x] tags (no more than 30 characters per tag as Peertube does not support it) - [x] tags (no more than 30 characters per tag as Peertube does not support it)
- [x] Option to force tags to be compatible with Mastodon publication
- [x] categories - [x] categories
- [x] license: cca or not (Youtube only as Peertube uses Attribution by design) - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
- [x] privacy (between public, unlisted or private) - [x] privacy (between public, unlisted or private)
@ -153,9 +154,10 @@ Languages:
- [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4)) - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
- [x] add videos to playlist - [x] add videos to playlist
- [x] create playlist - [x] create playlist
- [x] schedule your video with publishAt
- [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.
- [x] Use a config file (NFO) file to retrieve videos arguments - [x] Use a config file (NFO) file to retrieve videos arguments
- [x] Allow to choose peertube or youtube upload (to resume failed upload for example) - [x] Allow to choose peertube or youtube upload (to resume failed upload for example)
- [x] Add publishAt option to plan your videos
- [ ] Record and forget: put the video in a directory, and the script uploads it for you - [ ] Record and forget: put the video in a directory, and the script uploads it for you
- [ ] Usable on Desktop (Linux and/or Windows and/or MacOS) - [ ] Usable on Desktop (Linux and/or Windows and/or MacOS)
- [ ] Graphical User Interface - [ ] Graphical User Interface

+ 58
- 5
lib/pt_upload.py View File

@ -55,6 +55,50 @@ def get_default_channel(user_info):
return user_info['videoChannels'][0]['id'] return user_info['videoChannels'][0]['id']
def get_channel_by_name(user_info, options):
for channel in user_info["videoChannels"]:
if channel['displayName'].encode('utf8') == str(options.get('--channel')):
return channel['id']
def create_channel(oauth, url, options):
template = ('Peertube: Channel %s does not exist, creating it.')
logging.info(template % (str(options.get('--channel'))))
channel_name = utils.cleanString(str(options.get('--channel')))
# Peertube allows 20 chars max for channel name
channel_name = channel_name[:19]
data = '{"name":"' + channel_name +'", \
"displayName":"' + str(options.get('--channel')) +'", \
"description":null}'
headers = {
'Content-Type': "application/json"
}
try:
response = oauth.post(url + "/api/v1/video-channels/",
data=data,
headers=headers)
except Exception as e:
if hasattr(e, 'message'):
logging.error("Error: " + str(e.message))
else:
logging.error("Error: " + str(e))
if response is not None:
if response.status_code == 200:
jresponse = response.json()
jresponse = jresponse['videoChannel']
return jresponse['id']
if response.status_code == 409:
logging.error('Peertube: Error: It seems there is a conflict with an existing channel, please beware '
'Peertube internal name is compiled from 20 firsts characters of channel name.'
' Please check your channel name and retry.')
exit(1)
else:
logging.error(('Peertube: Creating channel failed with an unexpected response: '
'%s') % response)
exit(1)
def get_default_playlist(user_info): def get_default_playlist(user_info):
return user_info['videoChannels'][0]['id'] return user_info['videoChannels'][0]['id']
@ -65,7 +109,7 @@ def get_playlist_by_name(user_playlists, options):
return playlist['id'] return playlist['id']
def create_playlist(oauth, url, options, default_channel):
def create_playlist(oauth, url, options, channel):
template = ('Peertube: Playlist %s does not exist, creating it.') template = ('Peertube: Playlist %s does not exist, creating it.')
logging.info(template % (str(options.get('--playlist')))) logging.info(template % (str(options.get('--playlist'))))
# We use files for form-data Content # We use files for form-data Content
@ -74,7 +118,7 @@ def create_playlist(oauth, url, options, default_channel):
files = {'displayName': (None, str(options.get('--playlist'))), files = {'displayName': (None, str(options.get('--playlist'))),
'privacy': (None, "1"), 'privacy': (None, "1"),
'description': (None, "null"), 'description': (None, "null"),
'videoChannelId': (None, str(default_channel)),
'videoChannelId': (None, str(channel)),
'thumbnailfile': (None, "null")} 'thumbnailfile': (None, "null")}
try: try:
response = oauth.post(url + "/api/v1/video-playlists/", response = oauth.post(url + "/api/v1/video-playlists/",
@ -199,13 +243,22 @@ def upload_video(oauth, secret, options):
fields.append(("thumbnailfile", get_file(options.get('--thumbnail')))) fields.append(("thumbnailfile", get_file(options.get('--thumbnail'))))
fields.append(("previewfile", get_file(options.get('--thumbnail')))) fields.append(("previewfile", get_file(options.get('--thumbnail'))))
default_channel = get_default_channel(user_info)
fields.append(("channelId", str(default_channel)))
if options.get('--channel'):
channel_id = get_channel_by_name(user_info, options)
if not channel_id and options.get('--channelCreate'):
channel_id = create_channel(oauth, url, options)
elif not channel_id:
logging.warning("Channel `" + options.get('--channel') + "` is unknown, using default channel.")
channel_id = get_default_channel(user_info)
else:
channel_id = get_default_channel(user_info)
fields.append(("channelId", str(channel_id)))
if options.get('--playlist'): if options.get('--playlist'):
playlist_id = get_playlist_by_name(user_playlists, options) playlist_id = get_playlist_by_name(user_playlists, options)
if not playlist_id and options.get('--playlistCreate'): if not playlist_id and options.get('--playlistCreate'):
playlist_id = create_playlist(oauth, url, options, default_channel)
playlist_id = create_playlist(oauth, url, options, channel_id)
elif not playlist_id: elif not playlist_id:
logging.warning("Playlist `" + options.get('--playlist') + "` does not exist, please set --playlistCreate" logging.warning("Playlist `" + options.get('--playlist') + "` does not exist, please set --playlistCreate"
" if you want to create it") " if you want to create it")

+ 5
- 3
nfo_example.txt View File

@ -16,10 +16,12 @@ category = Films
cca = True cca = True
privacy = private privacy = private
disable-comments = True disable-comments = True
thumbnail = /path/to/your/thumbnail.jpg # Set the absolute path to your thumbnail
playlist = My Test Playlist
#thumbnail = /path/to/your/thumbnail.jpg # Set the absolute path to your thumbnail
channel = CookingTest
channelCreate = True
playlist = Desserts Recipes playlist
playlistCreate = True playlistCreate = True
nsfw = True
nsfw = False
platform = youtube, peertube platform = youtube, peertube
language = French language = French
publishAt=2034-05-07T19:00:00 publishAt=2034-05-07T19:00:00

+ 9
- 2
prismedia_upload.py View File

@ -24,7 +24,8 @@ Options:
--disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled) --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
--nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe) --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
--nfo=STRING Configure a specific nfo file to set options for the video. --nfo=STRING Configure a specific nfo file to set options for the video.
By default Prismedia search a .txt based on video name
By default Prismedia search a .txt based on the video name and will
decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
See nfo_example.txt for more details See nfo_example.txt for more details
--platform=STRING List of platform(s) to upload to, comma separated. --platform=STRING List of platform(s) to upload to, comma separated.
Supported platforms are youtube and peertube (default is both) Supported platforms are youtube and peertube (default is both)
@ -36,8 +37,12 @@ Options:
--thumbnail=STRING Path to a file to use as a thumbnail for the video. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
Supported types are jpg and jpeg. Supported types are jpg and jpeg.
By default, prismedia search for an image based on video name followed by .jpg or .jpeg By default, prismedia search for an image based on video name followed by .jpg or .jpeg
--channel=STRING Set the channel to use for the video (Peertube only)
If the channel is not found, spawn an error except if --channelCreate is set.
--channelCreate Create the channel if not exists. (Peertube only, default do not create)
Only relevant if --channel is set.
--playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube. --playlist=STRING Set the playlist to use for the video. Also known as Channel for Peertube.
If the playlist is not found, spawn an error except if --playlist-create is set.
If the playlist is not found, spawn an error except if --playlistCreate is set.
--playlistCreate Create the playlist if not exists. (default do not create) --playlistCreate Create the playlist if not exists. (default do not create)
Only relevant if --playlist is set. Only relevant if --playlist is set.
-h --help Show this help. -h --help Show this help.
@ -207,6 +212,8 @@ if __name__ == '__main__':
Optional('--thumbnail'): Or(None, And( Optional('--thumbnail'): Or(None, And(
str, validateThumbnail, error='thumbnail is not supported, please use jpg/jpeg'), str, validateThumbnail, error='thumbnail is not supported, please use jpg/jpeg'),
), ),
Optional('--channel'): Or(None, str),
Optional('--channelCreate'): bool,
Optional('--playlist'): Or(None, str), Optional('--playlist'): Or(None, str),
Optional('--playlistCreate'): bool, Optional('--playlistCreate'): bool,
'--help': bool, '--help': bool,

Loading…
Cancel
Save