mirror of
https://github.com/iptv-org/epg
synced 2026-09-10 13:56:51 -04:00
Fix mi.tv time parsing and cheerio stuff
This commit is contained in:
Generated
-48
@@ -3119,9 +3119,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0 AND MIT",
|
"license": "Apache-2.0 AND MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3138,9 +3135,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0 AND MIT",
|
"license": "Apache-2.0 AND MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3157,9 +3151,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ppc64"
|
"ppc64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0 AND MIT",
|
"license": "Apache-2.0 AND MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3176,9 +3167,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"s390x"
|
"s390x"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0 AND MIT",
|
"license": "Apache-2.0 AND MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3195,9 +3183,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0 AND MIT",
|
"license": "Apache-2.0 AND MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3214,9 +3199,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0 AND MIT",
|
"license": "Apache-2.0 AND MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3959,9 +3941,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3975,9 +3954,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3991,9 +3967,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"loong64"
|
"loong64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4007,9 +3980,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"loong64"
|
"loong64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4023,9 +3993,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ppc64"
|
"ppc64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4039,9 +4006,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4055,9 +4019,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4071,9 +4032,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"s390x"
|
"s390x"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4087,9 +4045,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4103,9 +4058,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
|
|||||||
+24
-18
@@ -23,14 +23,22 @@ module.exports = {
|
|||||||
const [country, id] = channel.site_id.split('#')
|
const [country, id] = channel.site_id.split('#')
|
||||||
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/0`
|
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/0`
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date, channel }) {
|
||||||
|
const country = channel?.site_id?.split('#')?.[0] || null
|
||||||
|
let hourformat
|
||||||
|
if (country === 'co') { // Colombia uses h:mma instead of HH:mm
|
||||||
|
hourformat = 'h:mma'
|
||||||
|
} else {
|
||||||
|
hourformat = 'HH:mm'
|
||||||
|
}
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content)
|
const $ = cheerio.load(content)
|
||||||
items.forEach(item => {
|
const items = parseItems($)
|
||||||
|
for (const item of items) {
|
||||||
const prev = programs[programs.length - 1]
|
const prev = programs[programs.length - 1]
|
||||||
const $item = cheerio.load(item)
|
const $item = $(item)
|
||||||
let start = parseStart($item, date)
|
let start = parseStart($item, date, hourformat)
|
||||||
if (!start) return
|
if (!start) continue
|
||||||
if (prev) {
|
if (prev) {
|
||||||
if (start.isBefore(prev.start)) {
|
if (start.isBefore(prev.start)) {
|
||||||
start = start.add(1, 'd')
|
start = start.add(1, 'd')
|
||||||
@@ -47,7 +55,7 @@ module.exports = {
|
|||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
@@ -82,29 +90,29 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart($item, date) {
|
function parseStart($item, date, hourformat) {
|
||||||
const timeString = $item('a > div.content > span.time').text()
|
const timeString = $item.find('a > div.content > span.time').text()
|
||||||
if (!timeString) return null
|
if (!timeString) return null
|
||||||
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
|
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
|
||||||
|
|
||||||
return dayjs.utc(dateString, 'MM/DD/YYYY HH:mm')
|
return dayjs.utc(dateString, `MM/DD/YYYY ${hourformat}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle($item) {
|
function parseTitle($item) {
|
||||||
return $item('a > div.content > h2').text().trim()
|
return $item.find('a > div.content > h2').text().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCategory($item) {
|
function parseCategory($item) {
|
||||||
return $item('a > div.content > span.sub-title').text().trim()
|
return $item.find('a > div.content > span.sub-title').text().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDescription($item) {
|
function parseDescription($item) {
|
||||||
return $item('a > div.content > p.synopsis').text().trim()
|
return $item.find('a > div.content > p.synopsis').text().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function parseImage($item) {
|
function parseImage($item) {
|
||||||
const styleAttr = $item('a > div.image-parent > div.image').attr('style')
|
const styleAttr = $item.find('a > div.image-parent > div.image').attr('style')
|
||||||
|
|
||||||
if (styleAttr) {
|
if (styleAttr) {
|
||||||
const match = styleAttr.match(/background-image:\s*url\(['"]?(.*?)['"]?\)/)
|
const match = styleAttr.match(/background-image:\s*url\(['"]?(.*?)['"]?\)/)
|
||||||
@@ -113,7 +121,7 @@ function parseImage($item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const backgroundImage = $item('a > div.image-parent > div.image').css('background-image')
|
const backgroundImage = $item.find('a > div.image-parent > div.image').css('background-image')
|
||||||
|
|
||||||
if (backgroundImage && backgroundImage !== 'none') {
|
if (backgroundImage && backgroundImage !== 'none') {
|
||||||
const match = backgroundImage.match(/url\(['"]?(.*?)['"]?\)/)
|
const match = backgroundImage.match(/url\(['"]?(.*?)['"]?\)/)
|
||||||
@@ -137,8 +145,6 @@ function cleanUrl(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function parseItems(content) {
|
function parseItems($) {
|
||||||
const $ = cheerio.load(content)
|
|
||||||
|
|
||||||
return $('#listings > ul > li').toArray()
|
return $('#listings > ul > li').toArray()
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ it('can generate valid url', () => {
|
|||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
|
||||||
const result = parser({ content, date }).map(p => {
|
const result = parser({ content, date, channel }).map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
|
|||||||
Reference in New Issue
Block a user