forked from benmoose39/YouTube_to_m3u
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube_m3ugrabber.py
58 lines (53 loc) · 1.93 KB
/
youtube_m3ugrabber.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
#! /usr/bin/python3
banner = r''
import requests
import os
import sys
windows = False
if 'win' in sys.platform:
windows = True
def grab(url):
response = requests.get(url, timeout=15).text
if '.m3u8' not in response:
#response = requests.get(url).text
if '.m3u8' not in response:
if windows:
print('https://raw.githubusercontent.com/benmoose39/YouTube_to_m3u/main/assets/moose_na.m3u')
return
#os.system(f'wget {url} -O temp.txt')
os.system(f'curl "{url}" > temp.txt')
response = ''.join(open('temp.txt').readlines())
if '.m3u8' not in response:
print('https://raw.githubusercontent.com/benmoose39/YouTube_to_m3u/main/assets/moose_na.m3u')
return
end = response.find('.m3u8') + 5
tuner = 100
while True:
if 'https://' in response[end-tuner : end]:
link = response[end-tuner : end]
start = link.find('https://')
end = link.find('.m3u8') + 5
break
else:
tuner += 5
print(f"{link[start : end]}")
print('#EXTM3U x-tvg-url="https://github.com/botallen/epg/releases/download/latest/epg.xml"')
print(banner)
#s = requests.Session()
with open('youtube_channel_info.txt') as f:
for line in f:
line = line.strip()
if not line or line.startswith('~~'):
continue
if not line.startswith('https:'):
line = line.split('|')
ch_name = line[0].strip()
grp_title = line[1].strip().title()
tvg_logo = line[2].strip()
tvg_id = line[3].strip()
print(f'\n#EXTINF:-1 group-title="{grp_title}" tvg-logo="{tvg_logo}" tvg-id="{tvg_id}", {ch_name}')
else:
grab(line)
if 'temp.txt' in os.listdir():
os.system('rm temp.txt')
os.system('rm watch*')