daffen

simple livestreamer

Sep 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. import webbrowser, os
  2. from Tkinter import *
  3.  
  4. class Twitcher:
  5.  
  6.     def __init__(self):
  7.         # Fetch a list with channels for the listbox from a file.
  8.         self.favs = open("favs.txt","r")
  9.         self.fav = self.favs.read().split()
  10.         self.lbHeight = len(self.fav)
  11.  
  12.         # Get your auth key at: http://www.twitchapps.com/tmi/
  13.         # And assign self.twitchAuth
  14.         self.twitchAuth = ""
  15.  
  16.     def init_window(self):
  17.         self.root = Tk()
  18.         self.root.title("Twitcher")
  19.         self.customStream = StringVar()
  20.  
  21.         # Frame
  22.         self.frame = Frame(self.root)
  23.         self.frame.pack(padx=20,pady=20)
  24.  
  25.         # Listbox
  26.         self.listbox = Listbox(self.frame, selectmode=SINGLE,height=self.lbHeight,width=35)
  27.         for self.n in self.fav:
  28.             self.listbox.insert(END, self.n)
  29.         self.listbox.pack()
  30.  
  31.         # Button
  32.         self.vlcButton = Button(self.frame, text="Open in vlc", command= lambda: self.runStream('vlc'))
  33.         self.vlcButton.pack(pady=10, side=LEFT)
  34.  
  35.         self.brButton = Button(self.frame, text="Open in Browser", command= lambda: self.runStream('browser'))
  36.         self.brButton.pack(pady=10,padx=10,side=LEFT)
  37.  
  38.         self.root.mainloop()
  39.  
  40.     def runStream(self,platform):
  41.         self.platform = platform
  42.         self.index = int(self.listbox.curselection()[0])
  43.         self.channel = self.listbox.get(self.index)
  44.  
  45.         if self.platform == 'browser':
  46.             webbrowser.open('http://twitch.tv/%s' % self.channel)
  47.         elif self.platform == 'vlc':
  48.             os.system("livestreamer --twitch-oauth-token %s twitch.tv/%s best &" % (self.twitchAuth,self.channel))
  49.  
  50. if __name__ == "__main__":
  51.     t = Twitcher()
  52.     t.init_window()
Add Comment
Please, Sign In to add comment