aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/downloader/fragment.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-08-09 17:40:24 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-08-10 01:22:55 +0530
commitad3dc496bbf2e2a574a16244ddde0740778e5daf (patch)
treef4eeaf0711946c1181ce1769c33d8ff94c3847cd /yt_dlp/downloader/fragment.py
parent2831b4686c2436cd151260539e010ce3577911cc (diff)
downloadhypervideo-pre-ad3dc496bbf2e2a574a16244ddde0740778e5daf.tar.lz
hypervideo-pre-ad3dc496bbf2e2a574a16244ddde0740778e5daf.tar.xz
hypervideo-pre-ad3dc496bbf2e2a574a16244ddde0740778e5daf.zip
Misc fixes - See desc
* Remove unnecessary uses of _list_from_options_callback * Fix download tests - Bug from 6e84b21559f586ee4d6affb61688d5c6a0c21221 * Rename ExecAfterDownloadPP to ExecPP and refactor its tests * Ensure _write_ytdl_file closes file handle on error - Potential fix for #517
Diffstat (limited to 'yt_dlp/downloader/fragment.py')
-rw-r--r--yt_dlp/downloader/fragment.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/yt_dlp/downloader/fragment.py b/yt_dlp/downloader/fragment.py
index 88238b64d..1cc99a4e9 100644
--- a/yt_dlp/downloader/fragment.py
+++ b/yt_dlp/downloader/fragment.py
@@ -105,17 +105,19 @@ class FragmentFD(FileDownloader):
def _write_ytdl_file(self, ctx):
frag_index_stream, _ = sanitize_open(self.ytdl_filename(ctx['filename']), 'w')
- downloader = {
- 'current_fragment': {
- 'index': ctx['fragment_index'],
- },
- }
- if 'extra_state' in ctx:
- downloader['extra_state'] = ctx['extra_state']
- if ctx.get('fragment_count') is not None:
- downloader['fragment_count'] = ctx['fragment_count']
- frag_index_stream.write(json.dumps({'downloader': downloader}))
- frag_index_stream.close()
+ try:
+ downloader = {
+ 'current_fragment': {
+ 'index': ctx['fragment_index'],
+ },
+ }
+ if 'extra_state' in ctx:
+ downloader['extra_state'] = ctx['extra_state']
+ if ctx.get('fragment_count') is not None:
+ downloader['fragment_count'] = ctx['fragment_count']
+ frag_index_stream.write(json.dumps({'downloader': downloader}))
+ finally:
+ frag_index_stream.close()
def _download_fragment(self, ctx, frag_url, info_dict, headers=None, request_data=None):
fragment_filename = '%s-Frag%d' % (ctx['tmpfilename'], ctx['fragment_index'])