From ea7bff363236789cb106da8852b7ab1c2325ff2b Mon Sep 17 00:00:00 2001 From: ZhanZiyuan <154674404+ZhanZiyuan@users.noreply.github.com> Date: Sat, 15 Feb 2025 10:30:54 +0800 Subject: [PATCH 1/2] Refactored the file path handling in the main script. - Replaced `os.path` module with `pathlib` for the file path handling to improve code readability and simplicity. --- yt_dlp/__main__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/yt_dlp/__main__.py b/yt_dlp/__main__.py index 06c392039..8f382ef87 100644 --- a/yt_dlp/__main__.py +++ b/yt_dlp/__main__.py @@ -4,14 +4,15 @@ # $ python3 -m yt_dlp import sys - -if __package__ is None and not getattr(sys, 'frozen', False): - # direct call of __main__.py - import os.path - path = os.path.realpath(os.path.abspath(__file__)) - sys.path.insert(0, os.path.dirname(os.path.dirname(path))) +from pathlib import Path import yt_dlp +if __package__ is None and not getattr(sys, 'frozen', False): + # direct call of __main__.py + path = Path(__file__).resolve() + sys.path.insert(0, str(path.parent.parent)) + if __name__ == '__main__': + yt_dlp.main() From 2df5c07325d41210048fb5fde089fd8ff9bb4508 Mon Sep 17 00:00:00 2001 From: Zhan Ziyuan <154674404+ZhanZiyuan@users.noreply.github.com> Date: Sat, 15 Feb 2025 19:25:12 +0800 Subject: [PATCH 2/2] Moved `import yt_dlp`. Moved `import yt_dlp` in `__main__.py`. --- yt_dlp/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yt_dlp/__main__.py b/yt_dlp/__main__.py index 8f382ef87..70bc52323 100644 --- a/yt_dlp/__main__.py +++ b/yt_dlp/__main__.py @@ -6,13 +6,13 @@ import sys from pathlib import Path -import yt_dlp - if __package__ is None and not getattr(sys, 'frozen', False): # direct call of __main__.py path = Path(__file__).resolve() sys.path.insert(0, str(path.parent.parent)) +import yt_dlp + if __name__ == '__main__': yt_dlp.main()