-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChurch.py
More file actions
114 lines (87 loc) · 3.01 KB
/
Copy pathChurch.py
File metadata and controls
114 lines (87 loc) · 3.01 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
#! /usr/bin/python3
from __future__ import unicode_literals
import youtube_dl
import requests
import shutil
from urllib.request import urlopen
from bs4 import BeautifulSoup
channel_no = 0
m3u = None
def get_live_info(channel_id):
try:
webpage = urlopen(f"https://www.youtube.com/{channel_id}/live").read()
soup = BeautifulSoup(webpage, 'html.parser')
urlMeta = soup.find("meta", property="og:url")
if urlMeta is None:
return None
url = urlMeta.get("content")
if(url is None or url.find("/watch?v=") == -1):
return None
titleMeta = soup.find("meta", property="og:title")
imageMeta = soup.find("meta", property="og:image")
descriptionMeta = soup.find("meta", property="og:description")
return {
"url": url,
"title": titleMeta.get("content"),
"image": imageMeta.get("content"),
"description": descriptionMeta.get("content")
}
except Exception as e:
return None
banner = r'''
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=5400000
'''
def generate_youtube_tv():
global channel_no
ydl_opts = {
'format': 'best',
}
ydl = youtube_dl.YoutubeDL(ydl_opts)
with open('Church.txt') as f:
lines = f.readlines()
for line in lines:
line = line.strip()
if line == "":
continue
channel = get_live_info(line)
if channel is None:
continue
try:
with ydl:
result = ydl.extract_info(
f"https://www.youtube.com/{line}/live",
download=False # We just want to extract the info
)
if 'entries' in result:
# Can be a playlist or a list of videos
video = result['entries'][-1]
else:
# Just a video
video = result
video_url = video['url']
channel_no += 1
channel_name = f"{channel_no}-{line.split('/')[-1]}"
playlistInfo = f"#EXTINF:-1 tvg-chno=\"{channel_no}\" tvg-id=\"{line}\" tvg-name=\"{channel_name}\" tvg-logo=\"{channel.get('image')}\" group-title=\"ARGENTINA\",{channel.get('title')}\n"
write_to_playlist(video_url)
write_to_playlist("\n")
except Exception as e:
print(e)
def write_to_playlist(content):
global m3u
m3u.write(content)
def create_playlist():
global m3u
m3u = open("Church.m3u8", "w")
m3u.write("#EXTM3U")
m3u.write("\n")
def close_playlist():
global m3u
m3u.close()
def generate_youtube_PlayList():
create_playlist()
m3u.write(banner)
generate_youtube_tv()
close_playlist()
if __name__ == '__main__':
generate_youtube_PlayList()