Skip to content

Commit

Permalink
Merge pull request #12 from offish/v1.3.0
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
offish authored Dec 4, 2020
2 parents 8447e4f + d57282b commit 13acf0b
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 180 deletions.
126 changes: 45 additions & 81 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
twitchtube
==========
|license| |stars| |issues| |repo_size| |chat|
# twitchtube
[![License](https://img.shields.io/github/license/offish/twitchtube.svg)](https://github.com/offish/twitchtube/blob/master/LICENSE)
[![Stars](https://img.shields.io/github/stars/offish/twitchtube.svg)](https://github.com/offish/twitchtube/stargazers)
[![Issues](https://img.shields.io/github/issues/offish/twitchtube.svg)](https://github.com/offish/twitchtube/issues)
[![Size](https://img.shields.io/github/repo-size/offish/twitchtube.svg)](https://github.com/offish/twitchtube)
[![Chat](https://img.shields.io/discord/467040686982692865.svg)](https://discord.gg/t8nHSvA)

[![Donate Steam](https://img.shields.io/badge/donate-steam-green.svg)](https://steamcommunity.com/tradeoffer/new/?partner=293059984&token=0-l_idZR)
[![Donate PayPal](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/0ffish)

|donate_steam| |donate|

Automatically make video compilations of the most viewed Twitch clips and upload it to YouTube using Python 3.

.. contents:: Table of Contents
:depth: 2

Installation
------------
## Installation
Download the repo as ZIP and unpack it somewhere accessible.

To install all the needed packages you either need to run install.bat or this command (has to be in
To install all the packages needed you need to run this command (has to be in
the right directory).

.. code-block:: text
```
pip install -r requirements.txt
```

pip install -r requirements.txt

Configuration
-------------
Creating your Twitch Application
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
## Configuration
### Creating your Twitch Application
Go to https://dev.twitch.tv/console and register a new application.
The name of the application does not matter. Set "OAuth Redirect URLs" to https://twitchapps.com/tokengen/
Set category to Application Integration or Other.
You will now see your Client ID, copy this ID.
Go to config.py under dist, find CLIENT_ID and paste it inside apostrophes.

Getting your OAuth Token
^^^^^^^^^^^^^^^^^^^^^^^^
### Getting your OAuth Token
Now head over to https://twitchapps.com/tokengen/
Paste in your Client ID, scopes does not matter in our case.
Click "Connect" and then authorize with Twitch.
Copy your OAuth Token, go to config.py, find OAUTH_TOKEN and paste it inside the apostrophes.

Creating your Google Project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
### Creating your Google Project
Go to https://console.cloud.google.com/ and create a new project.
Name does not matter.

Enabling YouTube Data API v3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
### Enabling YouTube Data API v3
Click on the menu on the left side of your screen and navigate to "APIs & Services".
Hover over this button and click "Library".
Search for "YouTube Data API v3" and click the first result.
Enable this API.

Getting your client_secret
^^^^^^^^^^^^^^^^^^^^^^^^^^
### Getting your client_secret
When you've clicked enable you should now be on the "Overview" tab.
Click "Credentials" and then "+ Create Credentials".
You will now see 3 options, click "OAuth client ID".
Expand All @@ -63,43 +60,41 @@ Set application type to Desktop app and name it whatever.
Click Ok, and click the download icon.
Open the JSON file that gets downloaded, select everything and paste it into the client_secret file under dist.

Adding/removing games
^^^^^^^^^^^^^^^^^^^^^
If you want to add a game/category, you simply write the name of the game how it appears on Twitch inside the GAMES list in config.py.
### Adding/removing games
If you want to add a game/category, you simply write the name of the game how it appears on Twitch inside the GAMES list in [`config.py`](twitchtube/config.py).
If you want to add Just Chatting for example GAMES should look like this:

.. code-block:: python
GAMES = ['Rust', 'Just Chatting', 'Team Fortress 2']
```python
GAMES = ['Rust', 'Just Chatting', 'Team Fortress 2']
```

Last entry in the list must not have a comma.

If only want to have 1 game/category GAMES, in this case Just Chatting it should look like this:

.. code-block:: python
GAMES = ['Just Chatting']
```python
GAMES = ['Just Chatting']
```

**EVERY ENTRY IN GAMES MUST ALSO BE FOUND IN TAGS AND DESCRIPTIONS**

Example:

.. code-block:: python
GAMES = ['Just Chatting']
```python
GAMES = ['Just Chatting']

TAGS = {
'Just Chatting': 'just chatting, just chatting twitch, just chatting twitch highlights'
}
TAGS = {
'Just Chatting': 'just chatting, just chatting twitch, just chatting twitch highlights'
}

DESCRIPTIONS = {
'Just Chatting': 'The most viewed Just Chatting clips today.\n\n{}\n#Twitch #TwitchHighlights #Just Chatting'
}
DESCRIPTIONS = {
'Just Chatting': 'The most viewed Just Chatting clips today.\n\n{}\n#Twitch #TwitchHighlights #Just Chatting'
}
```

Counter-Strike: Global Offensive is currently not supported since folders can't include colons in their folder name.

How it works
------------
## How it works
The script starts by checking every game listed in the config. It will then create a folder with
the current date as the name and inside of this folder it will create another folder for the
first game in the list (also specified in the config). It will send a request to Twitch's API
Expand All @@ -111,26 +106,20 @@ video is done rendering, it will upload it to YouTube. When the video is uploade
create a new folder for the next game in the list (if any) with the game title as folder
name and redo the process written above.

Running
-------
To run the script simply run start.bat or type python main.py in command prompt (must be in the correct folder).
## Running
To run the script run `python main.py` in command prompt (must be in the correct folder).

Example
-------
`Here`_ is an example of how the videos look like on YouTube. Majority of these videos are made using
## Example
[Here](https://www.youtube.com/channel/UCd0wttXr03lIcTLv38U5d-w) is an example of how the videos look like on YouTube. Majority of these videos are made using
this repo. Only a couple of titles and thumbnails have been changed.

.. _Here: https://www.youtube.com/channel/UCd0wttXr03lIcTLv38U5d-w

Note
----
## Note
I've only tested this script using Python 3.7.3, but should work with later versions.

License
-------
## License
MIT License

Copyright (c) 2020 `offish`_
Copyright (c) 2020 [offish](https://offi.sh)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -150,32 +139,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

.. _offish: https://offi.sh

.. |license| image:: https://img.shields.io/github/license/offish/twitchtube.svg
:target: https://github.com/offish/twitchtube/blob/master/LICENSE
:alt: License

.. |stars| image:: https://img.shields.io/github/stars/offish/twitchtube.svg
:target: https://github.com/offish/twitchtube/stargazers
:alt: Stars

.. |issues| image:: https://img.shields.io/github/issues/offish/twitchtube.svg
:target: https://github.com/offish/twitchtube/issues
:alt: Issues

.. |repo_size| image:: https://img.shields.io/github/repo-size/offish/twitchtube.svg
:target: https://github.com/offish/twitchtube
:alt: Repo Size

.. |chat| image:: https://img.shields.io/discord/467040686982692865.svg
:target: https://discord.gg/t8nHSvA
:alt: Discord

.. |donate_steam| image:: https://img.shields.io/badge/donate-steam-green.svg
:target: https://steamcommunity.com/tradeoffer/new/?partner=293059984&token=0-l_idZR
:alt: Donate via Steam

.. |donate| image:: https://img.shields.io/badge/donate-paypal-blue.svg
:target: https://www.paypal.me/0ffish
:alt: Done via PayPal
21 changes: 0 additions & 21 deletions dist/logging.py

This file was deleted.

4 changes: 0 additions & 4 deletions install.bat

This file was deleted.

41 changes: 25 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
from os.path import isdir
from os.path import exists
from pathlib import Path
from time import sleep
from glob import glob
from os import remove

from dist.config import GAMES, VIDEO_LENGTH, CLIP_PATH, TIMEOUT, UPLOAD_TO_YOUTUBE
from dist.other import create_video_config, get_date
from dist.clips import get_clips, download_clips
from dist.upload import upload_video_to_youtube
from dist.video import render
from dist.logging import log
from twitchtube.logging import Log
from twitchtube.config import *
from twitchtube.upload import upload_video_to_youtube
from twitchtube.utils import create_video_config, get_date
from twitchtube.clips import get_clips, download_clips
from twitchtube.video import render


log = log()
log = Log()


while True:

for game in GAMES:

path = CLIP_PATH.format(get_date(), game)

if not isdir(path):
tries = 3
if not exists(path + f'/{FILE_NAME}.mp4'):

for i in range(tries):
for i in range(RETRIES):

Path(path).mkdir(parents=True, exist_ok=True)

Expand All @@ -35,14 +37,21 @@
if UPLOAD_TO_YOUTUBE:
config = create_video_config(game, names)
upload_video_to_youtube(config)

del config

del names

if DELETE_CLIPS:
files = glob(f'{path}/*.mp4')

for file in files:
if not file == path + '\\' + FILE_NAME + '.mp4':
try:
remove(file)
except PermissionError:
log.error(f'Could not remove {file} because its being used')

break

else:
log.error(f'There was an error or timeout on Twitch\'s end, retrying... {i + 1}/{tries}')
log.error(f'There was an error or timeout on Twitch\'s end, retrying... {i + 1}/{RETRIES}')

else:
log.info(f'Already made a video for {game}. Rechecking after {TIMEOUT} seconds.')
Expand Down
4 changes: 0 additions & 4 deletions start.bat

This file was deleted.

2 changes: 1 addition & 1 deletion dist/__init__.py → twitchtube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
__title__ = 'twitchtube'
__author__ = 'offish'
__license__ = 'MIT'
__version__ = '1.2.2'
__version__ = '1.3.0'
File renamed without changes.
Loading

0 comments on commit 13acf0b

Please sign in to comment.