Repository: yt-dlp/yt-dlp

Issue:
[Zype] [Nebula] HLS subtitles not downloaded.
<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
- First of, make sure you are using the latest version of yt-dlp. Run `yt-dlp --version` and ensure your version is 2021.09.02. If it's not, see https://github.com/yt-dlp/yt-dlp on how to update. Issues with outdated version will be REJECTED.
- Make sure that all provided video/audio/playlist URLs (if any) are alive and playable in a browser.
- Make sure that all URLs and arguments with special characters are properly quoted or escaped as explained in https://github.com/yt-dlp/yt-dlp.
- Search the bugtracker for similar issues: https://github.com/yt-dlp/yt-dlp. DO NOT post duplicates.
- Read bugs section in FAQ: https://github.com/yt-dlp/yt-dlp
- Finally, put x into all relevant boxes like this [x] (Dont forget to delete the empty space)
-->

- [ ] I'm reporting a bug unrelated to a specific site
- [x] I've verified that I'm running yt-dlp version **2021.09.02**
- [x] I've checked that all provided URLs are alive and playable in a browser
- [x] The provided URLs do not contain any DRM to the best of my knowledge
- [x] I've checked that all URLs and arguments with special characters are properly quoted or escaped
- [x] I've searched the bugtracker for similar bug reports including closed ones
- [x] I've read bugs section in FAQ


## Verbose log

