Srikanth Mani
Published © GPL3+

GUI Remote Control for VLC - Telnet Interface - Updated

GUI remote control to control VLC Telnet interface using Python. Written using Tkinter GUI

IntermediateWork in progress3 hours1,814
GUI Remote Control for VLC - Telnet Interface - Updated

Things used in this project

Story

Read more

Code

Main Python Program

Python
Main application program
from tkinter import *
from tkinter import filedialog
from vlcclient import VLCClient
import time
import socket
from kodijson import Kodi,PLAYER_VIDEO
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.tools import argparser
from list_tracker import ListTracker
import pafy

DEVELOPER_KEY = <enter your google api to acess youtube function>
YOUTUBE_API_SERVICE_NAME = 'youtube'
YOUTUBE_API_VERSION = 'v3'
global ready_for_next
global vlc
global ir
global vlc_active

def play_pause() :
 global ir
 global vlc
 global vlc_active
 if kodi_active == 1:
        players = kodi.Player.GetActivePlayers()
        if players["result"]==[]:
            print("There is nothing playing")
        else:
            playid=players["result"][0]["playerid"]
            if pp_bt["text"] == 'Pause' :
               kodi.Player.PlayPause({"playerid": playid,"play": False})
               pp_bt.configure(text='Play')
            elif pp_bt["text"] == 'Play' :
               kodi.Player.PlayPause({"playerid": playid,"play": True})
               pp_bt.configure(text='Pause')
 elif vlc_active == True :
       t_txt= vlc.raw('status').decode()
       title = t_txt[8:(len(t_txt))-1]
       index = title.find(')')
       t_txt = (title[12:index]).strip()
       if t_txt == "" :
         current_file = ir.current()
         if current_file :
           vlc.add(current_file)
#       i = vlc.raw('is_playing').decode()
       if pp_bt["text"] == 'Pause' :
          vlc.pause()
          pp_bt.configure(text='Play')
       else:
          vlc.play()
          pp_bt.configure(text='Pause')

def stop_play() :
 global vlc
 global vlc_active
 if vlc_active == True :
    pp_bt.configure(text='Play')
    vlc.stop()

def open_file() :
 global ir
 global vlc
 global vlc_active
 fname = filedialog.askopenfilename(parent=top,title="Select file", initialdir="/media/Data00/Audio",filetypes=(("Audio files", "*.mp3"),("All files", "*.*")))
 if fname != None :
    if kodi_active == 1 :
          fname = fname.replace('media','storage',1)
          kodi.Player.open(item={"file":fname})
    else :
          if vlc_active == True:
           ir.addfile(fname)
 else :
   print ("No file selected")

def open_playlist() :
 global ir
 global vlc
 global vlc_active
 fname = filedialog.askopenfilename(parent=top,title="Select file", initialdir="/media/minipc/plist",filetypes=(("Audio files", "*.pls"),("All files", "*.*")))
 if fname != None :
  if vlc_active == True :
   if fname[-4:] == '.pls' :
      with open(fname) as f:
       content = f.read().splitlines()
      vlc.clear()
      for i in range(len(content)):
       ir.addfile(content[i])
 else :
  print ("No file selected")

def clear_playlist() :
   global ir
   global vlc
   global vlc_active
   if vlc_active == True:
       vlc.clear()
       ir.clear()

def prev_playlist() :
 global ir
 global vlc
 global vlc_active
 if kodi_active == 1:
        players=kodi.Player.GetActivePlayers()
        playid=players["result"][0]["playerid"]
        kodi.Player.GoTo({"playerid":playid,"to":"previous"})
 elif vlc_active == True:
      p_st =ir.prev()
      if p_st :
           vlc.add(p_st)

def next_playlist() :
 global ir
 global vlc
 global vlc_active
 if kodi_active == 1:
        players=kodi.Player.GetActivePlayers()
        playid=players["result"][0]["playerid"]
        kodi.Player.GoTo({"playerid":playid,"to":"next"})
 elif vlc_active == True:
      n_st = ir.next()
      if n_st :
        vlc.add(n_st)

def volume() :
 global vlc
 global vlc_active
 val = int(sb_txt.get())
 if kodi_active == 1:
    kodi.Application.SetVolume(val)
 elif vlc_active == True:
  vlc.volume((val/100) * 256)

def seek_file() :
 global vlc
 global vlc_active
 val = int(sb_txt.get())
 if vlc_active == True:
  ml = int(vlc.raw('get_length'))
  mm = (ml * (val/100))
  vlc.seek(int(mm))

