Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
--reset also deletes the config file
  • Loading branch information
BasioMeusPuga committed May 8, 2017
1 parent ba903c4 commit 478dddf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 62 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# twitchy
livestreamer / streamlink wrapper for twitch.tv

**Requires livestreamer (or streamlink), python3**
**Requires streamlink (or livestreamer), python3, python-requests**

This script hopefully fulfills the needs of the discerning git cloner who wants to watch Twitch, hates the CPU utilization of having a browser/flash running, and has only a terminal handy.

Features:
* Integration with your conky instance.
* Tracking of most watched channels.
* View VODs
* Custom layouts: User adjustable colors and columns
* VOD support
* Get notified when a channel you watch comes online
* Music identification (uses twitchecho.com)
* Sync your followed accounts to a local sqlite database that does not judge you.
* Stream as many... streams as you want at once.
* Stream multiple... streams at once.
* Integration with your conky instance.
* The ability to display alternate names for games / streamers. If your happiness is somehow contingent upon displaying "Hearthstone: Heroes of Warcraft" as "Wizard Poker", well, you've come to the right place.

## Installation
Expand All @@ -32,24 +32,27 @@ https://aur.archlinux.org/packages/twitchy-git
[OPTIONS]
-h, --help This helpful message
-a <channel name> Add channel(s)
-an Set/unset alternate names
-an [*searchstring*] Set/unset alternate names
--configure Configure options
--conky [ go / csvnames ] Generate data for conky
-d Delete channel(s) from database
-d [*searchstring*] Delete channel(s) from database
-f Check which of your favorite channels are online
-n Notify if a channel comes online
-n [*searchstring*] Notify if a channel comes online
--reset Delete everything and start over
-s <username> Sync followed channels from specified account
--update Update to the latest git revision
-v <channel name> Watch channel's recorded videos
-w <channel name> Watch specified channel(s)

First run:
Will create both the database and an editable config file in ~/.config/twitchy

While playing:
<m> to attempt music identification with twitchecho
<q> to quit
<q / Ctrl + C> to quit

Notification settings:
When a channel comes online, the script will play alarm.mp3 (in the same directory as itself).
While the path of the file is hardcoded, feel free to replace it with whatever you find (in)appropriate.
While the path of the file is hardcoded, feel free to replace it with whatever you find appropriate.

Conky options. Execute script with:
--conky Now playing
Expand All @@ -62,20 +65,21 @@ https://aur.archlinux.org/packages/twitchy-git
Using no argument while launching the script will check the status of every channel in the local database:
![alt tag](https://i.imgur.com/1Id6J7G.png)

Add "bobross" to local database:
Add channels to local database:

$ twitchy -a bobross
$ twitchy -a bobross <channel2> <channel3> ...
$ twitchy -s <your twitch username>

Display all strings matching *obr*:

$ twitchy obr
Checking channels...
Creative
1 bobross 80085 The Joy of Painting Monday Season 7 Marathon #painting...
1 bobross 80085 The Joy of Painting Monday Season 7 Marathon #painting...
Sonic: Generations
2 mariobro 123 #WhereMuhPrincessAt?
2 mariobro 123 #WhereMuhPrincessAt?
Wizard Poker
3 flatulentcobra 6969 Playing secret Paladin. Killing a puppy later.
3 flatulentcobra 6969 Playing secret Paladin. Killing a puppy later.
Channel number(s): 1-h 2-s 3-l

Custom quality settings: Specify with hyphen next to channel number.
Expand All @@ -86,7 +90,5 @@ Watch specified channel(s) - Do not have to be in local database:
$ twitchy -w northernlion cobaltstreak
Checking channels...
The Binding of Isaac: Afterbirth
1 northernlion 5757 Egg
Offline
x cobaltstreak
1 northernlion 5757 Egg
Channel number(s): 1
88 changes: 45 additions & 43 deletions twitchy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Requires: python3, livestreamer, requests
# rev = 130
# rev = 133


import sys
Expand All @@ -23,6 +23,7 @@
from os import remove, makedirs
from os.path import expanduser, exists, realpath, dirname


# Color code declaration for initial configuration and Options
class Colors:
CYAN = '\033[96m'
Expand Down Expand Up @@ -101,20 +102,20 @@ def configure_options():
check_interval = int(check_int)

print('\n' + Colors.CYAN + ' Current Settings:' + Colors.ENDC)
penultimate_check = (' Backend: {6}\n'
' Media Player: {0}\n'
' Default Quality: {1}\n'
' Truncate status at: {2}\n'
' Number of faves: {3}\n'
' Display chat for multiple streams: {4}\n'
' Check interval: {5}').format(
Colors.YELLOW + player + Colors.ENDC,
Colors.YELLOW + default_quality + Colors.ENDC,
Colors.YELLOW + str(truncate_status_at) + Colors.ENDC,
Colors.YELLOW + str(number_of_faves_displayed) + Colors.ENDC,
Colors.YELLOW + str(display_chat_for_multiple_twitch_streams) + Colors.ENDC,
Colors.YELLOW + str(check_interval) + Colors.ENDC,
Colors.YELLOW + backend + Colors.ENDC)
penultimate_check = (' Backend: {6}\n'
' Media Player: {0}\n'
' Default Quality: {1}\n'
' Truncate status at: {2}\n'
' Number of faves: {3}\n'
' Display chat for multiple streams: {4}\n'
' Check interval: {5}').format(
Colors.YELLOW + player + Colors.ENDC,
Colors.YELLOW + default_quality + Colors.ENDC,
Colors.YELLOW + str(truncate_status_at) + Colors.ENDC,
Colors.YELLOW + str(number_of_faves_displayed) + Colors.ENDC,
Colors.YELLOW + str(display_chat_for_multiple_twitch_streams) + Colors.ENDC,
Colors.YELLOW + str(check_interval) + Colors.ENDC,
Colors.YELLOW + backend + Colors.ENDC)

print(penultimate_check)

Expand Down Expand Up @@ -144,6 +145,7 @@ def configure_options():
except KeyboardInterrupt:
exit()


def write_to_config_file(options_from_wizard):
player = options_from_wizard[0]
mpv_hardware_acceleration = options_from_wizard[1]
Expand Down Expand Up @@ -197,14 +199,14 @@ def write_to_config_file(options_from_wizard):
'[CHAT]\n'
'Enable = True\n'
'EnableForMultiTwitch = {7}\n'.format(
backend,
player,
mpv_hardware_acceleration,
default_quality,
truncate_status_at,
number_of_faves_displayed,
check_interval,
display_chat_for_multiple_twitch_streams))
backend,
player,
mpv_hardware_acceleration,
default_quality,
truncate_status_at,
number_of_faves_displayed,
check_interval,
display_chat_for_multiple_twitch_streams))

