-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVLC-tv-gui.py
131 lines (106 loc) · 4.16 KB
/
VLC-tv-gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# vlctv-gui.py
# November 20, 2020
import PySimpleGUI as sg
import requests
import vlc
import time
import os
import pickledb
tvdb = 'D:\\Dev\\Python\\VLC\\tv.db' #Change this to the location of your pickledb file
tvlist = ''
selected = False
previousvalue = 25
#Load pickledb with our channels
try:
db = pickledb.load(tvdb, False)
except:
print(f'Unable to open pickledb file at {tvdb}')
quit()
#Put db values into a list
db.lcreate(tvlist)
for value in db.getall():
db.ladd(tvlist, value)
allChannels = db.lgetall(tvlist)
#Function to play channel when called
def PlayChannel():
playlists = set(['pls','m3u'])
url = channel
try:
r = requests.get(url, stream=True)
found = r.ok
except ConnectionError as e:
print('failed to get stream: {e}'.format(e=e))
quit()
if found:
Media = Instance.media_new(url)
#Media_list = Instance.media_list_new([url])
Media.get_mrl()
player.set_media(Media)
if player.play() == -1:
print ("\nError playing Stream")
#Create new base instance of VLC
Instance = vlc.Instance()
player = Instance.media_player_new()
#Create layout for the GUI
layout = [
[sg.Text('Channels')],
[sg.Listbox(list(allChannels), size=(30,20), key='ChannelList', select_mode=sg.LISTBOX_SELECT_MODE_SINGLE, enable_events=False, visible=True), sg.Text('Volume', key='Volume', size=(6,1)),
sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=50, enable_events=True, key='VolumeSlider'),
sg.Checkbox('Mute', key='Mute', enable_events=True) ],
[sg.Button(' Select '), sg.Button(' Stop '), sg.Button(' Add '), sg.Button(' Exit ')],
[sg.Text('Name:', key='ChannelTitleText', size=(5,1), visible=False), sg.InputText('', key='ChannelTitle', size=(30,1), visible=False),
sg.Text('URL:', key='ChannelURLText', visible=False), sg.InputText('', key='ChannelURL', size=(30,1), visible=False)],
[sg.Button(' Add Channel ', visible=False), sg.Button(' Cancel ', visible=False)]
]
#Start the GUI
window = sg.Window('VLC-TV 2.01b', layout=layout, margins=(10,10), return_keyboard_events=True, finalize=True)
while True:
event, values = window.read()
if event in (' Exit ', None):
break
if event == ' Select ':
choice = values['ChannelList'][0]
channel = db.get(choice)
PlayChannel()
if event == ' Stop ':
player.stop()
if event == ' Add ':
window['ChannelTitleText'].update(visible=True)
window['ChannelTitle'].update(visible=True)
window['ChannelURLText'].update(visible=True)
window['ChannelURL'].update(visible=True)
window[' Add Channel '].update(visible=True)
window[' Cancel '].update(visible=True)
if event == ' Add Channel ':
channelname = ''
channelurl = ''
channelname = values['ChannelTitle']
#print(channelname)
channelurl = values['ChannelURL']
#print(channelurl)
if channelname and channelurl:
db.set(channelname, channelurl)
db.dump()
window['ChannelTitle'].update(value = '')
window['ChannelURL'].update(value = '')
if event == ' Cancel ':
channelname = ''
channelurl = ''
window['ChannelTitleText'].update(visible=False)
window['ChannelTitle'].update(visible=False)
window['ChannelURLText'].update(visible=False)
window['ChannelURL'].update(visible=False)
window[' Add Channel '].update(visible=False)
window[' Cancel '].update(visible=False)
volumelevel = int(values['VolumeSlider'])
player.audio_set_volume(volumelevel)
if event == 'Mute':
currentlevel = player.audio_get_volume()
if currentlevel == 1:
window['VolumeSlider'].update(value=previousvalue)
player.audio_set_volume(previousvalue)
if currentlevel > 1:
previousvalue = currentlevel
window['VolumeSlider'].update(value=1)
player.audio_set_volume(1)
window.close()