|
3 | 3 | # Copyright (c) 2022-2025 Dimitri Kroon. |
4 | 4 | # This file is part of plugin.video.viwx. |
5 | 5 | # SPDX-License-Identifier: GPL-2.0-or-later |
6 | | -# See LICENSE.txt |
| 6 | +# See LICENSE.txt or https://www.gnu.org/licenses/gpl-2.0.txt |
7 | 7 | # ---------------------------------------------------------------------------------------------------------------------- |
8 | 8 |
|
9 | 9 | import json |
@@ -293,25 +293,34 @@ def parse_editorial_slider(url, slider_data): |
293 | 293 | """Parse editorialSliders from the main page or from a collection.""" |
294 | 294 | # noinspection PyBroadException |
295 | 295 | try: |
296 | | - coll_data = slider_data['collection'] |
297 | | - if not coll_data.get('shows'): |
298 | | - # Has happened. Items without field `shows` have an invalid headingLink |
299 | | - return None |
300 | | - page_link = coll_data.get('headingLink') |
301 | | - base_url = 'https://www.itv.com/watch' |
302 | | - if page_link: |
303 | | - # Link to the collection's page if available |
304 | | - params = {'url': base_url + page_link['href']} |
| 296 | + header = slider_data.get('header') |
| 297 | + if header: |
| 298 | + # slider from the main page |
| 299 | + params = {'url': 'https://www.itv.com' + header['linkHref']} |
| 300 | + title = header['title'] |
| 301 | + |
305 | 302 | else: |
306 | | - # Provide the slider name when the collection contents are the |
307 | | - # items in the slider on the original page. |
308 | | - slider_name = slider_data['collection']['sliderName'] |
309 | | - params = {'url': url, 'slider': slider_name} |
| 303 | + # slider from a collection page |
| 304 | + coll_data = slider_data['collection'] |
| 305 | + if not coll_data.get('shows'): |
| 306 | + # Has happened. Items without a field `shows` have an invalid headingLink |
| 307 | + return None |
| 308 | + title = coll_data['headingTitle'] |
| 309 | + page_link = coll_data.get('headingLink') |
| 310 | + base_url = 'https://www.itv.com/watch' |
| 311 | + if page_link: |
| 312 | + # Link to the collection's page if available |
| 313 | + params = {'url': base_url + page_link['href']} |
| 314 | + else: |
| 315 | + # Provide the slider id when the collection contents are the |
| 316 | + # items in the slider on the original page. |
| 317 | + params = {'url': url, 'slider': slider_data['id']} |
310 | 318 |
|
311 | 319 | return {'type': 'collection', |
312 | | - 'show': {'label': coll_data['headingTitle'], |
| 320 | + 'show': {'label': title, |
313 | 321 | 'params': params, |
314 | | - 'info': {'sorttitle': sort_title(coll_data['headingTitle'])}}} |
| 322 | + 'info': {'sorttitle': sort_title(title), |
| 323 | + }}} |
315 | 324 | except: |
316 | 325 | logger.error("Unexpected error parsing editorialSlider from %s", url, exc_info=True) |
317 | 326 | return None |
@@ -499,19 +508,27 @@ def parse_item_type_collection(item_data): |
499 | 508 | Only items from heroContent seem to have a field `ctaLabel`. |
500 | 509 |
|
501 | 510 | """ |
502 | | - url = '/'.join(('https://www.itv.com/watch/collections', |
503 | | - item_data.get('titleSlug', ''), |
504 | | - item_data.get('collectionId') or item_data['pageId'])) |
| 511 | + if 'href' in item_data: |
| 512 | + # This is a new format found in the main page's editorial rails |
| 513 | + url = 'https://www.itv.com' + item_data['href'] |
| 514 | + else: |
| 515 | + # A format still found on collection pages and hero rail. |
| 516 | + url = '/'.join(('https://www.itv.com/watch/collections', |
| 517 | + item_data.get('titleSlug', ''), |
| 518 | + item_data.get('collectionId') or item_data['pageId'])) |
505 | 519 | if item_data['contentType'] == 'page': |
506 | 520 | # This querystring is required for page items |
507 | 521 | url += '?ind' |
508 | 522 |
|
509 | 523 | title = item_data['title'] |
510 | | - descr = '\n\n'.join(txt for txt in (item_data.get('ctaLabel', 'Collection'), item_data.get('description')) if txt) |
| 524 | + descr = '\n\n'.join(txt for txt in (item_data.get('ctaLabel', 'Collection'), |
| 525 | + item_data.get('description'), |
| 526 | + item_data.get('subtitle')) if txt) |
| 527 | + img_template = item_data.get('imageTemplate') or item_data['partnershipTileImageTemplate'] |
511 | 528 | item = { |
512 | 529 | 'label': title, |
513 | | - 'art': {'thumb': item_data['imageTemplate'].format(**IMG_PROPS_THUMB), |
514 | | - 'fanart': item_data['imageTemplate'].format(**IMG_PROPS_FANART)}, |
| 530 | + 'art': {'thumb': img_template.format(**IMG_PROPS_THUMB), |
| 531 | + 'fanart': img_template.format(**IMG_PROPS_FANART)}, |
515 | 532 | 'info': {'title': '[B]{}[/B]'.format(title), |
516 | 533 | 'plot': descr, |
517 | 534 | 'sorttitle': sort_title(title)}, |
|
0 commit comments