def donothing() :
  print("file selected")

def vlc_fullscreen() :
 global vlc
 if fc.get() :
  vlc.set_fullscreen(True)
 else :
  vlc.set_fullscreen(False)

def call_view() :
 global ir
 p_list = ir.list_all()
 listNodes.delete(0,'end')
 if sp.get() and len(p_list) > 0:
  for x in range(len(p_list)):
    listNodes.insert(END, p_list[x])
  pl_wind.deiconify()
  listNodes.selection_set(ir.current_index());
 elif not sp.get() :
   pl_wind.withdraw()

def playlist_select(event):
 global ir
 global vlc
 x = listNodes.curselection()
 ir.set_current(x[0])
 vlc.add(ir.current())
# print (listNodes.get(x[0]))

def connect_to(args):
  global ir
  global vlc
  global vlc_active
  st = args.split(':')
  if st[0].startswith('Kodi') :
    kodi_url = 'http://'+st[1].strip()+':8080/jsonrpc'
    kodi = Kodi(kodi_url, "kodi", "kodi")
    top.title('Connected to '+st[0])
    kodi_active = 1
  else :
   vlc_server = st[1].strip()
   vlc=VLCClient(vlc_server)
   try:
    vlc.connect()
    vlc_active = True
#    print('Connected to %s successfully ' % vlc_server)
    top.title('Connected to '+st[0])
   except socket.error as msg:
    print("Not able to connect to VLC Server")
    top.title('Not Connected')
    vlc_active = False

def move_to(args):
  global ir
  global vlc
  global vlc_active
  st = args.split(':')
  isplay= int(vlc.raw('is_playing'))
  if isplay == 1:
     t_txt = str(vlc.status())
     title = t_txt[2:(len(t_txt))-1]
     index = title.find(')')
     t_txt = (title[12:index]).strip()
     cur_pos = int(vlc.raw('get_time').decode())
     print (cur_pos)
     vlc_server = st[1].strip() 
     vlc1=VLCClient(vlc_server)
     if isplay == 1:
           vlc.pause()
     try:
               vlc1.connect()
               vlc1.clear()
               vlc.stop()
               vlc.clear()
               vlc.disconnect()
               vlc1.disconnect()
               vlc = VLCClient(vlc_server)
               vlc.connect()
               vlc_active = True
               if isplay == 1:
                vlc.add(ir.current())
                time.sleep(3)
                #vlc.play()
                if cur_pos > 0:
                  vlc.seek(cur_pos)
               top.title('Connected to '+st[0])
     except socket.error as msg:
               print("Not able to connect to VLC Server")
               vlc.play()

def radio(args):
 global ir
 global vlc
 global vlc_active
 ta_link=['http://163.172.165.94:8000/;stream.mp3', 'http://s2.voscast.com:10616/;stream', 'http://prclive1.listenon.in:9948/;', 'http://media2.lankasri.fm/;', 'http://163.172.165.94:8012/;stream.mp3', 'http://sc1.streamingpulse.com:8084/stream', 'http://prclive1.listenon.in:9930/;', 'http://103.16.47.70:9555/;', 'http://listen.shoutcast.com/tamilsuperhits', 'http://live.tamilkuyilradio.com:8095/;stream/2','http://prclive1.listenon.in:9296/;stream.mp3','http://prclive1.listenon.in:8836/;stream.mp3', 'http://prclive1.listenon.in:8816/;stream.mp3', 'http://prclive1.listenon.in:8332/;stream.mp3', 'http://prclive1.listenon.in:8324/;stream.mp3',"http://212.83.138.48:8332/;","http://212.83.138.48:8328/;","http://212.83.138.48:8340/;","http://sc.cobrasoftwares.in:8012/;","http://212.83.138.48:8090/;","http://212.83.138.48:8336/;","http://prclive1.listenon.in:9936/;","http://prclive1.listenon.in:8836/;","http://prclive1.listenon.in:8816/;","http://prclive1.listenon.in:9948/;","http://prclive1.listenon.in:9930/;","http://212.83.138.48:8344/;","http://chennai.spicefm.in:8000/spice_b","http://212.83.138.48:8094/;","http://212.83.138.48:8348/;","http://equinox.shoutca.st:9950/stream128","http://212.83.138.48:8305/;","http://66.55.145.43:7364/stream","http://212.83.138.48:8360/;","http://209.133.216.3:7048/stream","http://www.radio99.lk:8000/;","http://shaincast.caster.fm:47830/listen.mp3","http://220.247.227.51:8000/stream","http://sooriyanfm.asiabroadcasting.stream:7071/;","http://sunfm.asiabroadcasting.stream:7058/;","http://cdn2.streamcase.net:8010/live.mp3","http://s3.voscast.com:8402/;"]
 te_link=['http://184.154.202.243:8310/stream', 'http://174.37.252.208:8530/;stream.mp3', 'http://fmout.spicefm.in:8000/spice_b', 'http://stream.radiojar.com/265xy1sdxwwtv/;', 'http://50.7.99.163:11091/;', 'http://173.203.133.187:9700/;']
 hi_link=['http://64.71.79.181:5124/;stream/1','http://50.7.77.115:8174/;','http://50.7.68.251:7064/;stream/1','http://198.178.123.2:9484/;stream/1','http://69.4.230.78:9000/;','http://158.69.227.214:8021/;','http://208.115.222.203:9960/;','http://67.212.165.106:8022/;']

 if vlc_active == True:
   if args == 'tamil' :
     vlc.clear()
