From 61e7e5a3c61cde5cf250940cbff199cb7af32012 Mon Sep 17 00:00:00 2001 From: ELIO MILITE Date: Sun, 5 Nov 2023 20:05:30 +0100 Subject: [PATCH] fix player error occurred message --- src/components/Live/MainLive.js | 36 ++--- src/components/Login.js | 6 +- src/components/Player/Player.js | 21 ++- src/components/Vod/MainVod.js | 5 +- src/other/Player-github/player-github.js | 3 +- src/other/axios.js | 36 +++-- src/other/epg-database.js | 45 +++--- src/other/load-playlist.js | 174 ++++++++++++++--------- 8 files changed, 192 insertions(+), 134 deletions(-) diff --git a/src/components/Live/MainLive.js b/src/components/Live/MainLive.js index b88d244..5e0dfd2 100644 --- a/src/components/Live/MainLive.js +++ b/src/components/Live/MainLive.js @@ -46,29 +46,31 @@ const MainLive = () => { const [showPopup, setShowPopup] = useState(false); useEffect(()=>{ - setBlurBackground(((isNaN(category) || category === undefined) || history.location.pathname.includes("menu")) ? {filter:"blur(.5rem)", pointerEvents: "none"} : {}); - - if(category !== undefined){ - loadPlaylist("live",category).then(chs => { + const fun = async() => { + setBlurBackground(((isNaN(category) || category === undefined) || history.location.pathname.includes("menu")) ? {filter:"blur(.5rem)", pointerEvents: "none"} : {}); + + if(category != undefined && category != 0){ + let chs = await loadPlaylist("live",category) chs = chs || []; if(category==="fav") chs = chs.filter(x=> DB.findOne("live",x.stream_id,true)) dispatch(setPlaylist(chs)); if(chs.length === 0) setShowPopup(1) - }) - }else if(resetMemory("live")){ - loadGroup("live").then(gps => { - if(!gps || gps.length===0){ - history.replace("/") - return; - } - gps.unshift({category_name : "Only favorites", category_id:"fav"}) - setGroup(gps[1].category_id) - dispatch(setGroupList(gps)); - history.replace("/live/category/"+gps[1].category_id+"/") - }) - }else history.replace("/live/category/"); + }else if(resetMemory("live")){ + await loadGroup("live").then(gps => { + if(!gps || gps.length===0){ + history.replace("/") + return; + } + gps.unshift({category_name : "Only favorites", category_id:"fav"}) + setGroup(gps[1].category_id) + dispatch(setGroupList(gps)); + history.replace("/live/category/"+gps[1].category_id+"/") + }) + }else history.replace("/live/category/"); + } + fun() },[dispatch,category]) useEffect(() => { diff --git a/src/components/Login.js b/src/components/Login.js index 030d29f..2bff304 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -124,8 +124,10 @@ const Login = ({url}) => { <> -

Welcome to {window.playername}

-
Write your credentials to continue.
+ {false && (

Welcome to {window.playername}

)} +

+ +
Write your credentials to continue

{!window.dns && ([ diff --git a/src/components/Player/Player.js b/src/components/Player/Player.js index 465a9c5..d9ce7f2 100644 --- a/src/components/Player/Player.js +++ b/src/components/Player/Player.js @@ -155,9 +155,24 @@ const Player = () => { url={url} pip={pip} controls={false} - onError={()=> setError(true)} - onBufferEnd={()=>setIsLoading(false)} - onBuffer={()=>setIsLoading(true)} + onProgress={(state)=>{ + setError(false) + }} + onPlay={()=>{ + setError(false) + }} + onError={(error, data)=> { + setError(true) + setIsLoading(false) + }} + onBufferEnd={()=>{ + setError(false) + setIsLoading(false) + }} + onBuffer={()=>{ + setIsLoading(true); + setError(false) + }} /> { isLoading === true && ( diff --git a/src/components/Vod/MainVod.js b/src/components/Vod/MainVod.js index a39622f..f768142 100644 --- a/src/components/Vod/MainVod.js +++ b/src/components/Vod/MainVod.js @@ -134,7 +134,7 @@ const MainVod = () => { setIsLoading(true); setRefresh(0) - if (reset === true) { + if (reset === true || cat.length === 0) { await loadGroup(playingMode).then(gps => { if (!gps || gps.length === 0) { history.replace("/") @@ -142,9 +142,10 @@ const MainVod = () => { } gps.unshift({category_id:"fav", favorite:1, category_name: "Only favorites"},{category_id:"toend", history: 1, category_name:"Continue to watch"}) dispatch(setGroupList(gps || [])); + cat = gps }) } - loadPlaylist(playingMode, category || "ALL").then(chs => { + await loadPlaylist(playingMode, category || "ALL").then(chs => { if(category && isNaN(category)){ chs = chs.filter(s=> { const f = DB.findOne(playingMode, playingMode === "series" ? s.series_id : s.stream_id, category === "fav") diff --git a/src/other/Player-github/player-github.js b/src/other/Player-github/player-github.js index 4dd9c28..0583686 100644 --- a/src/other/Player-github/player-github.js +++ b/src/other/Player-github/player-github.js @@ -55,7 +55,6 @@ export default function ReactNetflixPlayer({ onErrorVideo = false, onNextClick = false, onClickItemListReproduction = false, - onCrossClick = () => {}, startPosition = 0, playlistTitle = "Playlist", @@ -551,7 +550,7 @@ export default function ReactNetflixPlayer({

{title}

{subTitle}

- + )} diff --git a/src/other/axios.js b/src/other/axios.js index d24dedc..1af2db3 100644 --- a/src/other/axios.js +++ b/src/other/axios.js @@ -12,37 +12,43 @@ export async function get(url, timeout = 1) { return Axios.get(url).catch(err => err); } -export async function post(url, params = {}, local) { +export async function post(url, params = {}, local, useProxy) { if (!dns) return null; + let uri = url + if (local === true && !window.location.origin.match(/iptveditor\.com|localhost/)) { - return Axios.post(url, qs.stringify(params)).catch(err => err) + return Axios.post(uri, qs.stringify(params)).catch(err => err) } if (isIptveditor === false) { - url += "?"; + uri += "?"; for (const key in params) { - url += key + "=" + encodeURIComponent(params[key]) + "&"; + uri += key + "=" + encodeURIComponent(params[key]) + "&"; } } - if (proxyRequired === true && isIptveditor === true) - url = "/proxy.php?url=" + encodeURIComponent(dns); - else if (proxyRequired === true && isIptveditor === false) - url = "/proxy.php?url=" + encodeURIComponent(dns + url); + if ((proxyRequired || useProxy) === true && isIptveditor === true) + uri = "/proxy.php?url=" + encodeURIComponent(dns); + else if ((proxyRequired || useProxy) === true && isIptveditor === false) + uri = "/proxy.php?url=" + encodeURIComponent(dns + uri); else if (isIptveditor === false) - url = dns + url; - else url = dns; + uri = dns + uri; + else uri = dns; - return isIptveditor === true ? - Axios.post(url, qs.stringify(params)) : - Axios.get(url, { + return isIptveditor === true && !(proxyRequired || useProxy)? + Axios.post(uri, qs.stringify(params)) : + Axios.get(uri, { headers: { 'User-Agent': 'Mozilla/6.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.55 Safari/537.36 Edge/86.0.622.28' }, timeout: 25000 - }).catch(err => err); + }).catch(err => { + if(proxyRequired === false && !useProxy && !err.response) + return post(url, params, local, true) + return err + }); } @@ -55,7 +61,7 @@ export function setDns(data) { else if (window.location.protocol === 'https:' && !data.includes("https")) data = data.replace("http", "https"); - isIptveditor = !!data.match(/iptveditor\.com|xtream-ie|localhost|192\.168\.178\.71\:3100/) + isIptveditor = !!data.match(/iptveditor\.com|xtream-ie|opop\.pro|localhost|192\.168\.178\.71\:3100/) if (window.isDebug === 1) data = window.dns; diff --git a/src/other/epg-database.js b/src/other/epg-database.js index e7cd0ad..071c537 100644 --- a/src/other/epg-database.js +++ b/src/other/epg-database.js @@ -93,31 +93,30 @@ export async function downloadEpgDataFromCategories(channels) { if (toDownload.length === 0) return; else { - await loadEpgArray(toDownload, limit).then(result => { - toDownload.forEach(id => { - let data = result[[id]] - if (data && data.length > 0) { - data = convertEpgListing(data); - const dataset = epgMap.has(id) ? epgMap.get(id) : { days: {}, data: [] } - mergeDay(dataset, data, limit); - epgMap.set(id, dataset) - } else { - if (epgMap.has(id)) { - if (!epgMap.get(id)){ - - } - if (!epgMap.get(id).days) - epgMap.get(id).days = {} - epgMap.get(id).days[limit] = false; - } else if (limit === 1) - epgMap.set(id, false); - else { - let obj = { days: {}, data: [] }; - obj.days[limit] = false; - epgMap.set(id, obj); + const result = await loadEpgArray(toDownload, limit) + toDownload.forEach(id => { + let data = result[[id]] + if (data && data.length > 0) { + data = convertEpgListing(data); + const dataset = epgMap.has(id) ? epgMap.get(id) : { days: {}, data: [] } + mergeDay(dataset, data, limit); + epgMap.set(id, dataset) + } else { + if (epgMap.has(id)) { + if (!epgMap.get(id)){ + } + if (!epgMap.get(id).days) + epgMap.get(id).days = {} + epgMap.get(id).days[limit] = false; + } else if (limit === 1) + epgMap.set(id, false); + else { + let obj = { days: {}, data: [] }; + obj.days[limit] = false; + epgMap.set(id, obj); } - }) + } }) } diff --git a/src/other/load-playlist.js b/src/other/load-playlist.js index bbb6df0..16b12be 100644 --- a/src/other/load-playlist.js +++ b/src/other/load-playlist.js @@ -1,92 +1,126 @@ import * as axios from "./axios"; -import {getInfo} from "./user_info" -import {getVodTmdbData, getSeriesTmdbData, clearEpisodeName} from "./tmdb" +import { getInfo } from "./user_info" +import { getVodTmdbData, getSeriesTmdbData, clearEpisodeName } from "./tmdb" import { downloadEpgDataFromCategories } from "./epg-database"; import { groupBy } from './group-by'; +import Axios from "axios"; -export async function loadGroup(mode){ - return await axios.post("player_api.php",{ +export async function loadGroup(mode) { + return await axios.post("player_api.php", { username: getInfo().username, - password : getInfo().password, + password: getInfo().password, action: getAddress(mode, true) - }).catch(err => []) - .then(result =>{ - return result.data; - }); + }).then(res => res.data).catch(err => []) } -export async function loadPlaylist(mode,group){ - const result = await axios.post("player_api.php",{ +export async function loadPlaylist(mode, group) { + const result = await axios.post("player_api.php", { username: getInfo().username, - password : getInfo().password, + password: getInfo().password, action: getAddress(mode, false), - category_id : isNaN(group) ? "*" : group - }).catch(err => []) - if(mode==="live" && !isNaN(group) && axios.getIsIptveditor()===true){ - await downloadEpgDataFromCategories(result.data) + category_id: isNaN(group) ? "*" : group + }).then(res => res.data).catch(err => []) + if (mode === "live" && !isNaN(group) && axios.getIsIptveditor() === true) { + await downloadEpgDataFromCategories(result) } //else if(mode==="movie") // result.data = result.data.sort((a,b)=>b.added-a.added) //else if(mode==="series") // result.data = result.data.sort((a,b)=>b.last_modified-a.last_modified) - return result.data; + return result; } -export async function loadEpg(epg_id, limit = 1){ +export async function loadEpg(epg_id, limit = 1) { let now = new Date(); - - return await axios.post("/epg.php",{ + if (axios.getIsIptveditor() === true) return []; + + return await axios.post("/epg.php", { username: getInfo().username, - password : getInfo().password, + password: getInfo().password, action: "get_simple_data_table", - epg_id : epg_id, - limit : limit, - start: parseInt(new Date(now.getFullYear(),now.getMonth(), now.getDate()+limit-1, 0,0,0,0).getTime()/1000), - stop: parseInt(new Date(now.getFullYear(),now.getMonth(), now.getDate()+limit-1, 23,59,59,9999).getTime()/1000), + epg_id: epg_id, + limit: limit, + start: parseInt(new Date(now.getFullYear(), now.getMonth(), now.getDate() + limit - 1, 0, 0, 0, 0).getTime() / 1000), + stop: parseInt(new Date(now.getFullYear(), now.getMonth(), now.getDate() + limit - 1, 23, 59, 59, 9999).getTime() / 1000), }, true).catch(err => []) - .then(result =>{ - return result.data; - }); + .then(result => { + return result.data; + }); } -export async function loadEpgArray(epg_ids, limit = 2){ +export async function loadEpgArray(epg_ids, limit = 2) { + if (axios.getIsIptveditor() === false) return [] let now = new Date(); - + const programmes = []; - return await axios.post("/epg.php",{ - username: getInfo().username, - password : getInfo().password, - action: "get_simple_data_table_array", - epg_ids: JSON.stringify(epg_ids), - limit : limit, - start: parseInt(new Date(now.getFullYear(),now.getMonth(), now.getDate()+limit-1, 0,0,0,0).getTime()/1000), - stop: parseInt(new Date(now.getFullYear(),now.getMonth(), now.getDate()+limit-1, 23,59,59,9999).getTime()/1000), - }).catch(err => []) - .then(result =>{ - if(!result.data) - return epg_ids - const d = groupBy(result.data, "id") - return d; - }); + const set = new Set() + const map = {} + + epg_ids.filter(x=>!!x).forEach(x=> { + const id = x.replace(/\.(plus|minus)\d+$/,"") + set.add(id) + + const shift = x.match(/\.(plus|minus)(?\d+)$/) + if(shift && shift.groups){ + const list = map[id] || [] + list.push(shift.groups.number) + map[id] = list + } + }) + epg_ids = Array.from(set) + + for (let i = 0, j = epg_ids.length; i < j; i += 50) { + let sliced = epg_ids.slice(i, i + 50) + + const result = await Axios.post( `${process.env.REACT_APP_IPTVEDITOR_API}webplayer`, { + username: getInfo().username, + password: getInfo().password, + action: "get_simple_data_table_array", + epg_ids: sliced, + limit: limit, + start: parseInt(new Date(now.getFullYear(), now.getMonth(), now.getDate() + limit - 1, 0, 0, 0, 0).getTime() / 1000), + stop: parseInt(new Date(now.getFullYear(), now.getMonth(), now.getDate() + limit - 1, 23, 59, 59, 9999).getTime() / 1000), + }).then(result=> result.data).catch(err=> []) + + Object.keys(map).filter(c=> sliced.includes(c)).forEach(c=>{ + const pgs = result.filter(x=>x.id === c) + map[c].forEach(shift => { + const id = c + (shift > 0 ? `.plus${shift}` : `.minus${shift}`) + pgs.forEach(p=> result.push({ + ...p, + id, + start: p.start + (shift * 3600), + stop: p.stop + (shift * 3600) + })) + }) + + }) + + result.forEach(p=> programmes.push(p)) + } + + const toReturn = groupBy(programmes, "id") + + return toReturn; } export async function getVodInfo(vod_id, name, existingTmdb) { let result = null; - if (axios.getIsIptveditor()===false) { + if (axios.getIsIptveditor() === false) { result = await axios.post("player_api.php", { - username: getInfo().username, - password: getInfo().password, - action: "get_vod_info", - vod_id: vod_id, - }).catch(err => null) + username: getInfo().username, + password: getInfo().password, + action: "get_vod_info", + vod_id: vod_id, + }).catch(err => null) .then(result => { return result.data; }); } - if(result && result.info && result.info.cover_big) + if (result && result.info && result.info.cover_big) return result; return await getVodTmdbData(name, existingTmdb) @@ -94,44 +128,44 @@ export async function getVodInfo(vod_id, name, existingTmdb) { export async function getSeriesInfo(series_id, name, only_info, existingTmdb) { let result = null; - if (axios.getIsIptveditor()===false || only_info === false) { + if (axios.getIsIptveditor() === false || only_info === false) { result = await axios.post("player_api.php", { username: getInfo().username, password: getInfo().password, action: "get_series_info", series_id: series_id, }).catch(err => null) - .then(result => { - if(result.data && Array.isArray(result.data)){ - result.data.forEach(x=> { - if(!x.episode_num && x.episode) - x.episode_num = x.episode - }) - } - return result.data; - }); + .then(result => { + if (result.data && Array.isArray(result.data)) { + result.data.forEach(x => { + if (!x.episode_num && x.episode) + x.episode_num = x.episode + }) + } + return result.data; + }); } - - if(axios.getIsIptveditor()===true) + + if (axios.getIsIptveditor() === true) return await getSeriesTmdbData(name, result, existingTmdb) - else if(only_info===false) + else if (only_info === false) clearEpisodeName(name, result) return result; } -const getAddress = (mode,group) =>{ - switch(mode){ +const getAddress = (mode, group) => { + switch (mode) { case "live": - if(!group) + if (!group) return "get_live_streams" else return "get_live_categories" case "movie": - if(!group) + if (!group) return "get_vod_streams" else return "get_vod_categories" case "series": - if(!group) + if (!group) return "get_series" else return "get_series_categories" default: