Browse Source

Merge branch 'release/v0.7.0'

master v0.7.0
LecygneNoir 4 years ago
parent
commit
1fc0577ce7
5 changed files with 92 additions and 17 deletions
  1. +11
    -0
      CHANGELOG.md
  2. +8
    -6
      README.md
  3. +58
    -5
      lib/pt_upload.py
  4. +5
    -3
      nfo_example.txt
  5. +10
    -3
      prismedia_upload.py

+ 11
- 0
CHANGELOG.md View File

@ -1,5 +1,16 @@
# Changelog
## v0.7.0
### Features
Support Peertube channel additionally with playlist for Peertube!
Peertube only as channel are Peertube's feature. See #40 for details.
### Fixes
- Best uses of special chars in videoname, channel name and playlist name
- Some fixes in logging message for better lisibility
- Readme features list improved for better lisibility
## v0.6.4
### Fixes

+ 8
- 6
README.md View File

@ -91,8 +91,6 @@ Options:
WARN: tags with space and special characters (!, ', ", ?, ...)
are not supported by Mastodon to be published from Peertube
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)
--cca License should be CreativeCommon Attribution (affects Youtube upload only)
-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.
Supported types are jpg and 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.
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)
Only relevant if --playlist is set.
-h --help Show this help.
@ -139,10 +141,9 @@ Languages:
- [x] Youtube upload
- [x] Peertube upload
- Support of all videos arguments (description, tags, category, licence, ...)
- Support of videos parameters (description, tags, category, licence, ...)
- [x] description
- [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] license: cca or not (Youtube only as Peertube uses Attribution by design)
- [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] add videos to 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] 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
- [ ] Usable on Desktop (Linux and/or Windows and/or MacOS)
- [ ] 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']
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):
return user_info['videoChannels'][0]['id']
@ -65,7 +109,7 @@ def get_playlist_by_name(user_playlists, options):
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.')
logging.info(template % (str(options.get('--playlist'))))
# 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'))),
'privacy': (None, "1"),
'description': (None, "null"),
'videoChannelId': (None, str(default_channel)),
'videoChannelId': (None, str(channel)),
'thumbnailfile': (None, "null")}
try:
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(("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'):
playlist_id = get_playlist_by_name(user_playlists, options)
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:
logging.warning("Playlist `" + options.get('--playlist') + "` does not exist, please set --playlistCreate"
" if you want to create it")

+ 5
- 3
nfo_example.txt View File

@ -16,10 +16,12 @@ category = Films
cca = True
privacy = private
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
nsfw = True
nsfw = False
platform = youtube, peertube
language = French
publishAt=2034-05-07T19:00:00

+ 10
- 3
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)
--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.
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
--platform=STRING List of platform(s) to upload to, comma separated.
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.
Supported types are jpg and 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.
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)
Only relevant if --playlist is set.
-h --help Show this help.
@ -92,7 +97,7 @@ except ImportError:
'see https://github.com/ahupp/python-magic\n')
exit(1)
VERSION = "prismedia v0.6.4"
VERSION = "prismedia v0.7.0"
VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
VALID_CATEGORIES = (
@ -207,6 +212,8 @@ if __name__ == '__main__':
Optional('--thumbnail'): Or(None, And(
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('--playlistCreate'): bool,
'--help': bool,

Loading…
Cancel
Save