<!--
Provide the complete verbose output of yt-dlp that clearly demonstrates the problem.
Add the `-v` flag to your command line you run yt-dlp with (`yt-dlp -v <your command line>`), copy the WHOLE output and insert it below. It should look similar to this:
 [debug] System config: []
 [debug] User config: []
 [debug] Command-line args: [u'-v', u'http://www.youtube.com/watch?v=BaW_jenozKc']
 [debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
 [debug] yt-dlp version 2021.09.02
 [debug] Python version 2.7.11 - Windows-2003Server-5.2.3790-SP2
 [debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
 [debug] Proxy map: {}
 <more lines>
-->

```

PS C:\temp> yt-dlp.exe --verbose --write-subs   --cookies-from-browser firefox -fbest https://nebula.app/videos/wendover-productions-the-logistics-of-resettling-afghan-refugees
[debug] Command-line config: ['--verbose', '--write-subs', '--cookies-from-browser', 'firefox', '-fbest', 'https://nebula.app/videos/wendover-productions-the-logistics-of-resettling-afghan-refugees']
[Cookies] Extracting cookies from firefox
[debug] extracting from: "C:\Users\Adam\AppData\Roaming\Mozilla\Firefox\Profiles\ku69lu4m.default-release\cookies.sqlite"
[Cookies] Extracted 2973 cookies from firefox
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, pref cp1252
[debug] yt-dlp version 2021.09.02 (exe)
[debug] Python version 3.8.10 (CPython 64bit) - Windows-10-10.0.19043-SP0
[debug] exe versions: ffmpeg N-103120-g5b62544dee-gc50f5460d2, ffprobe N-103120-g5b62544dee-gc50f5460d2, rtmpdump 2.4-20210219-gf1b83c1-GnuTLS_3.6.13-x86_64-static
[debug] Optional libraries: mutagen, pycryptodome, sqlite, websockets
[debug] Proxy map: {}
[Nebula] Authenticating to Nebula with token from cookie jar
[debug] [Nebula] Extracting URL: https://nebula.app/videos/wendover-productions-the-logistics-of-resettling-afghan-refugees
[Nebula] wendover-productions-the-logistics-of-resettling-afghan-refugees: Downloading webpage
[Nebula] wendover-productions-the-logistics-of-resettling-afghan-refugees: Retrieving Zype API key
[Nebula] wendover-productions-the-logistics-of-resettling-afghan-refugees: Retrieving metadata from Zype
[Nebula] wendover-productions-the-logistics-of-resettling-afghan-refugees: Retrieving Zype access token
[debug] [Zype] Extracting URL: https://player.zype.com/embed/6138d86cb64f790001ac76a0.html?access_token=a7a06f7a1eb41269b3edd5cd2bb8afae132fd9e36e95cf37f61dd2523d2b23bf
[Zype] 6138d86cb64f790001ac76a0: Downloading JSON metadata
[Zype] 6138d86cb64f790001ac76a0: Downloading m3u8 information
WARNING: [Zype] Ignoring subtitle tracks found in the HLS manifest; if any subtitle tracks are missing, please report this issue on  https://github.com/yt-dlp/yt-dlp . Make sure you are using the latest version; see  https://github.com/yt-dlp/yt-dlp  on how to update. Be sure to call yt-dlp with the --verbose flag and include its complete output.
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[info] 6138d86cb64f790001ac76a0: Downloading 1 format(s): hls-4280
[debug] Invoking downloader on "https://mf.zype.com/eyJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2d2c20uenlwZS5jb20vNWMxODJkMDY2NDlmMGYxMzRhMDAxNzAzLzYxMzhkODZjYjY0Zjc5MDAwMWFjNzZhMC82MTM4ZDg2Y2I2NGY3OTAwMDFhYzc2YTEvNTQ1YmRhYjE2OTcwMmQwNWJjMDEwMDAwLzkzMjQ4OGQ1LTUyYTQtNGQ5MS04Mjk4LTlkNDBiZDYyNmI4OC5tM3U4IiwicGFyYW1zIjp7IjZwTEtNUTN5IjoiQTNMemlRM2kiLCJGMzhiMWRGNCI6IjYxMzlmYjYzNWE3MTQwMDAwMTE5ZTQ3YSJ9LCJleHAiOjE2MzEyMDA2NjB9._Ul8q_urpY3mS7vNIg2p6KrN-pI4AzRmAZzPYNiwzTw"
[download] The Logistics of Resettling Afghan Refugees [6138d86cb64f790001ac76a0].mp4 has already been downloaded
[download] 100% of 125.97MiB
WARNING: 6138d86cb64f790001ac76a0: malformed AAC bitstream detected
```
<!--
Do not remove the above ```
-->


## Description

<!--
Provide an explanation of your issue in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.
-->

No subtitles are written to the downloaded file

```
PS C:\temp> ffprobe -i '.\The Logistics of Resettling Afghan Refugees [6138d86cb64f790001ac76a0].mp4'
ffprobe version N-103120-g5b62544dee-gc50f5460d2+4 Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 10.3.0 (Rev5, Built by MSYS2 project)
  configuration:  --pkg-config=pkgconf --cc='ccache gcc' --cxx='ccache g++' --ld='ccache g++' --disable-autodetect --enable-amf --enable-bzlib --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-cuda-llvm --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libaom --disable-debug --enable-libfdk-aac --enable-fontconfig --enable-libass --enable-libbluray --enable-libfreetype --enable-libmfx --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-avisynth --enable-libxvid --enable-libopenmpt --enable-version3 --enable-librav1e --enable-libsrt --enable-libgsm --enable-libvmaf --enable-libsvtav1 --enable-chromaprint --enable-decklink --enable-frei0r --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfribidi --enable-libgme --enable-libilbc --enable-libsvthevc --enable-libsvtvp9 --enable-libkvazaar --enable-libmodplug --enable-librist --enable-librtmp --enable-librubberband --enable-libtesseract --enable-libxavs --enable-libzmq --enable-libzvbi --enable-openal --enable-libcodec2 --enable-ladspa --enable-libglslang --enable-vulkan --enable-libdavs2 --enable-libxavs2 --enable-libuavs3d --enable-opencl --enable-opengl --enable-libopenh264 --enable-openssl --extra-cflags=-DLIBTWOLAME_STATIC --extra-libs=-lstdc++ --extra-cflags=-DCACA_STATIC --extra-cflags=-DMODPLUG_STATIC --extra-cflags=-DCHROMAPRINT_NODLL --extra-libs=-lstdc++ --extra-cflags=-DZMQ_STATIC --extra-libs=-lpsapi --extra-cflags=-DLIBXML_STATIC --extra-libs=-liconv --disable-w32threads --extra-cflags=-DKVZ_STATIC_LIB --enable-nonfree --extra-cflags=-DAL_LIBTYPE_STATIC --extra-cflags='-IC:/temp/media-autobuild/local64/include' --extra-cflags='-IC:/temp/media-autobuild/local64/include/AL'
  libavutil      57.  3.100 / 57.  3.100
  libavcodec     59.  3.102 / 59.  3.102
  libavformat    59.  4.101 / 59.  4.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  1.103 /  8.  1.103
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
Input #0, mpegts, from '.\The Logistics of Resettling Afghan Refugees [6138d86cb64f790001ac76a0].mp4':
  Duration: 00:04:15.81, start: 0.043444, bitrate: 4130 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
  Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn
  Stream #0:1[0x101](eng): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 135 kb/s
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/zype.py b/yt_dlp/extractor/zype.py
--- a/yt_dlp/extractor/zype.py
+++ b/yt_dlp/extractor/zype.py
@@ -56,6 +56,8 @@ def _real_extract(self, url):
         video = response['video']
         title = video['title']
 
+        subtitles = {}
+
         if isinstance(body, dict):
             formats = []
             for output in body.get('outputs', []):
@@ -64,7 +66,7 @@ def _real_extract(self, url):
                     continue
                 name = output.get('name')
                 if name == 'm3u8':
-                    formats = self._extract_m3u8_formats(
+                    formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                         output_url, video_id, 'mp4',
                         'm3u8_native', m3u8_id='hls', fatal=False)
                 else:
@@ -97,7 +99,7 @@ def get_attr(key):
 
                 if get_attr('integration') == 'verizon-media':
                     m3u8_url = 'https://content.uplynk.com/%s.m3u8' % get_attr('id')
-            formats = self._extract_m3u8_formats(
+            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                 m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls')
             text_tracks = self._search_regex(
                 r'textTracks\s*:\s*(\[[^]]+\])',
@@ -107,7 +109,6 @@ def get_attr(key):
                     text_tracks, video_id, js_to_json, False)
         self._sort_formats(formats)
 
-        subtitles = {}
         if text_tracks:
             for text_track in text_tracks:
                 tt_url = dict_get(text_track, ('file', 'src'))


Test patch: