From 6e35d4364de46a9dbf51a307e86eed42f3c483c9 Mon Sep 17 00:00:00 2001 From: Natanel-Shitrit <65548905+Natanel-Shitrit@users.noreply.github.com> Date: Sat, 29 Mar 2025 14:39:04 +0300 Subject: [PATCH 1/2] Add freetv.tv --- sites/freetv.tv/freetv.tv.channels.xml | 10 +++++ sites/freetv.tv/freetv.tv.config.js | 62 ++++++++++++++++++++++++++ sites/freetv.tv/freetv.tv.test.js | 50 +++++++++++++++++++++ sites/freetv.tv/readme.md | 21 +++++++++ 4 files changed, 143 insertions(+) create mode 100644 sites/freetv.tv/freetv.tv.channels.xml create mode 100644 sites/freetv.tv/freetv.tv.config.js create mode 100644 sites/freetv.tv/freetv.tv.test.js create mode 100644 sites/freetv.tv/readme.md diff --git a/sites/freetv.tv/freetv.tv.channels.xml b/sites/freetv.tv/freetv.tv.channels.xml new file mode 100644 index 00000000..10b6071c --- /dev/null +++ b/sites/freetv.tv/freetv.tv.channels.xml @@ -0,0 +1,10 @@ + + + مكان + כאן 11 + חינוכית + קשת 12 + רשת 13 + ערוץ 14 + ערוץ הכנסת + diff --git a/sites/freetv.tv/freetv.tv.config.js b/sites/freetv.tv/freetv.tv.config.js new file mode 100644 index 00000000..4b21ba88 --- /dev/null +++ b/sites/freetv.tv/freetv.tv.config.js @@ -0,0 +1,62 @@ +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: 'freetv.tv', + days: 2, + url: function ({ channel, date }) { + const localDate = dayjs(date).tz('Asia/Jerusalem') + const since = localDate.startOf('day').format('YYYY-MM-DDTHH:mmZZ') + const till = localDate.add(1, 'day').startOf('day').format('YYYY-MM-DDTHH:mmZZ') + + return `https://web.freetv.tv/api/products/lives/programmes?liveId[]=${ + channel.site_id + }&since=${encodeURIComponent(since)}&till=${encodeURIComponent(till)}&lang=HEB&platform=BROWSER` + }, + parser: function ({ content }) { + const programs = [] + let items = [] + + try { + items = JSON.parse(content) + } catch { + return programs + } + + items.forEach(item => { + const start = parseStart(item) + const stop = parseStop(item) + if (!start.isValid() || !stop.isValid()) return + + programs.push({ + title: item.title, + description: item.description || item.lead, + image: getImageUrl(item), + icon: getImageUrl(item), + start, + stop + }) + }) + + return programs + } +} + +function parseStart(item) { + return item.since ? dayjs.utc(item.since).tz('Asia/Jerusalem') : null +} + +function parseStop(item) { + return item.till ? dayjs.utc(item.till).tz('Asia/Jerusalem') : null +} + +function getImageUrl(item) { + const url = item.images?.['16x9']?.[0]?.url + return url ? `https:${url}` : null +} diff --git a/sites/freetv.tv/freetv.tv.test.js b/sites/freetv.tv/freetv.tv.test.js new file mode 100644 index 00000000..e65c3cfe --- /dev/null +++ b/sites/freetv.tv/freetv.tv.test.js @@ -0,0 +1,50 @@ +const { parser, url } = require('./freetv.tv.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('2025-03-28', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '3370462', + xmltv_id: 'Kan11.il' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://web.freetv.tv/api/products/lives/programmes?liveId[]=3370462&since=2025-03-28T00%3A00%2B0200&till=2025-03-29T00%3A00%2B0300&lang=HEB&platform=BROWSER') +}) + +it('can parse response', () => { + const content = '[{"id":5856194,"publicUid":"f17b5a1d-3f2a-42a0-a11b-a08e5c9785fd","title":"בוש 4 - פרק 3","lead":"עונה 4 חדשה לדרמה הבלשית. 3. השטן בתוך הבית: הכוח המיוחד מנסה לחקור, ומגלה אליבי שקרי עם השלכות מרעישות. הבלש סנטיאגו רוברטסון צריך לשים את קשריו האישיים בצד למען החקירה. בוש זוכה לביקור פתע לילי.כ עב","description":"עונה 4 חדשה לדרמה הבלשית. 3. השטן בתוך הבית: הכוח המיוחד מנסה לחקור, ומגלה אליבי שקרי עם השלכות מרעישות. הבלש סנטיאגו רוברטסון צריך לשים את קשריו האישיים בצד למען החקירה. בוש זוכה לביקור פתע לילי.כ עב","rating":14,"ratingEmbedded":false,"type":"PROGRAMME","uhd":false,"since":"2025-03-27T21:26:00Z","till":"2025-03-27T22:17:00Z","images":{"16x9":[{"url":"//d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1361162/COVER/images/1361162_1736767668746.jpg?dsth=177&dstw=315&srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1","templateUrl":"//d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1361162/COVER/images/1361162_1736767668746.jpg?srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1&dsth={height:177}&dstw={width:315}"}]},"genres":[],"webUrl":"https://web.freetv.tv/news,1991/rw-11,3370462/2025-03-27/bw-4---prq-3,5856194","trailer":false,"live":{"type_":"LIVE","id":3370462},"available":true,"timeshiftAvailable":false,"startoverAvailable":false,"catchupTill":"2025-04-10T21:26:00Z","npvrTill":"2025-04-10T21:26:00Z","programRecordingId":7068534,"audio":false,"video":true,"showRecommendations":false,"recommended":false,"premiere":false,"liveBroadcast":false,"slug":"bw-4---prq-3"},{"id":5858584,"publicUid":"1dc296c9-0c28-4202-8b20-cbef56a763f5","title":"אבא משתדל - 5. חבר","lead":"סדרה קומית. יוסי מכיר אב לילד עם צרכים מיוחדים ובין השניים מתפתח קשר בסגנון חיזור גורלי שמערער את יוסי. כ עב.","description":"סדרה קומית. יוסי מכיר אב לילד עם צרכים מיוחדים ובין השניים מתפתח קשר בסגנון חיזור גורלי שמערער את יוסי. כ עב.","ratingEmbedded":false,"type":"PROGRAMME","uhd":false,"since":"2025-03-27T22:17:00Z","till":"2025-03-27T22:43:00Z","images":{"16x9":[{"url":"//d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1070668/COVER/images/1070668_1742202219830.jpg?dsth=177&dstw=315&srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1","templateUrl":"//d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1070668/COVER/images/1070668_1742202219830.jpg?srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1&dsth={height:177}&dstw={width:315}"}]},"genres":[],"webUrl":"https://web.freetv.tv/news,1991/rw-11,3370462/2025-03-27/b-mdl---5-br,5858584","trailer":false,"live":{"type_":"LIVE","id":3370462},"available":true,"timeshiftAvailable":false,"startoverAvailable":false,"catchupTill":"2025-04-10T22:17:00Z","npvrTill":"2025-04-10T22:17:00Z","programRecordingId":7071052,"audio":false,"video":true,"showRecommendations":false,"recommended":false,"premiere":false,"liveBroadcast":false,"slug":"b-mdl---5-br"}]' + + const results = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(results.length).toBe(2) + expect(results[0]).toMatchObject({ + title: 'בוש 4 - פרק 3', + description: 'עונה 4 חדשה לדרמה הבלשית. 3. השטן בתוך הבית: הכוח המיוחד מנסה לחקור, ומגלה אליבי שקרי עם השלכות מרעישות. הבלש סנטיאגו רוברטסון צריך לשים את קשריו האישיים בצד למען החקירה. בוש זוכה לביקור פתע לילי.כ עב', + image: 'https://d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1361162/COVER/images/1361162_1736767668746.jpg?dsth=177&dstw=315&srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1', + icon: 'https://d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1361162/COVER/images/1361162_1736767668746.jpg?dsth=177&dstw=315&srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1', + start: '2025-03-27T21:26:00.000Z', + stop: '2025-03-27T22:17:00.000Z' + }) + expect(results[1]).toMatchObject({ + title: 'אבא משתדל - 5. חבר', + description: 'סדרה קומית. יוסי מכיר אב לילד עם צרכים מיוחדים ובין השניים מתפתח קשר בסגנון חיזור גורלי שמערער את יוסי. כ עב.', + image: 'https://d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1070668/COVER/images/1070668_1742202219830.jpg?dsth=177&dstw=315&srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1', + icon: 'https://d1zqtf09wb8nt5.cloudfront.net/scale/oil/freetv/upload/programme/1070668/COVER/images/1070668_1742202219830.jpg?dsth=177&dstw=315&srcmode=0&srcx=0&srcy=0&quality=65&type=1&srcw=1/1&srch=1/1', + start: '2025-03-27T22:17:00.000Z', + stop: '2025-03-27T22:43:00.000Z' + }) +}) + +it('can handle empty guide', () => { + const results = parser({ content: '' }) + + expect(results).toMatchObject([]) +}) diff --git a/sites/freetv.tv/readme.md b/sites/freetv.tv/readme.md new file mode 100644 index 00000000..f4a22937 --- /dev/null +++ b/sites/freetv.tv/readme.md @@ -0,0 +1,21 @@ +# freetv.tv + +https://example.com + +### Download the guide + +```sh +npm run grab --- --site=freetv.tv +``` + +### Update channel list + +```sh +npm run channels:parse --- --config=./sites/freetv.tv/freetv.tv.config.js --output=./sites/freetv.tv/freetv.tv.channels.xml +``` + +### Test + +```sh +npm test --- freetv.tv +``` From c12254f80d13911815204f7495ecf7b9b56715d9 Mon Sep 17 00:00:00 2001 From: Natanel Shitrit <65548905+Natanel-Shitrit@users.noreply.github.com> Date: Sun, 30 Mar 2025 03:23:02 +0300 Subject: [PATCH 2/2] Update sites/freetv.tv/readme.md Co-authored-by: Aleksandr Statciuk <7253922+freearhey@users.noreply.github.com> --- sites/freetv.tv/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/freetv.tv/readme.md b/sites/freetv.tv/readme.md index f4a22937..f614fac3 100644 --- a/sites/freetv.tv/readme.md +++ b/sites/freetv.tv/readme.md @@ -1,6 +1,6 @@ # freetv.tv -https://example.com +https://freetv.tv/ ### Download the guide