From 7c58b5148d58adf1293d9b651d83bc0bc1781e67 Mon Sep 17 00:00:00 2001 From: Rob Date: Sun, 3 May 2020 23:17:58 -0700 Subject: [PATCH 1/5] Adding chmod step to write_json_file to keep permissions in line with other files such as description, jpg, and annotations. This is to resolve https://github.com/ytdl-org/youtube-dl/issues/12471 tempfile on linux will make a file that is readonly for the user with all other permission bits turned off. Tempfile is only used for the info.json files. This makes it unique when compared to jpg, annotations, description, and other files that youtube-dl can retrieve or create. --- youtube_dl/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 38262bee4..0f36466ed 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -27,6 +27,7 @@ import random import re import socket import ssl +import stat import subprocess import sys import tempfile @@ -1835,6 +1836,12 @@ def write_json_file(obj, fn): os.unlink(fn) except OSError: pass + os.chmod(tf.name, + stat.S_IRUSR | + stat.S_IWUSR | + stat.S_IRGRP | + stat.S_IROTH) + os.rename(tf.name, fn) except Exception: try: From 177a9ad6cc854902972db1fa771e75d5bebd612f Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 4 May 2020 00:15:44 -0700 Subject: [PATCH 2/5] Revert "Adding Audio and Visual converter for ffmpeg." This reverts commit 4aafb9a5e7e1728bf728a3f8c572cfa4454a6771. --- youtube_dl/postprocessor/__init__.py | 2 -- youtube_dl/postprocessor/ffmpeg.py | 54 ++++------------------------ 2 files changed, 6 insertions(+), 50 deletions(-) diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py index 734bb8b9b..3ea518399 100644 --- a/youtube_dl/postprocessor/__init__.py +++ b/youtube_dl/postprocessor/__init__.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from .embedthumbnail import EmbedThumbnailPP from .ffmpeg import ( FFmpegPostProcessor, - FFmpegAVConvertorPP, FFmpegEmbedSubtitlePP, FFmpegExtractAudioPP, FFmpegFixupStretchedPP, @@ -26,7 +25,6 @@ def get_postprocessor(key): __all__ = [ 'EmbedThumbnailPP', 'ExecAfterDownloadPP', - 'FFmpegAVConvertorPP', 'FFmpegEmbedSubtitlePP', 'FFmpegExtractAudioPP', 'FFmpegFixupM3u8PP', diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py index c482c841c..fd3f921a8 100644 --- a/youtube_dl/postprocessor/ffmpeg.py +++ b/youtube_dl/postprocessor/ffmpeg.py @@ -2,7 +2,6 @@ from __future__ import unicode_literals import io import os -import shutil import subprocess import time import re @@ -351,10 +350,9 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor): class FFmpegVideoConvertorPP(FFmpegPostProcessor): - def __init__(self, downloader=None, preferedformat=None, outpath=None): + def __init__(self, downloader=None, preferedformat=None): super(FFmpegVideoConvertorPP, self).__init__(downloader) self._preferedformat = preferedformat - self._outpath = outpath def run(self, information): path = information['filepath'] @@ -364,56 +362,16 @@ class FFmpegVideoConvertorPP(FFmpegPostProcessor): options = [] if self._preferedformat == 'avi': options.extend(['-c:v', 'libxvid', '-vtag', 'XVID']) - if not self._outpath: - prefix, sep, ext = path.rpartition('.') - self._outpath = prefix + sep + self._preferedformat - self._downloader.to_screen('[' + 'ffmpeg' + '] Converting video from %s to %s, Destination: ' % (information['ext'], self._preferedformat) + self._outpath) - self.run_ffmpeg(path, self._outpath, options) - information['filepath'] = self._outpath + prefix, sep, ext = path.rpartition('.') + outpath = prefix + sep + self._preferedformat + self._downloader.to_screen('[' + 'ffmpeg' + '] Converting video from %s to %s, Destination: ' % (information['ext'], self._preferedformat) + outpath) + self.run_ffmpeg(path, outpath, options) + information['filepath'] = outpath information['format'] = self._preferedformat information['ext'] = self._preferedformat return [path], information -class FFmpegAVConvertorPP(FFmpegPostProcessor): - def __init__(self, downloader=None, preferedvformat=None, preferedaformat=None, preferredquality=None): - super(FFmpegAVConvertorPP, self).__init__(downloader) - self._downloader = downloader - self._preferedaformat = preferedaformat - self._preferedvformat = preferedvformat - self._preferredquality = preferredquality - - def run(self, information): - path = information['filepath'] - paths_to_remove = [] - prefix, sep, ext = path.rpartition('.') - tmp_file = prefix + '.tmp' + sep + self._preferedvformat - if ext != self._preferedvformat: - tmp_file = prefix + '.tmp' + sep + self._preferedvformat - vc = FFmpegVideoConvertorPP(downloader=self._downloader, - preferedformat=self._preferedvformat, - outpath=tmp_file) - path_list, information = vc.run(information) - paths_to_remove.append(path_list[0]) - elif self.get_audio_codec(path) != self._preferedaformat: - information['filepath'] = tmp_file - shutil.move(path, tmp_file) - else: - self._downloader.to_screen('[ffmpeg] Not converting video file %s - ' - 'already is in target format %s:%s' % - (path, self._preferedvformat, self._preferedaformat)) - return [], information - - path = information['filepath'] - if self.get_audio_codec(path) != self._preferedaformat: - output = prefix + sep + self._preferedvformat - aformat = self._preferedaformat - quality = self._preferredquality + 'k' - self.run_ffmpeg(path, output, ['-c:v', 'copy', '-c:a', aformat, '-b:a', quality]) - paths_to_remove.append(path) - return paths_to_remove, information - - class FFmpegEmbedSubtitlePP(FFmpegPostProcessor): def run(self, information): if information['ext'] not in ('mp4', 'webm', 'mkv'): From bf4361ae92cabc8e62b149b6d7bf4b75040d0859 Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 4 May 2020 12:11:35 -0700 Subject: [PATCH 3/5] Adding additional permissions and respecting umask --- youtube_dl/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 0f36466ed..8d3142e81 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1836,11 +1836,16 @@ def write_json_file(obj, fn): os.unlink(fn) except OSError: pass + mask = os.umask(0) + os.umask(mask) os.chmod(tf.name, - stat.S_IRUSR | - stat.S_IWUSR | - stat.S_IRGRP | - stat.S_IROTH) + (stat.S_IRUSR + | stat.S_IWUSR + | stat.S_IRGRP + | stat.S_IWGRP + | stat.S_IROTH + | stat.S_IWOTH) + & ~mask) os.rename(tf.name, fn) except Exception: From ac6256f9a0a89650426cae18bfe6e93c1bb2f8a5 Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 19 May 2020 12:41:32 -0700 Subject: [PATCH 4/5] Fixing white space, adding try/except block, and specifying permissions without stat. --- youtube_dl/utils.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 8d3142e81..ca4061f30 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1836,17 +1836,12 @@ def write_json_file(obj, fn): os.unlink(fn) except OSError: pass - mask = os.umask(0) - os.umask(mask) - os.chmod(tf.name, - (stat.S_IRUSR - | stat.S_IWUSR - | stat.S_IRGRP - | stat.S_IWGRP - | stat.S_IROTH - | stat.S_IWOTH) - & ~mask) - + try: + mask = os.umask(0) + os.umask(mask) + os.chmod(tf.name, 0o666 & ~mask) + except OSError: + pass os.rename(tf.name, fn) except Exception: try: From 86a41535dc04e2781f739fa1d5baf528949936bc Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 19 May 2020 12:49:20 -0700 Subject: [PATCH 5/5] Removing stat as unused import. --- youtube_dl/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index ca4061f30..b8c9f3471 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -27,7 +27,6 @@ import random import re import socket import ssl -import stat import subprocess import sys import tempfile