A scripting way to upload videos to peertube and youtube written in python2
Scripting your way to upload videos to peertube and youtube. Works with Python 2.7 and 3.3+.
## Dependencies
Search in your package manager, otherwise use ``pip install --upgrade``
Search in your system package manager, otherwise use ``pip install --upgrade`` for the following packages:
- google-auth
- google-auth-oauthlib
- google-auth-httplib2
@ -14,29 +15,44 @@ Search in your package manager, otherwise use ``pip install --upgrade``
- python-magic-bin
- requests-toolbelt
- tzlocal
- configparser
- future
Otherwise, you can use the requirements file with `pip install -r requirements.txt`. (*note:* requirements are generated via `poetry export -f requirements.txt`)
Otherwise, you can use [poetry](https://poetry.eustace.io/):
```
poetry install # installs the dependency in the current virtualenv, or creates one specific to the project if no virtualenv is currently active
```
## Configuration
Edit peertube_secret and youtube_secret.json with your credentials.
Generate sample files with `python -m prismedia.genconfig`. Edit
`peertube_secret` and `youtube_secret.json` with your credentials.
### Peertube
Set your credentials, peertube server URL.
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
You can set ``OAUTHLIB_INSECURE_TRANSPORT`` to 1 if you do not use https (not recommended)
### Youtube
Youtube uses combination of oauth and API access to identify.
**Credentials**
The first time you connect, prismedia will open your browser to as you to authenticate to
Youtube and allow the app to use your Youtube channel.
**It is here you choose which channel you will upload to**.
Once authenticated, the token is stored inside the file ``.youtube_credentials.json``.
Prismedia will try to use this file at each launch, and re-ask for authentication if it does not exist.
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).
**Credentials:** the first time you connect, prismedia will open your browser
to as you to authenticate to Youtube and allow the app to use your Youtube
channel.
**Oauth**:
The default youtube_secret.json should allow you to upload some videos.
If you plan an larger usage, please consider creating your own youtube_secret file:
**It is here you choose which channel you will upload to:** once authenticated,
the token is stored inside the file `.youtube_credentials.json`. Prismedia will
try to use this file at each launch, and re-ask for authentication if it does
not exist.
**OAuth 2.0**: the default `youtube_secret.json` should allow you to upload
some videos. If you plan a more frequent usage, please consider creating your
own `youtube_secret` file:
- Go to the [Google console](https://console.developers.google.com/).
- Create project.
@ -48,37 +64,36 @@ If you plan an larger usage, please consider creating your own youtube_secret fi
- Save this JSON as your youtube_secret.json file.
## How To
Currently in heavy development
Support only mp4 for cross compatibility between Youtube and Peertube
>> Currently in heavy development
Supports only mp4 for cross compatibility between Youtube and Peertube.
Simply upload a video:
```
./prismedia_upload.py --file="yourvideo.mp4"
python -m prismedia --file="yourvideo.mp4"
```
Specify description and tags:
```
./prismedia_upload.py --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
python -m prismedia --file="yourvideo.mp4" -d "My supa description" -t "tag1,tag2,foo"
```
Provide a thumbnail:
```
./prismedia_upload.py --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
python -m prismedia --file="yourvideo.mp4" -d "Video with thumbnail" --thumbnail="/path/to/your/thumbnail.jpg"
I notice that at the beginning of the libs we still use #!/usr/bin/env python2 as shebang.
It does nothing as files are never direclty calles as script, but to avoid any future (and hard to debug :D) problems between python2 and python3, it should be better to totally remove them?
Sheband are not needed when loading python files as libraries?
I notice that at the beginning of the libs we still use `#!/usr/bin/env python2` as shebang.
It does nothing as files are never direclty calles as script, but to avoid any future (and hard to debug :D) problems between python2 and python3, it should be better to totally remove them?
Sheband are not needed when loading python files as libraries?
# python 3.7.2
2019-02-23 10:49:04,384 Peertube: Error: name 'unicode' is not defined
However, we cannot use str direclty in python2 as this is not the same:
#python 2.7.15
2019-02-23 10:58:52,130 Peertube: Error: str() takes at most 1 argument (2 given)
I am looking for a way to have something working in both case, I'll let you know if I found something, does not hesitate to tell if you have any idea!
This line does not work with python3
Unfortunately, in python3 they have changed the `unicode` type that does not longer exist, in favor of `str` : [https://docs.python.org/dev/howto/pyporting.html#text-versus-binary-data](https://docs.python.org/dev/howto/pyporting.html#text-versus-binary-data):
```
# python 3.7.2
2019-02-23 10:49:04,384 Peertube: Error: name 'unicode' is not defined
```
However, we cannot use `str` direclty in python2 as this is not the same:
```
#python 2.7.15
2019-02-23 10:58:52,130 Peertube: Error: str() takes at most 1 argument (2 given)
```
I am looking for a way to have something working in both case, I'll let you know if I found something, does not hesitate to tell if you have any idea!
To reproduce you does not need a working account on Peertube instance:
± python -m prismedia --file="path/file.mp4" --nfo nfo_example.txt
2019-02-23 10:48:53,012 Using nfo_example.txt as NFO, loading...
2019-02-23 10:49:04,142 Peertube: Uploading video...
2019-02-23 10:49:04,384 Peertube: Error: name 'unicode' is not defined
To reproduce you does not need a working account on Peertube instance:
```
± python -m prismedia --file="path/file.mp4" --nfo nfo_example.txt
2019-02-23 10:48:53,012 Using nfo_example.txt as NFO, loading...
2019-02-23 10:49:04,142 Peertube: Uploading video...
2019-02-23 10:49:04,384 Peertube: Error: name 'unicode' is not defined
```
But as we did more treatment than juste returning the string, this broke other things in the code :-/
Error: decoding str is not supported
Apparently it's the strtoclean = unicodedata.normalize('NFKD', str(s, 'utf-8')).encode('ASCII', 'ignore') that does not work, even if we never call to decode directly, all these method should call it implicitely, I do not find a workaround at the moment.
The simple way should be to do something like that:
```
try:
strtoclean = unicodedata.normalize('NFKD', unicode(s, 'utf-8')).encode('ASCII', 'ignore')
except:
strtoclean = unicodedata.normalize('NFKD', str(s, 'utf-8')).encode('ASCII', 'ignore')
```
But as we did more treatment than juste returning the string, this broke other things in the code :-/
```
Error: decoding str is not supported
```
Apparently it's the `strtoclean = unicodedata.normalize('NFKD', str(s, 'utf-8')).encode('ASCII', 'ignore')` that does not work, even if we never call to `decode` directly, all these method should call it implicitely, I do not find a workaround at the moment.
This point should now be easiest thanks to v0.6.1-1
I have rewritten this code to use less python2 specific code based on unicode/str differences between python2 and 3, with the help of the SIX library you use in other places in the code, we should be able make this part compatible python3!
This point should now be easiest thanks to v0.6.1-1
I have rewritten this code to use less python2 specific code based on unicode/str differences between python2 and 3, with the help of the `SIX` library you use in other places in the code, we should be able make this part compatible python3!
defdecodeArgumentStrings(options,encoding):
# Python crash when decoding from UTF-8 to UTF-8, so we prevent this
I notice that at the beginning of the libs we still use
#!/usr/bin/env python2
as shebang.It does nothing as files are never direclty calles as script, but to avoid any future (and hard to debug :D) problems between python2 and python3, it should be better to totally remove them?
Sheband are not needed when loading python files as libraries?
Yes, we should remove them, libraries don't use them.