Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tv5unis.py (Python)

Code before:
          hls {
            url
          }
        }
      }
    }
  }
}''' % (self._GQL_QUERY_NAME, self._gql_args(groups)),  # noqa: UP031
            })['data'][self._GQL_QUERY_NAME]
        video = product['videoElement']
        if video is None:
            raise ExtractorError('No video element found')

        return {
            '_type': 'url_transparent',
            'id': video.get('mediaId'),
            'title': product.get('title'),
            'description': product.get('summary'),
            'url': traverse_obj(video, ('encodings', 'hls', 'url'), expected_type=url_or_none),
            'age_limit': parse_age_limit(try_get(product, lambda x: traverse_obj(x, ('rating', 'name'), expected_type=str))),
            'tags': product.get('tags'),
            'series': try_get(product, lambda x: traverse_obj(x, ('collection', 'title'), expected_type=str)),
            'season_number': int_or_none(product.get('seasonNumber')),
            'episode_number': int_or_none(product.get('episodeNumber')),
            'ie_key': 'Generic',
        }


class TV5UnisVideoIE(TV5UnisBaseIE):
    IE_NAME = 'tv5unis:video'
    _VALID_URL = r'https?://(?:www\.)?tv5unis\.ca/videos/[^/]+/(?P<id>\d+)'
    _TEST = {
        'url': 'https://www.tv5unis.ca/videos/bande-annonces/144041',
        'md5': '24a247c96119d77fe1bae8b440457dfa',
        'info_dict': {
            'id': '56862325352147149dce0ae139afced6',
            'ext': 'mp4',
            'title': 'Antigone',
            'description': "En aidant son frère à s'évader de prison, Antigone confronte les autorités : la police, le système judiciaire et pénal ainsi que le père de son ami Hémon. L'adolescente brillante au parcours jusque là sans tache voit l'étau se resserrer autour d'elle. Mais à la loi des hommes, elle substitue son propre sens de la justice, dicté par l'amour et la solidarité.",
            'duration': 61,
            'tags': 'count:0',
        },
    }
    _GQL_QUERY_NAME = 'productById'

    @staticmethod
    def _gql_args(groups):
        return f'id: {groups[0]}'


class TV5UnisIE(TV5UnisBaseIE):

Review comment (bug):
Returning a `url` result to the `Generic` extractor here is incorrect.

The extraction of m3u8 formats should be done in this extractor and it should return `formats` instead

e.g.

```py
        media_id = video['mediaId']

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            video['encodings']['hls']['url'], media_id, 'mp4')

        return {
            'id': media_id,
            'formats': formats,
            'subtitles': subtitles,
            # etc etc...
```

Code after:
      __typename
      ... on Video {
        mediaId
        encodings {
          hls {
            url
          }
        }
      }
      ... on RestrictedVideo {
        code
        reason
      }
    }
  }
}''' % (self._GQL_QUERY_NAME, self._gql_args(groups)),  # noqa: UP031
            })['data'][self._GQL_QUERY_NAME]

        video = product['videoElement']
        if video is None:
            raise ExtractorError('This content is no longer available', expected=True)

        if video.get('__typename') == 'RestrictedVideo':
            code = video.get('code')
            if code == 1001:
                self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
            reason = video.get('reason')
            raise ExtractorError(join_nonempty(
                'This video is restricted',
                code is not None and f', error code {code}',
                reason and f': {remove_end(reason, ".")}',
                delim=''))

        media_id = video['mediaId']
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            video['encodings']['hls']['url'], media_id, 'mp4')

        return {
            'id': media_id,
            '_old_archive_ids': [make_archive_id('LimelightMedia', media_id)],
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(product, {
                'title': ('title', {str}),
                'description': ('summary', {str}),
                'tags': ('tags', ..., {str}),
                'duration': ('duration', {int_or_none}),
                'season_number': ('seasonNumber', {int_or_none}),
                'episode_number': ('episodeNumber', {int_or_none}),
                'series': ('collection', 'title', {str}),
                'age_limit': ('rating', 'name', {parse_age_limit}),