-
Notifications
You must be signed in to change notification settings - Fork 0
/
podcast_main.py
executable file
·137 lines (126 loc) · 4.59 KB
/
podcast_main.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
132
133
134
135
136
137
#!/usr/bin/python
from lib.base_podcast import emission, station
from lib.stations.radiofrance import *
from lib.stations.rtlfrance import *
from lib.stations.rtbf import *
from lib.stations.europe1 import *
from lib.stations.bbc import *
from lib.stations.vrt import *
import readline
import os
clear = lambda: os.system('clear')
allstationgroup=[BBC,RTL,Lagardere,RadioFrance,RTBF,VRT]
allstation={}
for group in allstationgroup:
for st in group.stations:
allstation[st.code]=st
def complete(text, state):
for cmd in list(allstation.keys()):
if cmd.startswith(text):
if not state:
return cmd
else:
state -= 1
readline.parse_and_bind("tab: complete")
readline.set_completer(complete)
def clearscreen():
os.system('cls' if os.name == 'nt' else 'clear')
def printglobheader():
print('---------------------------------------------')
print('| Radio Station stream and podcast browser |')
print('---------------------------------------------')
def printheader(chaine):
print('\n***************************')
print('* '+chaine)
print('***************************', end=' ')
def printstationlist():
for group in allstationgroup:
print(" - "+group.name+" group :\n\t", end=' ')
for st in group.stations:
if st.lso==True:
lss="*"
else :
lss=""
print(st.name+" ("+st.code+lss+') - ', end=' ')
print("\n")
print(" *live stream only station\n")
def main():
menu = {}
#menu['0']="list chaines"
menu['0']="podcast search"
menu['1']="list programmes"
menu['2']="list and play podcast"
# menu['3']="play podcast"
menu['3']="play station"
menu['4']="change station"
menu['5']="Exit"
while True:
options=list(menu.keys())
options.sort()
# os.system('cls' if os.name == 'nt' else 'clear')
clearscreen()
printglobheader()
print("\nChoose your station\n********************")
printstationlist()
# print ' - '.join(sorted(allstation.keys())) + " - 0 to exit"
chaine=input("station code (or exit):")
if chaine =='0' or chaine=="exit":
return 0
clearscreen()
try:
printheader(allstation[chaine].name)
except KeyError:
print("wrong selection")
continue
if allstation[chaine] in RTBF.stations :
options=[options[ii] for ii in (0,1,3,4,5)]
elif allstation[chaine].lso:
options=options[3:6]
else:
options=options[1:6]
while True:
query=""
print("\n")
for entry in options:
print(entry+") "+menu[entry]," ", end=' ')
selection=input("\nPlease Select action:")
#if selection =='0':
# print ' - '.join(allstation.keys())
if selection =='1':
if allstation[chaine].query :
query=input("query:")
allstation[chaine].listemissions(query)
elif selection == '2':
emissid=input("index programme:")
maxx=input("how many to display?")
if not hasattr(allstation[chaine],"emissions"):
if allstation[chaine].query :
query=input("query:")
allstation[chaine].fillemission(query)
allstation[chaine].emissions[int(emissid)].listpodcasts(int(maxx))
playapodcast=input("1) Play one 2) Leave to menu\nchoice:")
if playapodcast=='1':
podcastid=input("podcast index:")
allstation[chaine].emissions[int(emissid)].playpodcast(int(podcastid))
clearscreen()
printheader(allstation[chaine].name)
elif selection == '0':
if allstation[chaine].query :
query=input("query:")
allstation[chaine].searchpodcast(query)
elif selection == '3':
clearscreen()
printheader(allstation[chaine].name)
print("\n---- LIVE STREAMING -----\n hit q to stop \n")
allstation[chaine].playstation()
clearscreen()
printheader(allstation[chaine].name)
elif selection == '4':
break
elif selection == '5':
#break
return 0
else:
print("Unknown Option Selected!")
if __name__ == "__main__":
main()