#     for i in range(len(ta_link)):
#        vlc.enqueue(ta_link[i])
     ir = ListTracker(ta_link)
     vlc.add(ir.current())
#    vlc.play()
   if args == 'telugu' :
     vlc.clear()
     ir = ListTracker(te_link)
     vlc.add(ir.current())
   if args == 'hindi' :
     vlc.clear()
     ir = ListTracker(hi_link)
     vlc.add(ir.current())

def youtube_media() :
  global ir
  global vlc
  print (se_text_value.get())
  p_list = get_api_youtube_data(se_text_value.get())
  ir = ListTracker(p_list)
  vlc.add(ir.current())

def get_api_youtube_data(phrase):
 global ir
 global vlc
 numidx=phrase.find(";")
 if numidx > 0 :
    numqry= phrase[numidx:]
    track=phrase.replace(numqry,"",1)
    track=track.strip()
 else :
    numqry = 'any'
    track = phrase.strip()
 if len(numqry) > 1 :
    numqry=numqry.replace(";","",1)
 if track.startswith('playlist:'):
    search_string = (track.replace('playlist:','',1)).strip()
    fullurl,ids = youtube_search(search_string,2,numqry)
 elif track.startswith('channel:'):
    search_string = (track.replace('channel:','',1)).strip()
    fullurl,ids = youtube_search(search_string,3,numqry)
 else :
    fullurl,ids = youtube_search(track,1,numqry)
# print(len(fullurl))
 vlc.clear()
 t_pl=[]
 print (chk_audio_value.get())
 for i in range(len(fullurl)):
   if chk_audio_value.get() == 1:
      vid = pafy.new(fullurl[i])
      ba = vid.getbestaudio()
      t_pl.append(ba.url)
   else:
      vid = pafy.new(fullurl[i])
      ba = vid.getbestvideo()
      t_pl.append(ba.url)
 return t_pl
#    vlc.enqueue(fullurl[i])
# if i > 0 :
#  vlc.play()

#Function to search YouTube and get videoid
def youtube_search(query,knd,media_len):
  youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
    developerKey=DEVELOPER_KEY)

  req=query
  # Call the search.list method to retrieve results matching the specified
  # query term.
  if knd == 3 :
     search_response = youtube.search().list(
       q=query,
       part='id,snippet',
       type='channel',
       maxResults=25
     ).execute()
  elif knd == 2 :
     search_response = youtube.search().list(
       q=query,
       part='id,snippet',
       type='playlist',
       maxResults=25
     ).execute()
  else :
     search_response = youtube.search().list(
       q=query,
       part='id,snippet',
       type='video',
       maxResults=25,
       videoDuration=media_len,
     ).execute()

  videos = []
  channels = []
  playlists = []
  videoids = []
  channelids = []
  playlistids = []
  urlid = []
  YouTubeURL = []

  # Add each result to the appropriate list, and then display the lists of
  # matching videos, channels, and playlists.

  for search_result in search_response.get('items', []):

    if search_result['id']['kind'] == 'youtube#video':
      videos.append('%s (%s)' % (search_result['snippet']['title'],
                                 search_result['id']['videoId']))
      videoids.append(search_result['id']['videoId'])

    elif search_result['id']['kind'] == 'youtube#channel':
      channels.append('%s (%s)' % (search_result['snippet']['title'],
                                   search_result['id']['channelId']))
      channelids.append(search_result['id']['channelId'])

    elif search_result['id']['kind'] == 'youtube#playlist':
      playlists.append('%s (%s)' % (search_result['snippet']['title'],
                                    search_result['id']['playlistId']))
      playlistids.append(search_result['id']['playlistId'])

  #Results of YouTube search. If you wish to see the results, uncomment them
  #print 'Videos:\n', '\n'.join(videos), '\n'
  #print 'Channels:\n', '\n'.join(channels), '\n'
  #print 'Playlists:\n', '\n'.join(playlists), '\n'

  #Checks if your query is for a channel, playlist or a video and changes the URL accordingly
  if knd == 3 and len(channels)!=0:
     for i in range(len(channels)) :
      urlid.append(channelids[i])
      YouTubeURL.append("https://www.youtube.com/watch?v="+channelids[i])
  elif knd == 2 and len(playlists)!=0:
    for i in ranage(len(playlists)) :
      urlid.append(playlistids[i])
      YouTubeURL.append("https://www.youtube.com/watch?v="+playlistids[i])
  else:
    for i in range(len(videos)) :
      urlid.append(videoids[i])
      YouTubeURL.append("https://www.youtube.com/watch?v="+videoids[i])
  return YouTubeURL,urlid

