-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·156 lines (149 loc) · 5.48 KB
/
test.py
File metadata and controls
executable file
·156 lines (149 loc) · 5.48 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python3
import sys
import os
from optparse import OptionParser
from operator import itemgetter
from resources.lib.epg import get_iptv_epg
# parse the options
parser = OptionParser()
parser.add_option('-a', '--authorize', action='store_true', dest='authorize')
parser.add_option('-u', '--username', type='string', dest='username',
help='CBC username (default: $CBC_USERNAME)')
parser.add_option('-p', '--password', type='string', dest='password',
help='CBC password (default: $CBC_PASSWORD)')
parser.add_option('-b', '--browse', action='store_true')
parser.add_option('-f', '--format', action='store')
# ?
parser.add_option('-g', '--guide', action='store_true', dest='guide', help="run guide code")
parser.add_option('-l', '--live-programs', action='store_true', dest='progs')
parser.add_option('-i', '--iptv', action='store_true', dest='iptv', help="IPTV Channel List")
parser.add_option('-I', '--iptv-channel', type='string', dest='channel', help="IPTV Channel ID")
parser.add_option('-c', '--channels', action='store_true', dest='chans')
parser.add_option('-C', '--category', action='store', dest='category')
parser.add_option('-v', '--video', action='store_true', dest='video')
parser.add_option('-s', '--shows', action='store_true', dest='shows')
parser.add_option('-S', '--show', action='store')
parser.add_option('-e', '--episode', action='store')
(options, args) = parser.parse_args()
# Get username and password from environment if not provided via command line
if not options.username:
options.username = os.environ.get('CBC_USERNAME')
if not options.password:
options.password = os.environ.get('CBC_PASSWORD')
from resources.lib.livechannels import *
# from resources.lib.liveprograms import *
# from resources.lib.shows import *
from resources.lib.cbc import CBC
from resources.lib.gemv2 import GemV2
def progress(x):
print(x)
cbc = CBC()
chans = LiveChannels()
# events = LivePrograms()
# shows = Shows()
res = []
if options.authorize:
if not options.username or not options.password:
print('Error: Username and password required (use -u/-p or set CBC_USERNAME/CBC_PASSWORD)')
sys.exit(1)
if not cbc.azure_authorize(options.username, options.password, progress):
print('Error: Authorization failed')
sys.exit(1)
print('Authorization successful')
sys.exit(0)
if options.browse:
b = GemV2.get_browse()
if b is None:
print('None from get_browse')
sys.exit(1)
for a in b:
print(a)
sys.exit(0)
if options.format:
if options.format == "category/shows":
# b = GemV2.get_format('experience/olympics')
b = GemV2.get_format(options.format)
# 8 was Rosemary Barton Live
for i in range(0, len(b)):
# if b[i]['url'] == 'about-that-with-andrew-chang':
# break
if b[i]['url'] == 'rosemary-barton-live':
break
# i = 1
n = GemV2.normalized_format_item(b[i])
p = GemV2.normalized_format_path(b[i], options.format)
print(n)
b = GemV2.get_format(p)
# [2] is season 3
n = GemV2.normalized_format_item(b[0])
p = GemV2.normalized_format_path(b[0], p)
print(n)
b = GemV2.get_format(p)
n = GemV2.normalized_format_item(b[0])
p = GemV2.normalized_format_path(b[0], p)
print(n)
s = GemV2.get_stream(id=p, app_code=n['app_code'])
print(f"{s['type']} {s['url']}")
x = GemV2.get_stream_drm(s)
wv_url, wv_tok = GemV2.get_stream_drm(s)
print(wv_url)
print(wv_tok)
sys.exit(0)
if options.format == "section/sports":
b = GemV2.get_format(options.format)
n = GemV2.normalized_format_item(b[0])
# print(f'{n["label"]}')
p = GemV2.normalized_format_path(b[0], options.format)
b = GemV2.get_format(p)
# i think these are upcomming
idx = 0
n = GemV2.normalized_format_item(b[idx])
print(f'{n["label"]}')
p = GemV2.normalized_format_path(b[idx], p)
b = GemV2.get_format(p)
n = GemV2.normalized_format_item(b[0])
print(f'{n["label"]}')
p = GemV2.normalized_format_path(b[0], p)
s = GemV2.get_stream(id=p, app_code=n['app_code'])
print(f"{s['type']} {s['url']}")
x = GemV2.get_stream_drm(s)
wv_url, wv_tok = GemV2.get_stream_drm(s)
print(wv_url)
print(wv_tok)
sys.exit(0)
if options.guide:
get_iptv_epg()
elif options.iptv:
live = LiveChannels()
for channel in live.get_iptv_channels():
id, name = itemgetter('id', 'name')(channel)
print(f'{id} - {name}')
elif options.channel:
live = LiveChannels()
stream = live.get_channel_stream(options.channel)
print(stream)
elif options.chans:
res = chans.get_live_channels()
print(res)
elif options.progs:
res = events.getLivePrograms()
elif options.video:
try:
res = shows.getStream(args[0])
except CBCAuthError as e:
print('ERROR: login required' if e.payment else 'ERROR: Unauthorized')
sys.exit(1)
print(res)
sys.exit(0)
else:
print('\nPlease specify something to do\n')
parser.print_help()
sys.exit(1)
if 'categories' in res:
for category in res['categories']:
id, title, _ = category.values()
print(f'Category: {id} - {title}')
if 'shelves' in res:
for shelf in res['shelves']:
id, title, _, items = shelf.values()
print(f'Shelves: {id} - {title}')