and_cesbo

Astra. Playlist for groups

Oct 24th, 2017
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. -- Script for Astra 5.63 and newer
  2. -- Save script to /etc/astra/mod/playlist.lua , and restart Astra
  3. --
  4. -- Create groups (category and group names for example):
  5. -- Open Settings -> Groups -> New Category
  6. -- Category Name : Genre
  7. -- Group Name : Music
  8. -- Press "Add Group" and append other groups Sport, Movie, etc...
  9. -- Press "Apply", then press "Streams"
  10. -- Select Music and check all channels related to this groups. Then select other group and check related channels
  11. --
  12. -- Link for playlist will be next:
  13. -- http://your-server:8000/playlist/Genre/Music.m3u8 - all music channels
  14. -- http://your-server:8000/playlist/Genre/Sport.m3u8 - all sport channels
  15. -- http://your-server:8000/playlist/Genre.m3u8 - all channels
  16.  
  17. function custom_playlist_m3u8(server, client, request)
  18.     if not request then
  19.         return nil
  20.     end
  21.  
  22.     local a = request.query.server
  23.     if not a then
  24.         a = request.headers["host"]
  25.         if not a then
  26.             server:abort(client, 400, "Server address is not defined")
  27.             return nil
  28.         end
  29.     end
  30.  
  31.     local q = request.request_uri:sub(#request.path + 1)
  32.     if http_play_hls then
  33.         q = "/index.m3u8" .. q
  34.     end
  35.  
  36.     local g = request.path:sub(1, #request.path - 5):sub(11):split("/")
  37.     local category = g[1]
  38.     local group = g[2]
  39.  
  40.     local content = "#EXTM3U\n"
  41.  
  42.     if not group then
  43.         for k,c in pairs(channel_list_ID) do
  44.             if c.config.groups and c.config.groups[category] ~= nil then
  45.                 content = content .. "#EXTINF:-1," .. c.config.name .. "\nhttp://" .. a .. "/play/" .. k .. q .. "\n"
  46.             end
  47.         end
  48.     else
  49.         for k,c in pairs(channel_list_ID) do
  50.             if c.config.groups and c.config.groups[category] == group then
  51.                 content = content .. "#EXTINF:-1," .. c.config.name .. "\nhttp://" .. a .. "/play/" .. k .. q .. "\n"
  52.             end
  53.         end
  54.     end
  55.  
  56.     server:send(client, {
  57.         code = 200,
  58.         headers = { "Content-Type: application/x-mpegurl", "Connection: close" },
  59.         content = content,
  60.     })
  61. end
  62.  
  63. control_server_instance:insert("/playlist/*", custom_playlist_m3u8)
Advertisement
Add Comment
Please, Sign In to add comment