diff --git a/sites/vivacom.bg/vivacom.bg.config.js b/sites/vivacom.bg/vivacom.bg.config.js new file mode 100644 index 00000000..a6ca9939 --- /dev/null +++ b/sites/vivacom.bg/vivacom.bg.config.js @@ -0,0 +1,83 @@ +const cheerio = require('cheerio') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const timezone = require('dayjs/plugin/timezone') +const customParseFormat = require('dayjs/plugin/customParseFormat') + +dayjs.extend(utc) +dayjs.extend(timezone) +dayjs.extend(customParseFormat) + +module.exports = { + site: 'vivacom.bg', + url({ date, channel }) { + const [page] = channel.site_id.split('#') + + return `https://www.vivacom.bg/bg/tv/programa/?date=${date.format('YYYY-MM-DD')}&page=${page}` + }, + logo({ content, channel }) { + const [_, channelId] = channel.site_id.split('#') + const $ = cheerio.load(content) + const imgSrc = $(`li[title="${channelId}"] > img`).attr('src') + + return imgSrc ? `https://www.vivacom.bg${imgSrc}` : null + }, + parser: function ({ content, channel, date }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + programs.push({ + title: parseTitle(item), + description: parseDescription(item), + start: parseStart(item, date), + stop: parseStop(item, date) + }) + }) + + return programs + } +} + +function parseStart(item, date) { + const $ = cheerio.load(item) + let [_, time] = $('span') + .text() + .match(/^(\d{2}:\d{2}:\d{2})/) || [null, null] + if (!time) return null + time = `${date.format('YYYY-MM-DD')} ${time}` + + return dayjs.tz(time, 'YYYY-MM-DD HH:mm:ss', 'Europe/Sofia').toJSON() +} + +function parseStop(item, date, pm) { + const $ = cheerio.load(item) + let [_, time] = $('span') + .text() + .match(/(\d{2}:\d{2}:\d{2})$/) || [null, null] + if (!time) return null + if (time === '00:00:00') date = date.add(1, 'd') + time = `${date.format('YYYY-MM-DD')} ${time}` + + return dayjs.tz(time, 'YYYY-MM-DD HH:mm:ss', 'Europe/Sofia').toJSON() +} + +function parseTitle(item) { + const $ = cheerio.load(item) + + return $('h3').text() +} + +function parseDescription(item) { + const $ = cheerio.load(item) + + return $('p').text() +} + +function parseItems(content, channel) { + const [_, channelId] = channel.site_id.split('#') + const $ = cheerio.load(content) + const listItem = $(`#scroll-vertical > li[title="${channelId}"]`) + const i = $(`#scroll-vertical > li`).index(listItem) + + return $(`#scroll-horizontal > ul:nth-child(${i + 1}) li`).toArray() +} diff --git a/sites/vivacom.bg/vivacom.bg.test.js b/sites/vivacom.bg/vivacom.bg.test.js new file mode 100644 index 00000000..da29192a --- /dev/null +++ b/sites/vivacom.bg/vivacom.bg.test.js @@ -0,0 +1,49 @@ +// npx epg-grabber --config=sites/vivacom.bg/vivacom.bg.config.js --channels=sites/vivacom.bg/vivacom.bg_bg.channels.xml --output=.gh-pages/guides/bg/vivacom.bg.epg.xml --days=2 + +const { parser, url, logo, request } = require('./vivacom.bg.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +const date = dayjs.utc('2021-11-05', 'YYYY-MM-DD').startOf('d') +const channel = { site_id: '1#БНТ 1 HD', xmltv_id: 'BNT1.bg' } +const content = `
  • Когато сърцето зове

    04:25:00 - 05:10:00

    Телевизионен филм. Тв филм /4 сезон, 5 епизод/п/

  • Dreamy Nights: Songs & Rhymes

    23:30:00 - 00:00:00

    Songs & Rhymes, Flowers, Milky Way, Close Your Eyes, Twilight

