mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-04 01:49:15 +02:00
Update files, functions and code to work with python3
This commit is contained in:
parent
8b26f0ee53
commit
fa633ee5bb
4 changed files with 32 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
|
@ -10,7 +10,7 @@ import pytz
|
|||
from os.path import splitext, basename, abspath
|
||||
from tzlocal import get_localzone
|
||||
|
||||
from ConfigParser import RawConfigParser
|
||||
from configparser import RawConfigParser
|
||||
from requests_oauthlib import OAuth2Session
|
||||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
@ -57,7 +57,7 @@ def get_default_channel(user_info):
|
|||
|
||||
def get_channel_by_name(user_info, options):
|
||||
for channel in user_info["videoChannels"]:
|
||||
if channel['displayName'].encode('utf8') == str(options.get('--channel')):
|
||||
if channel['displayName'] == options.get('--channel'):
|
||||
return channel['id']
|
||||
|
||||
|
||||
|
@ -68,15 +68,16 @@ def create_channel(oauth, url, options):
|
|||
# Peertube allows 20 chars max for channel name
|
||||
channel_name = channel_name[:19]
|
||||
data = '{"name":"' + channel_name + '", \
|
||||
"displayName":"' + str(options.get('--channel')) +'", \
|
||||
"description":null}'
|
||||
"displayName":"' + options.get('--channel') + '", \
|
||||
"description":null, \
|
||||
"support":null}'
|
||||
|
||||
headers = {
|
||||
'Content-Type': "application/json"
|
||||
'Content-Type': "application/json; charset=UTF-8"
|
||||
}
|
||||
try:
|
||||
response = oauth.post(url + "/api/v1/video-channels/",
|
||||
data=data,
|
||||
data=data.encode('utf-8'),
|
||||
headers=headers)
|
||||
except Exception as e:
|
||||
if hasattr(e, 'message'):
|
||||
|
@ -89,8 +90,10 @@ def create_channel(oauth, url, options):
|
|||
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.'
|
||||
logging.error('Peertube: Error: It seems there is a conflict with an existing channel named '
|
||||
+ channel_name + '.'
|
||||
' Please beware Peertube internal name is compiled from 20 firsts characters of channel name.'
|
||||
' Also note that channel name are not case sensitive (no uppercase nor accent)'
|
||||
' Please check your channel name and retry.')
|
||||
exit(1)
|
||||
else:
|
||||
|
@ -105,7 +108,7 @@ def get_default_playlist(user_info):
|
|||
|
||||
def get_playlist_by_name(user_playlists, options):
|
||||
for playlist in user_playlists["data"]:
|
||||
if playlist['displayName'].encode('utf8') == str(options.get('--playlist')):
|
||||
if playlist['displayName'] == options.get('--playlist'):
|
||||
return playlist['id']
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
|
||||
from ConfigParser import RawConfigParser, NoOptionError, NoSectionError
|
||||
from configparser import RawConfigParser, NoOptionError, NoSectionError
|
||||
from os.path import dirname, splitext, basename, isfile
|
||||
import re
|
||||
from os import devnull
|
||||
|
@ -102,7 +102,7 @@ def getLanguage(language, platform):
|
|||
def remove_empty_kwargs(**kwargs):
|
||||
good_kwargs = {}
|
||||
if kwargs is not None:
|
||||
for key, value in kwargs.iteritems():
|
||||
for key, value in kwargs.items():
|
||||
if value:
|
||||
good_kwargs[key] = value
|
||||
return good_kwargs
|
||||
|
@ -172,7 +172,7 @@ def parseNFO(options):
|
|||
nfo = loadNFO(options)
|
||||
if nfo:
|
||||
# We need to check all options and replace it with the nfo value if not defined (None or False)
|
||||
for key, value in options.iteritems():
|
||||
for key, value in options.items():
|
||||
key = key.replace("-", "")
|
||||
try:
|
||||
# get string options
|
||||
|
@ -192,7 +192,6 @@ def upcaseFirstLetter(s):
|
|||
return s[0].upper() + s[1:]
|
||||
|
||||
def cleanString(toclean):
|
||||
toclean = toclean.decode('utf-8')
|
||||
toclean = unidecode.unidecode(toclean)
|
||||
cleaned = re.sub('[^A-Za-z0-9]+', '', toclean)
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
# From Youtube samples : https://raw.githubusercontent.com/youtube/api-samples/master/python/upload_video.py # noqa
|
||||
|
||||
import httplib
|
||||
import http.client
|
||||
import httplib2
|
||||
import random
|
||||
import time
|
||||
|
@ -38,13 +38,13 @@ MAX_RETRIES = 10
|
|||
RETRIABLE_EXCEPTIONS = (
|
||||
IOError,
|
||||
httplib2.HttpLib2Error,
|
||||
httplib.NotConnected,
|
||||
httplib.IncompleteRead,
|
||||
httplib.ImproperConnectionState,
|
||||
httplib.CannotSendRequest,
|
||||
httplib.CannotSendHeader,
|
||||
httplib.ResponseNotReady,
|
||||
httplib.BadStatusLine,
|
||||
http.client.NotConnected,
|
||||
http.client.IncompleteRead,
|
||||
http.client.ImproperConnectionState,
|
||||
http.client.CannotSendRequest,
|
||||
http.client.CannotSendHeader,
|
||||
http.client.ResponseNotReady,
|
||||
http.client.BadStatusLine,
|
||||
)
|
||||
|
||||
RETRIABLE_STATUS_CODES = [500, 502, 503, 504]
|
||||
|
@ -146,7 +146,7 @@ def initialize_upload(youtube, options):
|
|||
|
||||
# Call the API's videos.insert method to create and upload the video.
|
||||
insert_request = youtube.videos().insert(
|
||||
part=','.join(body.keys()),
|
||||
part=','.join(list(body.keys())),
|
||||
body=body,
|
||||
media_body=MediaFileUpload(path, chunksize=-1, resumable=True)
|
||||
)
|
||||
|
@ -168,7 +168,7 @@ def get_playlist_by_name(youtube, playlist_name):
|
|||
maxResults=50
|
||||
).execute()
|
||||
for playlist in response["items"]:
|
||||
if playlist["snippet"]['title'].encode('utf8') == str(playlist_name):
|
||||
if playlist["snippet"]['title'] == playlist_name:
|
||||
return playlist['id']
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
|
@ -170,17 +170,17 @@ if __name__ == '__main__':
|
|||
schema = Schema({
|
||||
'--file': And(str, validateVideo, error='file is not supported, please use mp4'),
|
||||
Optional('--name'): Or(None, And(
|
||||
basestring,
|
||||
str,
|
||||
lambda x: not x.isdigit(),
|
||||
error="The video name should be a string")
|
||||
),
|
||||
Optional('--description'): Or(None, And(
|
||||
basestring,
|
||||
str,
|
||||
lambda x: not x.isdigit(),
|
||||
error="The video description should be a string")
|
||||
),
|
||||
Optional('--tags'): Or(None, And(
|
||||
basestring,
|
||||
str,
|
||||
lambda x: not x.isdigit(),
|
||||
error="Tags should be a string")
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue