From aa04d9482e24faadbee9195dbd2efa0281dc04ae Mon Sep 17 00:00:00 2001 From: Toha Date: Sat, 7 Dec 2024 23:49:27 +0700 Subject: [PATCH] Fetch detailed guide. Signed-off-by: Toha --- sites/mytelly.co.uk/__data__/programme.html | 814 +++++++++++++++++++ sites/mytelly.co.uk/__data__/programme2.html | 796 ++++++++++++++++++ sites/mytelly.co.uk/mytelly.co.uk.config.js | 81 +- sites/mytelly.co.uk/mytelly.co.uk.test.js | 45 +- 4 files changed, 1724 insertions(+), 12 deletions(-) create mode 100644 sites/mytelly.co.uk/__data__/programme.html create mode 100644 sites/mytelly.co.uk/__data__/programme2.html diff --git a/sites/mytelly.co.uk/__data__/programme.html b/sites/mytelly.co.uk/__data__/programme.html new file mode 100644 index 00000000..1bf7baff --- /dev/null +++ b/sites/mytelly.co.uk/__data__/programme.html @@ -0,0 +1,814 @@ + + + + + + Captain Phillips - TV Listings | My Telly + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+
+
+
+
+
+
+
+
+

+ Captain Phillips +

+
+
+
+
+ + + + +
12:00 am - 02:05 am, + Today + on BBC + One London (1) +
+
+
+ + + + +
+
+

+ + + + + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ Average User Rating: 4.50 (2 votes)
+ My Rating: Sign in or + Register to view last vote +

+
+
+ + + Add to Favorites + +
+
+
+
+
+ +
+
+
+
+
+

About this Broadcast

- +
+
+ +
+
+

An American cargo ship sets a dangerous course around the coast of Somalia, while inland, + four men are pressed into service as pirates by the local warlords. The captain is taken + hostage when the raiding party hijacks the vessel, resulting in a tense five-day crisis. + Fact-based thriller, starring Tom Hanks and Barkhad Abdi

+
+
+ 2013 + HD + subtitles + 16x9 +
+
+ Factual + Movie/Drama + Thriller +
+
+

+

+

+ Cast & Crew +

- +

+
+
+
+ + Tom Hanks + + (Actor) + .. Capt Richard Phillips +
+
+
+
+ + Barkhad Abdi + + (Actor) + .. Muse +
+
+
+
+ + Catherine Keener + + (Actor) + .. Andrea Phillips +
+
+
+
+ + Barkhad Abdirahman + + (Actor) + .. Bilal +
+
+
+
+ + Faysal Ahmed + + (Actor) + .. Najee +
+
+
+
+ + Mahat M Ali + + (Actor) + .. Elmi +
+
+
+
+ + Michael Chernus + + (Actor) + .. Shane Murphy +
+
+
+
+ + David Warshofsky + + (Actor) + .. Mike Perry +
+
+
+
+ + Paul Greengrass + + (Director) +
+
+
+ + + +
+

+

+

More Information

- +

+ +
No Logo
+
+ +
No Logo
+
+
+
+
+
+
+ + + + + + + +
+
+
+
+
+ +
+

+ Did You Know.. +

-