with open(config_path, 'w') as config_file:
config_file.write(config_string)
Expand Down Expand Up @@ -273,27 +275,26 @@ class Options:
if default_quality not in ['low', 'medium', 'high', 'source']:
default_quality = 'high'

video = dict(backend = backend,
default_quality = default_quality,
player_final = player_final)
video = dict(backend=backend,
default_quality=default_quality,
player_final=player_final)

# Which columns to display
columns_section = config['COLUMNS']
columns = dict(column1 = columns_section.get('Column1', 'ChannelName'),
column2 = columns_section.get('Column2', 'Viewers'),
column3 = columns_section.get('Column3', 'StreamStatus'))
columns = dict(column1=columns_section.get('Column1', 'ChannelName'),
column2=columns_section.get('Column2', 'Viewers'),
column3=columns_section.get('Column3', 'StreamStatus'))

# Display options
display_section = config['DISPLAY']
sort_by = display_section.get('SortBy', 'GameName')
if sort_by not in ['1', '2', '3', 'GameName']:
sort_by = 'GameName'
display = dict(sort_by = sort_by,
column_names = display_section.getboolean('ColumnNames', False),
truncate_status = display_section.getint('TruncateStatus', 0),
faves_displayed = display_section.getint('NumberOfFaves', 10),
check_interval = display_section.getint('CheckInterval', 60))

display = dict(sort_by=sort_by,
column_names=display_section.getboolean('ColumnNames', False),
truncate_status=display_section.getint('TruncateStatus', 0),
faves_displayed=display_section.getint('NumberOfFaves', 10),
check_interval=display_section.getint('CheckInterval', 60))

# How to color everything
colors_section = config['COLORS']
Expand Down Expand Up @@ -324,19 +325,19 @@ class Options:
'end': '\033[0m'}

try:
colors = dict(numbers = escape_codes[numbers],
game_name = escape_codes[game_name],
column1 = escape_codes[column1],
column2 = escape_codes[column2],
column3 = escape_codes[column3])
colors = dict(numbers=escape_codes[numbers],
game_name=escape_codes[game_name],
column1=escape_codes[column1],
column2=escape_codes[column2],
column3=escape_codes[column3])
except KeyError:
print(Colors.RED + ' You know it\'s possible you don\'t know how to spell the names of colors.' + Colors.ENDC)
raise

# When do we want to display chat
chat_section = config['CHAT']
chat = dict(enable = chat_section.getboolean('Enable', True),
for_multi_twitch = chat_section.getboolean('EnableForMultiTwitch', False))
chat = dict(enable=chat_section.getboolean('Enable', True),
for_multi_twitch=chat_section.getboolean('EnableForMultiTwitch', False))

# Required only at runtime in case values for a conky instance are needed
conky_run = False
Expand Down Expand Up @@ -522,7 +523,7 @@ def read_modify_deletefrom_database(channel_input, whatireallywant_ireallyreally

if i[1] == 0:
print(' ' + Options.colors['numbers'] + str(display_number).rjust(total_streams_digits) + Colors.ENDC + ' '
+ template.format(i[0],Colors.CYAN + str(i[2]) + Colors.RED, ' Unwatched' + Colors.ENDC))
+ template.format(i[0], Colors.CYAN + str(i[2]) + Colors.RED, ' Unwatched' + Colors.ENDC))
else:
time_watched = time_convert(i[1]).rjust(11)
print(' ' + Options.colors['numbers'] + str(display_number).rjust(total_streams_digits) + Colors.ENDC + ' '
Expand Down Expand Up @@ -1224,6 +1225,7 @@ def nuke_it_from_orbit():
print('Are you sure you want to remove the database and start over?')
confirm = input('Please type ' + Colors.RED + 'KappaKeepoPogChamp' + Colors.ENDC + ' to continue: ')
if confirm == 'KappaKeepoPogChamp':
remove(config_path)
remove(database_path)


Expand Down

0 comments on commit 478dddf

Please sign in to comment.