-
Notifications
You must be signed in to change notification settings - Fork 3
/
iptvScraper.py
66 lines (51 loc) · 1.61 KB
/
iptvScraper.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
from bs4 import BeautifulSoup
import requests
from xml.etree.ElementTree import Element, SubElement
from xml.etree import ElementTree
from xml.dom import minidom
def getWebSite(url):
r = requests.get(url)
return r.text
def getIptvs(webSite):
text = BeautifulSoup(webSite, 'html.parser').body.text
splittedText = text.split('#EXTINF:-1,')
splittedText.pop(0) # b'#EXTM3U
splittedText.pop()
return removeEndComma(splittedText)
def removeEndComma(list):
iptvs = []
for element in list:
iptvs.append(element.replace('\n', ',')[:-1])
return iptvs
def printList(list):
for element in list:
print(element.encode('utf-8'))
def generateF4m(iptvs):
streamingInfos = Element('streamingInfos')
for iptv in iptvs:
data = iptv.split(',')
item = SubElement(streamingInfos, 'item')
title = SubElement(item, 'title')
title.text = data[0]
link = SubElement(item, 'link')
link.text = "plugin://plugin.video.f4mTester/?streamtype=TSDOWNLOADER&url=" + data[1]
thumbnail = SubElement(item, 'thumbnail')
thumbnail.text = "imagehere"
return prettify(streamingInfos)
def prettify(elem):
"""Return a pretty-printed XML string for the Element.
"""
rough_string = ElementTree.tostring(elem, 'utf-8')
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=" ").encode('utf-8')
def writeIntoFile(fileName, content):
f = open(fileName, 'wb')
f.write(content)
f.close()
url = 'http://iptv.filmover.com/iptv-italian-and-french-playlist/'
webSite = getWebSite(url)
iptvs = getIptvs(webSite)
printList(iptvs)
f4mContent = generateF4m(iptvs)
#print(f4mContent)
writeIntoFile('result.xml', f4mContent)