def media_duration() :
# isplay = vlc.raw('is_playing').decode()
 global ir
 global vlc
 global vlc_active
 global ready_for_next
 if vlc_active == True :
  vlc_status = vlc.raw('status').decode()
 else :
  vlc_status = 'not connected'
  vlc_active = False
  top.title('Not Connected')

 if "state playing" in vlc_status :
  isplay = 1
  pp_bt.configure(text='Pause')
 else :
  isplay=0
  pp_bt.configure(text='Play')
 if isplay == 1:
  try :
    ct = int(vlc.raw('get_time').decode())
  except ValueError as ex:
     ct = -1
  sec = ct % 60
  if ct > 60 :
   min = (( ct - sec) / 60)
  else :
   min = 0

  if min > 60 :
    mm = int(min % 60)
    hrs = int((( min - mm) /60))
  else :
    mm = int(min)
    hrs = 0
  e_tim = '%02d:%02d:%02d' %(hrs,mm,sec)
  try :
    tt =int(vlc.raw('get_length').decode())
  except ValueError as ex:
     tt = -1
  sec = tt % 60
  if tt > 60 :
   min = int((( tt - sec) / 60))
  else :
   min = 0

  if min > 60 :
    mm = int(min % 60)
    hrs = int(( min - mm) /60)
  else :
    mm = int(min)
    hrs = int(0)
  if ((tt - ct) < 3 and (tt != -1) and (ct != -1)):
    ready_for_next = 1
  else :
   ready_for_next = 0

  t_len = '%02d:%02d:%02d' %(hrs,mm,sec)
  time_text.delete("1.0","insert")
  time_text.insert(INSERT,(e_tim +" / "+t_len),"center")
  t_txt= vlc.raw('status').decode()
  title = t_txt[8:(len(t_txt))-1]
  index = title.find(')')
  t_txt = 'Media : ' +(title[12:index]).strip()
  status.configure(text=t_txt)
 if ready_for_next == 1:
   next_stream = ir.next()
   if next_stream :
    vlc.add(next_stream)
    vlc.play()
   ready_for_next = 0
 time_text.after(1000, media_duration)

top = Tk()
pl_wind=Toplevel()
sb_txt = IntVar()
se_text_value = StringVar()
fc = BooleanVar()
sp = BooleanVar()