+
+
+
+
+ Tom Hanks + (Actor) + .. Capt Richard Phillips +
+
+
+ + Born: + + July 09, 1956 + in + California +
+
+ + Best Known For: + + Winning Oscars for Forrest Gump and Philadelphia +
+
+ + Early-life: + + Born in California in 1956, Tom Hanks grew up in what he calls a "fractured" + family. His parents were pioneers in the development of marriage dissolution law in that + state, and Tom moved around a lot, living with a succession of step-families. Eager for + a career in acting, he auditioned for a community theater play, was invited by the + director of that play to go to Cleveland, and there his acting career started. +
+
+ + Career: + + After several TV roles, Hanks made the transition to movies and became one of the + biggest stars of the past three decades. His breakthrough came in 1984's Splash, + and was followed by hit after hit, including Bachelor Party and Dragnet. When he took + the lead in Oscar-nominated Big in 1988, he transformed a simple comedy into something + much more powerful, before truly proving his acting credentials with an Oscar-winning + turn as an Aids-afflicted laweyer in Philadeplhia. He gave terrific turns in romantic + comedies like Sleepless in Seattle, then another Oscar followed for Forrest Gump. Many + expected him to garner a third for Saving Private Ryan. He has been a successful + director of several projects and helped bring iconic TV projects like Band of Brothers + to the screen. Recent hits include The Da Vinci Code and its follow-up, and the Toy + Story films. +
+
+ + Quote: + + "My wife keeps on telling me my worst fault is that I keep things to myself and + appear relaxed. But I am really in a room in my own head and not hearing a thing anyone + is saying." +
+
+
+
+
+ Barkhad Abdi + (Actor) + .. Muse +
+
+
+
+ Catherine Keener + (Actor) + .. Andrea Phillips +
+
+
+ + Born: + + March 23, 1959 + in + Miami, Florida +
+
+ + Best Known For: + + Playing Maxine Lund in Being John Malkovich. +
+
+ + Early-life: + + Catherine Ann Keener was born in Miami, Florida on March 23, 1959. She has four + siblings, including actress Elizabeth Keener. Catherine studied at Wheaton College in + Massachusetts, where she graduated with a degree in English and history in 1983. While + studying here, she joined a theatre course and appeared in her first theatrical + production during her junior year. +
+
+ + Career: + + Keener's first film appearance was a one-worded role as a waitress in About Last + Night… (1986). She then went on to appear in Survival Quest (1988). After struggling in + the industry for a number of years, she landed a part in Johnny Suede (1991) and began + getting roles in independent films. Her mainstream breakthrough was in Being John + Malkovich (1999). Since then, she has appeared in many more films, including Capote + (2005), Into The Wild (2007), Captain Phillips (2013) and Get Out (2017). +
+
+ + Quote: + + "Luck favours the prepared." +
+
+ + Trivia: + + She was Oscar-nominated for Best Supporting Actress in 2000 for her performance in Being + John Malkovich and in 2006 for her performance in Capote. +
+
+
+
+
+ Barkhad Abdirahman + (Actor) + .. Bilal +
+
+
+
+ Faysal Ahmed + (Actor) + .. Najee +
+
+
+
+ Mahat M Ali + (Actor) + .. Elmi +
+
+
+
+ Michael Chernus + (Actor) + .. Shane Murphy +
+
+
+
+ David Warshofsky + (Actor) + .. Mike Perry +
+
+
+
+ Paul Greengrass + (Director) +
+
+
+
+
+
+
+
+ +
+
+
+
+
+

Before / After

- +

+ + + + + +
+ + + + + +
+ + + +
+
+ + + + + +
+ + + +
+
+
+
+
+
+ + +
+ +
+ +
+
+
+
+ + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sites/mytelly.co.uk/__data__/programme2.html b/sites/mytelly.co.uk/__data__/programme2.html new file mode 100644 index 00000000..e1c637d2 --- /dev/null +++ b/sites/mytelly.co.uk/__data__/programme2.html @@ -0,0 +1,796 @@ + + + + + + The Rap Game UK - TV Listings | My Telly + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+
+
+
+
+
+
+
+
+

+ The Rap Game UK +

+
+
+
+
+ + + + +
11:35 pm - 12:40 am, + Today + on BBC + One Channel Islands (1) +
+
+
+ + + + +
+
+

+ + + + + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ Average User Rating: 1.00 (1 + votes)
+ My Rating: Sign in or + Register + to view last vote +

+
+
+ + + Add to Favorites + +
+
+
+
+
+ +
+
+
+
+
+

About this Broadcast

- +
+
+ +
+
+ Past and Pressure
+ Season 6, Episode 5 +
+
+

The artists are tasked with writing a song about their heritage. + For some, the pressure of the competition proves too much for + them to match. In their final challenge, they are put face to + face with industry experts who grill them about their plans + after the competition. Some impress, while others leave the + mentors confused

+
+
+ HD + subtitles + repeat + 16x9 +
+
+ Challenge/Reality Show + Show/Game Show +
+
+

+

+

+ Cast & Crew +

- +

+
+
+
+ + Konan + + (Presenter) +
+
+
+
+ + Krept + + (Presenter) +
+
+
+
+ + DJ Target + + (Presenter) +
+
+
+
+ + Hetal Dhanak + + (Series producer) +
+
+
+
+ + Tom O'Brien + + (Executive producer) +
+
+
+
+ + Paul Broadbent + + (Executive producer) +
+
+
+
+ + Trent Williams-Jones + + (Executive producer) +
+
+
+ + + +
+

+

+

More Information

- +

+ +
No Logo
+
+
+
+
+
+
+ + + + + +
+
+
+
+
+ +
+

Upcoming Broadcasts

-

+
+

The Rap Game UK is scheduled to broadcast again at the + following times

+
+
+

