-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanForChannels.py
More file actions
executable file
·185 lines (131 loc) · 4.66 KB
/
Copy pathscanForChannels.py
File metadata and controls
executable file
·185 lines (131 loc) · 4.66 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python3
# Copyright 2018-2018 Mick Costello.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
import argparse
import requests
import sys
from bs4 import BeautifulSoup
g_tvOnly = False
g_radioOnly = False
g_fullFormat = False
url = "http://en.kingofsat.net/freqs.php?&pos=28.2E&standard=all&ordre=freq&filtre=Clear"
def textValue(col):
for string in col.stripped_strings:
if len(string) > 0:
return '"{}"'.format(string)
return '""'
def multipleTextValues(col):
strings = []
for string in col.stripped_strings:
strings.append('"{}"'.format(string))
return strings
def intValue(col):
for string in col.stripped_strings:
if string.isdigit():
return string
return str(-1)
def saveTransponder(row):
try:
cols = row.find_all('td')
frequency = str(int(float(cols[2].text.strip())*1000))
polarity = textValue(cols[3]).lower()
standard = textValue(cols[6])
modulation = textValue(cols[7]).lower()
tmp = multipleTextValues(cols[8])
symbolRate = str(int(tmp[0].strip('"'))*1000)
fec = tmp[1]
networkId = intValue(cols[10])
transportId = intValue(cols[11])
if modulation.startswith("16APSK"):
modulation = "16APSK"
print('{}, {}, {}, {}, {}, {}, {}, {}'.format(
transportId,
networkId,
frequency,
symbolRate,
fec,
polarity,
modulation,
standard))
except:
return
def saveChannel(row):
try:
cols = row.find_all('td')
if cols[2].text.strip() == 'Name':
return
name = textValue(cols[2])
genre = textValue(cols[4])
serviceId = intValue(cols[7])
videoPid = intValue(cols[8])
audioPid = intValue(cols[9])
pmtPid = intValue(cols[10])
pcrPid = intValue(cols[11])
txtPid = intValue(cols[12])
if videoPid == '-1' and audioPid == '-1':
return
if g_tvOnly and videoPid == '-1':
return
if g_radioOnly and videoPid != '-1':
return
if g_fullFormat:
print('{:>20}, {:>10}, {:>5}, {:>5}, {:>5}, {:>5}, {:>5}, {:>5}'.format(
name,
genre,
serviceId,
videoPid,
audioPid,
pmtPid,
pcrPid,
txtPid))
else: # MythTV
print(' {:>5}, {:>5}'.format(
name,
serviceId))
except:
return
def main():
global g_tvOnly, g_radioOnly, g_fullFormat
parser = argparse.ArgumentParser(description='Scan KingOfSat for TV/Radio channels.')
parser.add_argument('-t', '--tvOnly', default=False, action='store_true', help='Scan for TV channels only.')
parser.add_argument('-r', '--radioOnly', default=False, action='store_true', help='Scan for Radio channels only.')
parser.add_argument('-f', '--fullFormat', default=True, action='store_true', help='Output in full format (include PIDs).')
args = parser.parse_args()
g_tvOnly = args.tvOnly
g_radioOnly = args.radioOnly
g_fullFormat = args.fullFormat
print()
print('# transportId, networkId, frequency, symbolRate, fec, polarity, modulation, standard')
if g_fullFormat:
print('# name, genre, serviceId, videoPid, audioPid, pmtPid, pcrPid, txtPid')
else:
print('# name, serviceId')
print()
page = requests.get(url)
soup = BeautifulSoup(page.text, "lxml")
tables = soup.find_all('table', {"class":"frq"})
for table in tables[1:]:
transponder = table.find('tr')
saveTransponder(transponder)
div = table.find_next_sibling('div')
channels = div.find_all('tr')
for channel in channels:
saveChannel(channel)
print()
print()
return 0
if __name__ == '__main__':
sys.exit(main())