From 98a5c8baa368a5e3061114c9ad24f1e7d9e1af92 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 11 Nov 2021 12:33:51 +0300 Subject: [PATCH 1/3] Create mtel.ba.test.js --- sites/mtel.ba/mtel.ba.test.js | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sites/mtel.ba/mtel.ba.test.js diff --git a/sites/mtel.ba/mtel.ba.test.js b/sites/mtel.ba/mtel.ba.test.js new file mode 100644 index 00000000..aef9f87d --- /dev/null +++ b/sites/mtel.ba/mtel.ba.test.js @@ -0,0 +1,56 @@ +// npx epg-grabber --config=sites/mtel.ba/mtel.ba.config.js --channels=sites/mtel.ba/mtel.ba_ba.channels.xml --output=.gh-pages/guides/ba/mtel.ba.epg.xml --days=2 + +const { parser, url, request, logo } = require('./mtel.ba.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-10', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '001#11', + xmltv_id: 'RTRSTV.ba' +} +const content = `{"page":0,"total_pages":1,"date":"2021-11-10","channels":[{"id":"11","name":"RTRS","description":null,"link":null,"image":"https:\/\/mtel.ba\/oec\/images\/tv_channels\/c3556aa629b00325aaaea622abfb1070.png","position":"001","items":[{"id_channel":"11","title":"\u0160uma","description":"Krajem decembra 1947. godine jugoslovenski predsjednik Josip Broz Tito prvi put je posjetio Rumuniju. Da bi u\u010dvrstili novo socijalisti\u010dko prijateljstvo, rumunski zvani\u010dnici su poklonili Titu sliku velikog rumunskog umjetnika Jona Andreskua pod nazivom \u0160uma. Mnogo godina kasnije ta slika je umje\u0161ana u napetu \u0161pijunsku pri\u010du i otkriva tajnu koja \u0107e uzdrmati temelje i Jugoslavije i Rumunije. Film je svjedok kompleksnosti i raznovrsnosti glasova koji \u010dine ono \u0161to zovemo stvarno\u0161\u0107u.","start":"00:00:00","duration":"46.00","full_start":"2021-11-09 23:29:00","full_end":"2021-11-10 00:46:00","image":"https:\/\/mtel.ba\/oec\/images\/epg\/60881491.jpg","category":"Televizijski film","subcategory":"Dokumentarna drama"},{"id_channel":"11","title":"Nema informacija o programu","description":"","start":"07:32:00","duration":"988.00","full_start":"2021-11-10 07:32:00","full_end":"2021-11-10 24:00:00","image":"","category":"","subcategory":""}]}]}` + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://mtel.ba/oec/epg/program?date=2021-11-10&position=001' + ) +}) + +it('can generate valid request headers', () => { + expect(request.headers).toMatchObject({ + 'X-Requested-With': 'XMLHttpRequest' + }) +}) + +it('can get logo url', () => { + expect(logo({ content, channel })).toBe( + 'https://mtel.ba/oec/images/tv_channels/c3556aa629b00325aaaea622abfb1070.png' + ) +}) + +fit('can parse response', () => { + const result = parser({ date, channel, content }) + expect(result).toMatchObject([ + { + start: '2021-11-09T22:29:00.000Z', + stop: '2021-11-09T23:46:00.000Z', + title: 'Šuma', + icon: 'https://mtel.ba/oec/images/epg/60881491.jpg', + description: `Krajem decembra 1947. godine jugoslovenski predsjednik Josip Broz Tito prvi put je posjetio Rumuniju. Da bi učvrstili novo socijalističko prijateljstvo, rumunski zvaničnici su poklonili Titu sliku velikog rumunskog umjetnika Jona Andreskua pod nazivom Šuma. Mnogo godina kasnije ta slika je umješana u napetu špijunsku priču i otkriva tajnu koja će uzdrmati temelje i Jugoslavije i Rumunije. Film je svjedok kompleksnosti i raznovrsnosti glasova koji čine ono što zovemo stvarnošću.`, + category: 'Televizijski film' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `{"message":"Tra\u017eeni termin nije prona\u0111en.\u003Cbr\u003E\u003Cbr\u003EProverite da li ste upisali pravilno ili poku\u0161ajte sa nekim drugim terminom."}` + }) + expect(result).toMatchObject([]) +}) From 3f6e3d9603e172c58e36e417f74ca0692c103453 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 11 Nov 2021 12:33:56 +0300 Subject: [PATCH 2/3] Create mtel.ba.config.js --- sites/mtel.ba/mtel.ba.config.js | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 sites/mtel.ba/mtel.ba.config.js diff --git a/sites/mtel.ba/mtel.ba.config.js b/sites/mtel.ba/mtel.ba.config.js new file mode 100644 index 00000000..0015d995 --- /dev/null +++ b/sites/mtel.ba/mtel.ba.config.js @@ -0,0 +1,63 @@ +const dayjs = require('dayjs') +const timezone = require('dayjs/plugin/timezone') + +dayjs.extend(timezone) + +module.exports = { + site: 'mtel.ba', + url: function ({ channel, date }) { + const [position] = channel.site_id.split('#') + + return `https://mtel.ba/oec/epg/program?date=${date.format('YYYY-MM-DD')}&position=${position}` + }, + request: { + timeout: 15000, + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }, + logo({ content, channel }) { + const data = parseContent(content, channel) + + return data ? data.image : null + }, + parser: function ({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + if (item.title === 'Nema informacija o programu') return + programs.push({ + title: item.title, + description: item.description, + category: item.category, + icon: item.image, + start: parseStart(item).toJSON(), + stop: parseStop(item).toJSON() + }) + }) + + return programs + } +} + +function parseStart(item) { + return dayjs.tz(item.full_start, 'Europe/Sarajevo') +} + +function parseStop(item) { + return dayjs.tz(item.full_end, 'Europe/Sarajevo') +} + +function parseContent(content, channel) { + const [_, channelId] = channel.site_id.split('#') + const data = JSON.parse(content) + if (!data || !Array.isArray(data.channels)) return null + + return data.channels.find(i => i.id === channelId) +} + +function parseItems(content, channel) { + const data = parseContent(content, channel) + + return data ? data.items : [] +} From d694e2b69e751aea1c8471676424ceee72d8e9c3 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 11 Nov 2021 12:34:04 +0300 Subject: [PATCH 3/3] Create mtel.ba_ba.channels.xml --- sites/mtel.ba/mtel.ba_ba.channels.xml | 183 ++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 sites/mtel.ba/mtel.ba_ba.channels.xml diff --git a/sites/mtel.ba/mtel.ba_ba.channels.xml b/sites/mtel.ba/mtel.ba_ba.channels.xml new file mode 100644 index 00000000..1c03d0f2 --- /dev/null +++ b/sites/mtel.ba/mtel.ba_ba.channels.xml @@ -0,0 +1,183 @@ + + + + 24 Kitchen Srbija + 101 TV + 360 Tune Box + Adult Channel 1 + Adult Channel 2 + Adult Channel 3 + Adult Channel 4 + Adult Channel 5 + Adult Channel 6 + Adult Channel 7 + Agro TV + Aljazeera Balkans + Amari TV + AMC Balkan + Animal Planet Europe + Arena Esport + Arena Fight + Arena Sport 1 + Arena Sport 1x2 + Arena Sport 2 + Arena Sport 3 + Arena Sport 4 + B92 + Babes TV + Baby TV Europe + Balkan Trip + Bang U + BHT 1 + BN + BN Music + Boomerang Central & Eastern Europe + Cafe & Club + Cartoon Network Central & Eastern Europe + CBS Reality Europe + CGTN + Cinemax 2 Central Europe + Cinemax Central Europe + CineStar TV 1 Srbija + CineStar TV Action Srbija + CineStar TV Comedy + CineStar TV Fantasy + CNN International Europe + Decija TV + Dexy TV + Discovery Channel Srbija + Discovery Science + Dizi + DM Sat + DocuBox HD + Dox TV + DTX East Europe + EG Melody + English Club TV + Erotic + Erotic 2 + Erotic 3 + Erotic 4 + Erotic 7 + Erotic 8 + Erox HD + Eroxxx HD + Extreme Sports Channel + EX YU Melody + FashionTV Europe + FilmBox Arthouse Worldwide + FilmBox Extra HD Adria + FilmBox Premium Adria + FilmBox Stars Adria + Film Klub + Folk Melody + Food Network EMEA + Fox Srbija + France 24 Français + Happy Reality 1 + Happy Reality 2 + Hayatovci + Hayat Plus + HBO 2 Central Europe + HBO 3 Central Europe + HBO Adria + HGTV Pan Regional + History 2 Polska + History Europe + Hits Melody + HRT 1 + HRT 2 + Hype TV + Investigation Discovery Europe + Jeka + JimJam Europe + K3 + K CN 3 + Kitchen TV + Klasik TV + Kurir TV + Kuvo TV + LFC TV + Melos TV + MTV 00s + MTV 80s + MTV Global + MTV Hits Europe + Muzzik + National Geographic Srbija + National Geographic Wild Europe + Nicktoons Adria + OTV Valentino + Pink Action + Pink BH + Pink Classic + Pink Comedy + Pink Crime & Mystery + Pink Extra + Pink Family + Pink Film + Pink Horror + Pink Koncert + Pink Kuvar + Pink Movies + Pink Pedia + Pink Reality + Pink Sci-Fi & Fantasy + Pink Serije + Pink Show + Pink Soap + Pink Srbija + Pink Style + Pink Thriller + Pink Western + Pink World + Pink Zabava + Pop Melody + Prva Files + Prva Kick + Prva Life + Prva Max + Prva Srpska TV + Prva World + Reality Kings TV + Red TV + Rock & Roll + Rossiya 24 + RTL Hrvatska + RTL II + RTL Kockica + RTL Living Hrvatska + RT News + RTR Planeta + RTRS TV + RTS 2 + RTS Klasika + RTS Kolo + RTS Nauka + RTS Poletarac + RTS Svet + RTV 2 + Sat. 1 Deutschland + SOS Kanal Plus + Super Sat + Superstar + Tanjug TV + Tb1 + TLC Balkan + Toxic Folk + Toxic TV + Travel Channel Europe + Tropik TV + TV Arena + TV Niksic + TV One + TV Partizan + TV Simić + Viasat Explore East + Viasat History + Viasat Nature East + World Wild Muzzik + Zdravlje TV + Zvezda TV + + \ No newline at end of file