+ +
+
Saturday, December 07
+
+ + + + + + + + + + + + + + + +
+
Time
+
+
Episode
+
+
Channel
+
+
11:35 pm
+
+
+ The Rap Game UK +
+
+ Season: 6, + Episode: 5 +
+
+ The artists are tasked with writing a song about + their heritage. For some, the pressure of the + competition proves too much for them to match. In + their final challenge, they are put face to face + with industry experts who grill them about their + plans after the competition. Some impress, while + others leave the mentors confused +
+
+
+ + BBC One Channel Islands HD + (101) + +
+
+ (BT TV) +
+
+
+
+
+ + +
+
+
+
+
+ +
+

+ Did You Know.. +

-

+
+
+
+
+ Konan + (Presenter) +
+
+
+
+ Krept + (Presenter) +
+
+
+
+ DJ Target + (Presenter) +
+
+
+
+ Hetal Dhanak + (Series producer) +
+
+
+
+ Tom O'Brien + (Executive producer) +
+
+
+
+ Paul Broadbent + (Executive producer) +
+
+
+
+ Trent Williams-Jones + (Executive producer) +
+
+
+
+
+
+
+
+ +
+
+
+
+
+

Before / After

- +

+ + + + + +
+ + + + + +
+ + + +
+
+ + + + + +
+ + + +
+
+
+
+
+
+ + +
+ +
+ +
+
+
+
+ + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sites/mytelly.co.uk/mytelly.co.uk.config.js b/sites/mytelly.co.uk/mytelly.co.uk.config.js index ef28ef78..f08be0bd 100644 --- a/sites/mytelly.co.uk/mytelly.co.uk.config.js +++ b/sites/mytelly.co.uk/mytelly.co.uk.config.js @@ -9,9 +9,9 @@ dayjs.extend(utc) dayjs.extend(timezone) dayjs.extend(customParseFormat) -const detailedGuide = false +const detailedGuide = true const tz = 'Europe/London' -const nworker = 10 +const nworker = 25 module.exports = { site: 'mytelly.co.uk', @@ -37,8 +37,7 @@ module.exports = { } else { const subtitle = td.find('h6') const time = $(el).find('td:eq(0)') - const dateString = `${date.format('YYYY-MM-DD')} ${time.text().trim()}` - let start = dayjs.tz(dateString, 'YYYY-MM-DD H:mm a', tz) + let start = parseTime(date, time.text().trim()) const prev = programs[programs.length - 1] if (prev) { if (start.isBefore(prev.start)) { @@ -56,6 +55,53 @@ module.exports = { }) } }) + + if (queues.length) { + await doFetch(queues, (url, res) => { + const $ = cheerio.load(res) + const time = $('center > h5 > b').text() + const title = parseText($('.inner-heading.sub h2')) + const subTitle = parseText($('.tab-pane > h5 > strong')) + const description = parseText($('.tab-pane > .tvbody > p')) + const image = $('.program-media-image img').attr('src') + const category = $('.schedule-attributes-genres span').toArray() + .map(el => $(el).text()) + const casts = $('.single-cast-head:not([id])').toArray() + .map(el => { + const cast = { name: parseText($(el).find('a')) } + const [, role] = $(el).text().match(/\((.*)\)/) || [null, null] + if (role) { + cast.role = role + } + return cast + }) + const [start, stop] = parseStartStop(date, time) + let season, episode + if (subTitle) { + const [, ses, epi] = subTitle.match(/Season (\d+), Episode (\d+)/) || [null, null] + if (ses) { + season = parseInt(ses) + } + if (epi) { + episode = parseInt(epi) + } + } + programs.push({ + title, + subTitle, + description, + image, + category, + season, + episode, + actor: casts.filter(c => c.role === 'Actor').map(c => c.name), + director: casts.filter(c => c.role === 'Director').map(c => c.name), + presenter: casts.filter(c => c.role === 'Presenter').map(c => c.name), + start, + stop + }) + }) + } } return programs @@ -115,12 +161,35 @@ module.exports = { } } +function parseStartStop(date, time) { + const [s, e] = time.split(' - ') + const start = parseTime(date, s) + let stop = parseTime(date, e) + if (stop.isBefore(start)) { + stop = stop.add(1, 'd') + } + + return [start, stop] +} + +function parseTime(date, time) { + return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD H:mm a', tz) +} + function parseText($item) { - return $item.text() + let text = $item.text() .replace(/\t/g, '') .replace(/\n/g, ' ') - .replace(/ /g, ' ') .trim() + while (true) { + if (text.match(/ /)) { + text = text.replace(/ /g, ' ') + continue + } + break + } + + return text } async function doFetch(queues, cb) { diff --git a/sites/mytelly.co.uk/mytelly.co.uk.test.js b/sites/mytelly.co.uk/mytelly.co.uk.test.js index e27a0816..20f6ced0 100644 --- a/sites/mytelly.co.uk/mytelly.co.uk.test.js +++ b/sites/mytelly.co.uk/mytelly.co.uk.test.js @@ -1,18 +1,41 @@ const { parser, url } = require('./mytelly.co.uk.config.js') +const axios = require('axios') const fs = require('fs') const path = require('path') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') const customParseFormat = require('dayjs/plugin/customParseFormat') + dayjs.extend(customParseFormat) dayjs.extend(utc) +jest.mock('axios') + const date = dayjs.utc('2024-12-07', 'YYYY-MM-DD').startOf('d') const channel = { site_id: '713/bbc-one-london', xmltv_id: 'BBCOneLondon.uk' } +axios.get.mockImplementation((url, opts) => { + if ( + url === 'https://www.mytelly.co.uk/tv-guide/listings/programme?cid=713&pid=1906433&tm=2024-12-07+00%3A00%3A00' + ) { + return Promise.resolve({ + data: fs.readFileSync(path.join(__dirname, '__data__', 'programme.html')) + }) + } + if ( + url === 'https://www.mytelly.co.uk/tv-guide/listings/programme?cid=713&pid=5656624&tm=2024-12-07+23%3A35%3A00' + ) { + return Promise.resolve({ + data: fs.readFileSync(path.join(__dirname, '__data__', 'programme2.html')) + }) + } + + return Promise.resolve({ data: '' }) +}) + it('can generate valid url', () => { expect(url({ channel, date })).toBe( 'https://www.mytelly.co.uk/tv-guide/listings/channel/713/bbc-one-london.html?dt=2024-12-07' @@ -20,24 +43,34 @@ it('can generate valid url', () => { }) it('can parse response', async () => { - const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html')) + const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.html')) const results = (await parser({ content, channel, date })).map(p => { p.start = p.start.toJSON() p.stop = p.stop.toJSON() return p }) - expect(results.length).toBe(25) + expect(results.length).toBe(2) expect(results[0]).toMatchObject({ start: '2024-12-07T00:00:00.000Z', stop: '2024-12-07T02:05:00.000Z', - title: 'Captain Phillips (2013)' + title: 'Captain Phillips', + description: + 'An American cargo ship sets a dangerous course around the coast of Somalia, while inland, four men are pressed into service as pirates by the local warlords. The captain is taken hostage when the raiding party hijacks the vessel, resulting in a tense five-day crisis. Fact-based thriller, starring Tom Hanks and Barkhad Abdi', + image: 'https://d16ia5iwuvax6y.cloudfront.net/uk-prog-images/c44ce7b0d3ae602c0c93ece5af140815.jpg?k=VeeNdUjml3bSHdlZ0OXbGLy%2BmsLdYPwTV6iAxGkzq4dsylOCGGE7OWlqwSWt0cd0Qtrin4DkEMC0Zzdp8ZeNk2vNIQzjMF0DG0h3IeTR5NM%3D', + category: ['Factual', 'Movie/Drama', 'Thriller'] }) - expect(results[24]).toMatchObject({ + expect(results[1]).toMatchObject({ start: '2024-12-07T23:35:00.000Z', - stop: '2024-12-08T00:05:00.000Z', + stop: '2024-12-08T00:40:00.000Z', title: 'The Rap Game UK', - subTitle: 'Past and Pressure - Season 6, Episode 5' + subTitle: 'Past and Pressure Season 6, Episode 5', + description: + 'The artists are tasked with writing a song about their heritage. For some, the pressure of the competition proves too much for them to match. In their final challenge, they are put face to face with industry experts who grill them about their plans after the competition. Some impress, while others leave the mentors confused', + image: 'https://d16ia5iwuvax6y.cloudfront.net/uk-prog-images/2039278182b27cc279570b9ab9b89379.jpg?k=VeeNdUjml3bSHdlZ0OXbGLy%2BmsLdYPwTV6iAxGkzq4cDhR7jXTNFW3tgwQCdOPUobhXwlT81mIsqOe93HPusDG6tw1aoeYOgafojtynNWxc%3D', + category: ['Challenge/Reality Show', 'Show/Game Show'], + season: 6, + episode: 5 }) })