Skip to content

Commit 056334b

Browse files
committed
initial commit
1 parent 86f4e24 commit 056334b

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

MonstercatFMTwitch.py

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import socket
2+
import string
3+
import getpass
4+
import os
5+
import os.path
6+
import re
7+
8+
def header():
9+
print(" __ ___ __ __ ________ ___ ", end='')
10+
print(" / \/ /___ ____ _____/ /____ ______________ _/ /_ / ____/ \/ / ", end='')
11+
print(" / /\_/ / __ \/ __ \/ ___/ __/ _ \/ ___/ ___/ __ `/ __/ / /_ / /\_/ / ", end='')
12+
print(" / / / / /_/ / / / (__ ) /_/ __/ / / /__/ /_/ / /_ / __/ / / / / ", end='')
13+
print(" /_/ /_/\____/_/ /_/____/\__/\___/_/ \___/\__,_/\__/ /_/ /_/ /_/ ", end='\n')
14+
print("Created by thinkaliker [http://thinkaliker.com]", end='')
15+
print(" and rhoCode [http://rhocode.com]", end='')
16+
print("Source available on GitHub [http://github.com/thinkaliker/MCFMPython]", end='')
17+
print("////////////////////////////////////////////////////////////////////////////////")
18+
19+
def belowline():
20+
print("Songs will appear below.")
21+
print("================================================================================")
22+
23+
def styleprompt():
24+
print("Text output styles")
25+
print("----------------------")
26+
print(" [1] Artist // Song")
27+
print(" [2] Song // Artist")
28+
print(" [3] Artist - Song")
29+
print(" [4] Song - Artist")
30+
31+
def fileprompt():
32+
print("Enter your text file output location (Somewhere on C:\ recommended)")
33+
34+
song=""
35+
artist=""
36+
37+
header()
38+
39+
def styleSwitch(style):
40+
styles = {
41+
1 : (" " + artist + " // " + song + " "),
42+
2 : (" " + song + " // " + artist + " "),
43+
3 : (" " + artist + " - " + song + " "),
44+
4 : (" " + song + " - " + artist + " "),
45+
5 : (" " + artist.upper() + " // " + song.upper() + " "),
46+
6 : (" " + song.upper() + " // " + artist.upper() + " "),
47+
7 : (" " + artist.upper() + " - " + song.upper() + " "),
48+
8 : (" " + song.upper() + " - " + artist.upper() + " ")
49+
}
50+
return styles[style]
51+
52+
fileprompt()
53+
fileloc = input("File path: ")
54+
55+
if (os.path.isfile(fileloc)) != 1:
56+
print("File does not exist. Creating.")
57+
open(fileloc, 'w+')
58+
59+
NICK=input("Enter your username: ")
60+
61+
CHANNEL=input("Enter the channnel you would like to join (eg. Monstercat): ")
62+
CHANNEL="#" + CHANNEL
63+
64+
print("Right click and paste your oauth key beginning with \"oath:\""),
65+
PASSWORD=getpass.getpass('(hidden):')
66+
67+
68+
HOST="irc.twitch.tv"
69+
PORT=6667
70+
IDENT=NICK
71+
REALNAME=NICK
72+
73+
readbuffer=""
74+
75+
def sendIRC(stuff, t):
76+
t.send(stuff.encode('utf-8'))
77+
78+
print("Connecting...")
79+
s=socket.socket( )
80+
s.connect((HOST, PORT))
81+
sendIRC("PASS %s\r\n" % PASSWORD, s)
82+
sendIRC("NICK %s\r\n" % NICK, s)
83+
sendIRC("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME), s)
84+
sendIRC("JOIN %s\r\n" % CHANNEL, s)
85+
86+
substring=":[email protected] PRIVMSG " +CHANNEL+ " :Now Playing:"
87+
88+
styleprompt()
89+
90+
instyle = input("Style: ")
91+
style = int(instyle)
92+
caps = input("All caps? (y/n): ")
93+
if caps == "y":
94+
style = style + 4
95+
96+
songartist = styleSwitch(style)
97+
belowline()
98+
sendIRC("PRIVMSG " + CHANNEL + " :!song\r\n", s)
99+
currentsongartist=songartist
100+
init = 1
101+
102+
while 1:
103+
readbuffer=(s.recv(1024)).decode("utf-8")
104+
if readbuffer.find(substring) != -1:
105+
song, artist=re.search('Now Playing: (.*) by (.*) - Listen', readbuffer).groups()
106+
107+
songartist=styleSwitch(style)
108+
109+
if (init or currentsongartist != songartist):
110+
init = 0
111+
112+
print(songartist)
113+
f=open(fileloc, 'r+')
114+
f.seek(0)
115+
f.write(songartist)
116+
f.truncate()
117+
f.close()
118+
currentsongartist=songartist

start.bat

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@echo off
2+
title Monstercat FM Twitch Helper for Python
3+
echo Your Python installation path should be in your PATH variable.
4+
cls
5+
call python MonstercatFMTwitch.py
6+
echo Whoops! Something happened!

0 commit comments

Comments
 (0)