menubar = Menu(top)
connectmenu = Menu(menubar,tearoff=0)
connectmenu.add_radiobutton(label="Midway - Audio Only",command=lambda: connect_to('Midway:192.168.1.72:a'))
connectmenu.add_radiobutton(label="Chromecast - Video enabled",command=lambda: connect_to('Chromecast:192.168.1.155:v'))
connectmenu.add_radiobutton(label="Laptop - Video enabled",command=lambda: connect_to('Laptop:192.168.1.222:v'))
connectmenu.add_radiobutton(label="pi Handheld - Video enabled",command=lambda: connect_to('Handheld:192.168.1.25:v'))
connectmenu.add_radiobutton(label="Broadcast - Audio enabled",command=lambda: connect_to('Broadcast:192.168.1.184:v'))
connectmenu.add_radiobutton(label="Headphone - Audio enabled",command=lambda: connect_to('Broadcast:192.168.1.156:a'))
connectmenu.add_separator()
connectmenu.add_radiobutton(label="Kodi 01",command=lambda: connect_to('Kodi 01:192.168.1.222'))
connectmenu.add_radiobutton(label="Kodi 02",command=lambda: connect_to('Kodi 02:192.168.1.222'))
menubar.add_cascade(label="Connect to",menu=connectmenu)
movemenu = Menu(menubar,tearoff=0)
movemenu.add_radiobutton(label="Midway - Audio Only",command=lambda: move_to('Midway:192.168.1.72:a'))
movemenu.add_radiobutton(label="Chromecast - Video enabled",command=lambda: move_to('Chromecast:192.168.1.155:v'))
movemenu.add_radiobutton(label="Laptop - Video enabled",command=lambda: move_to('Laptop:192.168.1.222:v'))
movemenu.add_radiobutton(label="pi Handheld - Video enabled",command=lambda: connect_to('Handheld:192.168.1.25:v'))
movemenu.add_radiobutton(label="Broadcast - Audio enabled",command=lambda: connect_to('Broadcast:192.168.1.184:a'))
movemenu.add_radiobutton(label="Headphone - Audio enabled",command=lambda: connect_to('Broadcast:192.168.1.156:a'))
menubar.add_cascade(label="Move Media to",menu=movemenu)
radiomenu = Menu(menubar,tearoff=0)
radiomenu.add_radiobutton(label="Tamil",command=lambda: radio('tamil'))
radiomenu.add_radiobutton(label="Telugu",command=lambda: radio('telugu'))
radiomenu.add_radiobutton(label="Hindi",command=lambda: radio('hindi'))
menubar.add_cascade(label="Internet Radio",menu=radiomenu)
othmenu = Menu(menubar,tearoff=0)
othmenu.add_command(label="Quit Program",command=lambda: top.destroy())
othmenu.add_checkbutton(label="VLC Full Screen",variable=fc,onvalue=True,offvalue=False,command=lambda: vlc_fullscreen())
othmenu.add_checkbutton(label="Show Playlist",variable=sp,onvalue=True,offvalue=False,command=lambda: call_view())
menubar.add_cascade(label="Options",menu=othmenu)
top.configure(background="#343434")
top.title("Main window")
top.geometry("480x300")
pl_wind.title("Playlist")
pl_wind.geometry("480x300")
pl_wind.protocol("WM_DELETE_WINDOW", pl_wind.withdraw)
listNodes = Listbox(pl_wind, width=51, height=10, font=("Helvetica", 12))
vscrollbar = Scrollbar(pl_wind, orient="vertical")
vscrollbar.config(command=listNodes.yview)
hscrollbar = Scrollbar(pl_wind, orient="horizontal")
hscrollbar.config(command=listNodes.xview)
hscrollbar.pack(side="bottom", fill="x")
listNodes.pack(side="left", fill="y")
vscrollbar.pack(side="right", fill="y")
listNodes.config(yscrollcommand=vscrollbar.set)
listNodes.config(xscrollcommand=hscrollbar.set)
listNodes.bind("<Double-Button-1>",playlist_select)

#Label(pl_wind,text="Playlist").pack()
top.config(menu=menubar)