` + +it('can generate valid url', () => { + const result = url({ date, channel }) + expect(result).toBe('https://www.vivacom.bg/bg/tv/programa/?date=2021-11-05&page=1') +}) + +it('can get logo url', () => { + const result = logo({ content, channel }) + expect(result).toBe('https://www.vivacom.bg/web/files/richeditor/tv/bnt-1-hd.png') +}) + +it('can parse response', () => { + const result = parser({ date, channel, content }) + expect(result).toMatchObject([ + { + start: '2021-11-05T02:25:00.000Z', + stop: '2021-11-05T03:10:00.000Z', + title: 'Когато сърцето зове', + description: 'Телевизионен филм. Тв филм /4 сезон, 5 епизод/п/' + }, + { + start: '2021-11-05T21:30:00.000Z', + stop: '2021-11-05T22:00:00.000Z', + title: 'Dreamy Nights: Songs & Rhymes', + description: 'Songs & Rhymes, Flowers, Milky Way, Close Your Eyes, Twilight' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `
` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/vivacom.bg/vivacom.bg_bg.channels.xml b/sites/vivacom.bg/vivacom.bg_bg.channels.xml new file mode 100644 index 00000000..942cba37 --- /dev/null +++ b/sites/vivacom.bg/vivacom.bg_bg.channels.xml @@ -0,0 +1,188 @@ + + + + 24 Kitchen Bulgaria + 360 Tune Box + 7/8 TV + Agro TV + Alfa TV + AMC Balkan + Animal Planet Europe + Auto Motor und Sport + AXN Black + AXN Bulgaria + AXN White + B1B Box + Baby TV Europe + Balkanika Music TV + Barely Legal TV + BeIn Movies Turk + BG Music Channel + Bloomberg TV Bulgaria + BNT 1 + BNT 2 + BNT 3 + BNT 4 + Boomerang Central & Eastern Europe + Box TV + BTV + BTV Action + BTV Cinema + BTV Comedy + BTV Lady + Bulgaria 24 + Bulgaria On Air + Bulgarska Svobodna TV + Cartoon Network Bulgaria + CBS Reality Europe + Chasse & Pêche + Cinemax 2 Central Europe + Cinemax Central Europe + City TV + Club MTV + CNBC Europe + CNN International Europe + Code Health TV + Crime + Investigation UK + Da Vinci + Deluxe Lounge + Deluxe Music + Detski Mir + Diema + Diema Family + Diema Sport + Diema Sport 2 + Discovery Channel Bulgaria + Discovery Science + Disney Channel Bulgaria + Disney Junior Romania & Bulgaria + DM Sat + DocuBox HD + Dorcel TV + Duck TV SD + DW English + EKids + English Club TV + Epic Drama + Erox HD + Eroxxx HD + Eurochannel + EuroNews English + Eurosport 1 + Eurosport 2 + Evrokom + Extreme Sports Channel + FashionBox HD + Fashion TV HD Europe + Fashion TV Russia + Fast & FunBox HD + Fen Folk + Fen TV + FightBox HD + FilmBox Arthouse Worldwide + FilmBox Basic + FilmBox Extra HD Bulgaria + FilmBox Stars Adria + Folklor TV + Food Network EMEA + Fox Bulgaria + Fox Crime Bulgaria + Fox Life Bulgaria + France 24 Français + Fuel TV + Gametoon + Habertürk + HBO 2 Central Europe + HBO 3 Central Europe + HBO Adria + History HD Europe + Hit Mix Channel + Hustler TV Europe + Investigation Discovery Europe + JimJam Europe + Jukebox + Kanal 7 Avrupa + Kino Nova + Lubimoe Kino + Luxe TV + Magic TV + Max Sport 1 + Max Sport 2 + Max Sport 3 + Mediaset Italia + Mezzo + Motorvision TV + Movie Star + MTV 00s + MTV 80s + MTV 90s + MTV Global + MTV Hits Europe + MTV Live + MyZen TV + Nastoyashcheye Vremya + National Geographic Bulgaria + National Geographic Wild Europe + Nickelodeon Europe + Nick Jr Central & Eastern Europe + Nova News + Nova Sport + Nova TV + Okhota i Rybalka + Penthouse Gold + Perviy kanal Europa + Planeta Folk + Planeta TV + Playboy TV Europe + Plovdivska Pravoslavna TV + Pyatnitsa! International + Redlight HD + Ring + Rossiya 24 + RT Arabic + RT Documentary + RTG International + RTL Deutschland + RT News + RTR Planeta + RTVi Europe + Show Turk + SKAT + Stingray CMusic + Stingray IConcerts + TGCom 24 + The Fishing & Hunting Channel + The Voice TV + The World + Tiankov Folk + TLC Balkan + TNT 4 International + TNT International + Trace Sport Stars + Travel Channel Europe + Travel TV + TRT World + TV 1 + TV 3 International + TV5Monde Europe + TV 8 International + TV 999 + TV 1000 Balkan + TV 1000 Russkoe Kino + TV Bulgare + TV Centr International + TV Evropa + TVR International + TV Tourism + Viasat Explore East + Viasat History + Viasat Nature East + Vivacom Arena + Vox Deutschland + VTK + Wild TV + Wness TV + XXL + Yaban + + \ No newline at end of file