-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiptv.lua
79 lines (72 loc) · 2.99 KB
/
iptv.lua
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
-- iptv.lua
-- v1.0.5
-- Combining free, frequently updated iptv sheets into one My.m3u, duplicate links removed
-- Launch: in cmdline Far.exe: lua:@iptv.lua, or lfjit.exe iptv.lua, or lflua.exe iptv.lua
-- replace the path with your own
local dir=win.GetEnv('APPDATA')..'\\IP-TV Player\\'
--local dir=win.GetEnv('TEMP')..'\\'
local fname=dir..'My.m3u'
-- list of links to free playlists
local urls={
--"http://help.a1.by/_files/TelecomTV/TelecomTVpacket/TVPACKET2.m3u",
"https://iptvm3u.ru/hdlist.m3u",
"http://iptvm3u.ru/onelist.m3u",
"https://smarttvnews.ru/apps/iptvchannels.m3u",
"https://smarttvnews.ru/apps/AutoIPTV.m3u",
"https://smarttvnews.ru/apps/freeiptv.m3u",
"https://webarmen.com/my/iptv/auto.nogrp.q.m3u"
}
local function fread(f) local x,h = nil,io.open(f,"rb") if h then x=h:read("*all") io.close(h) end return x end
local function fwrite(f,s) local x,h = nil,io.open(f,"wb") if h then x=h:write(s or "") io.close(h) end return x end
local function GetPage(x)
local s=""
if x then
if panel then panel.GetUserScreen() end
s=io.popen("curl.exe "..x,"rb"):read("*all")
if panel then panel.SetUserScreen() end
end
return s
end
local pgm,head = {},'#EXTM3U\n#EXTINF:-1,-= Update: '..os.date("%d.%m.%Y %H:%M")..' =-\nhttp://127.0.0.1/logo.png\n'
for j=1,#urls do
local i,s = 1,','..j..': '
local l=GetPage(urls[j]):gsub("#EXTGRP:[^\n]-\n",""):gsub(", +",",")
local name=urls[j]:match("/([^/]+)$")
fwrite(dir..name,l) -- save individual playlists
head=head..'#EXTINF:-1 '..s..name..'\nhttp://127.0.0.1/pls'..j..'.png\n'
for h,u in (l.."\n"):gmatch("(#EXTINF:[^\r\n]-)\r?\n(%w%w-://[^\r\n]-)\r?\n") do -- get channel's headers and urls
if h and u then table.insert(pgm,{i=i,h=h:gsub(' *,',s),u=u}) i=i+1 end
end
end
-- Adult filter
for i=#pgm,1,-1 do
local s=pgm[i].h:match(", -%d+: (.+)$")
if s then
local l=s:gsub("[ |]+"," "):gsub("^Q%d ",""):lower()
if l:find("18%+") or l:find("adult") or l:find("sex") or l:find("xxx") or l:find("porn") or l:find("traffic") then table.remove(pgm,i) end
end
end
table.sort(pgm,function(a,b) return a.u<b.u end) -- sort by urls
for i=#pgm,2,-1 do if pgm[i].u==pgm[i-1].u then table.remove(pgm,i) end end -- remove channel's duplicates
local function comp(x) -- HD channels => Top
local i,s = x:match(", -(%d+): (.+)$")
local p,q,l = "1","5",""
if i and s then
l=s:gsub("[ |]+"," "):gsub("^Q%d ",""):lower()..i
if l:find(" 4k") then q="0"
elseif l:find("uhd") then q="1"
elseif l:find("qhd") then q="2"
elseif l:find("fhd") then q="3"
elseif l:find("hd") then q="4"
end
end
return p..q..l
end
table.sort(pgm,function(a,b) return comp(a.h)<comp(b.h) end) -- sort by channel's name and playlist's number
fwrite(fname.."_",fread(fname)) -- backup old playlist
local h=io.open(fname,"wb") -- create new playlist
h:write(head)
h:close()
h=io.open(fname,"ab")
for i=1,#pgm do h:write(pgm[i].h..'\n'..pgm[i].u..'\n') end
h:close()