status = Label(top, text="Current Media : ", bd=1, relief=SUNKEN, anchor=W)
status.pack(side=BOTTOM, fill=X)
tw=20
opl_bt = Button(top,text="Open PlayList",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=open_playlist)
opl_bt.place(x=tw,y=245)
top.update()
tw=(tw+opl_bt.winfo_width()+30)
ppl_bt = Button(top,text="Prev in Playlist",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=prev_playlist)
ppl_bt.place(x=tw,y=245)
top.update()
tw=(tw+opl_bt.winfo_width() + 30)
npl_bt = Button(top,text="Next in Playlist",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=next_playlist)
npl_bt.place(x=tw,y=245)
top.update()
tw=30
th= (245 - npl_bt.winfo_height()) -10
clq_bt = Button(top,text="Clear Queue",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=clear_playlist)
clq_bt.place(x=tw,y=th)
top.update()
th= (245 - npl_bt.winfo_height()) -10
tw=(tw+clq_bt.winfo_width() + 30)
opf_bt = Button(top,text="Open File",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=open_file)
opf_bt.place(x=tw,y=th)
top.update()
th= (245 - npl_bt.winfo_height()) -10
tw=(tw+opf_bt.winfo_width() + 30)
pp_bt = Button(top,text="Play",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=play_pause)
pp_bt.place(x=tw,y=th)
top.update()
th= (245 - npl_bt.winfo_height()) -10
tw=(tw+pp_bt.winfo_width() + 30)
sp_bt = Button(top,text="Stop",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=stop_play)
sp_bt.place(x=tw,y=th)
top.update()
th= (th - sp_bt.winfo_height()) -10
tw=90
vol_bt = Button(top,text="Volume(%)",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=volume)
vol_bt.place(x=tw,y=th)
top.update()
tw=(tw+vol_bt.winfo_width() + 30)
spn_box = Spinbox(top,width=10,from_=0,to=100,textvariable=sb_txt,bg="grey",fg="black",relief=RAISED,activebackground="blue")
spn_box.place(x=tw,y=th)
top.update()
tw=(tw+spn_box.winfo_width() + 30)
sk_bt = Button(top,text="Seek(%)",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=seek_file)
sk_bt.place(x=tw,y=th)
top.update()
th= (th - sk_bt.winfo_height()) -10
tw=50
ta_radio = Button(top,text="Tamil Radio",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=volume)
ta_radio.place(x=tw,y=th)
top.update()
tw=(tw+ta_radio.winfo_width() + 30)
te_radio = Button(top,text="Telugu Radio",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=volume)
te_radio.place(x=tw,y=th)
top.update()
tw=(tw+te_radio.winfo_width() + 30)
hi_radio = Button(top,text="Hindi Radio",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=volume)
hi_radio.place(x=tw,y=th)
scr_bar = Scrollbar(orient="horizontal")
se_text_value = StringVar()
se_text = Entry(top,textvariable=se_text_value,bd=5,fg="yellow",bg="grey",width=55,xscrollcommand=scr_bar.set)
se_text.place(x=10,y=10)
chk_audio_value = IntVar()
chk_audio = Checkbutton(top, text = "Audio Only", variable = chk_audio_value,onvalue = 1, offvalue = 0,selectcolor="blue",fg="yellow",bg="grey" )
chk_audio.place(x=10,y=40)
se_yt_bt = Button(top,text="Search in Youtube",bg="grey",fg="yellow",relief=RAISED,activebackground="blue",activeforeground="white",command=youtube_media)
se_yt_bt.place(x=318,y=40)
time_text=Text(top,height=1,width=20,bg="grey",fg="yellow",font=("Helvetica", 20),relief=FLAT)
time_text.place(x=75,y=75)
time_text.tag_configure("center", justify="center")
time_text.configure(highlightthickness=0)
time_text.insert(INSERT,"00:00:00 / 00:00:00","center")
global vlc
vlc=VLCClient("192.168.1.72")
try:
  vlc.connect()
  vlc_active = True
  kodi_active = 0
  top.title('Connected to Midway')
except socket.error as msg:
  print("Not able to connect to VLC Server")
  top.title('Media server Not Connected')
  vlc_active = False
  kodi_active = 0
ir = ListTracker()
ready_for_next=0
time_text.after(1000,media_duration)
pl_wind.withdraw()
top.mainloop()

List Tracker Module

Python
This modules handles the playlist
class ListTracker(object):
  def __init__(self,plist=[]) :
          self.plist = plist
          self.count = len(self.plist)
          self.cur = 0

  def list_all(self) :
     return self.plist
  
  def set_current(self,idx=0) :
   self.cur=idx

  def current_index(self) :
     return self.cur

  def total_count(self) :
    return self.count

  def current(self):
    if self.count > 0 :
      return self.plist[self.cur]
    else :
      return False

  def next(self):
     if self.cur == (self.count - 1):
       return False
     else :
       self.cur = self.cur + 1
       return self.plist[self.cur]

  def prev(self):
     if self.cur == 0:
       return False
     else :
       self.cur = self.cur - 1
       return self.plist[self.cur]

  def clear(self) :
      self.plist = []
      self.cur = 0
  
  def addfile(self,fname) :
      self.plist.append(fname)
      self.count = len(self.plist)

#links = ['One', 'Two', 'three', 'Four', 'Five','Six','Seven']
#ls = ListTracker(links)
#print('current' + ls.current())
#print('Next item' + ls.next())
#print('Next item' + ls.next())
#print('Previous item' + ls.prev())

Credits

Srikanth Mani

Srikanth Mani

2 projects • 1 follower
Thanks to Michael Mayr.

Comments