Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.1.2 #48

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

   [![Download PyTube Downloader](https://img.shields.io/sourceforge/dm/pytube-downloader.svg)](https://sourceforge.net/projects/pytube-downloader/files/latest/download) [![Download PyTube Downloader](https://img.shields.io/sourceforge/dw/pytube-downloader.svg)](https://sourceforge.net/projects/pytube-downloader/files/latest/download) [![Download PyTube Downloader](https://img.shields.io/sourceforge/dt/pytube-downloader.svg)](https://sourceforge.net/projects/pytube-downloader/files/latest/download)

   `v2.1.1` [Visit to Download .exe for Windows](https://sourceforge.net/p/pytube-downloader)
   `v2.1.2` [Visit to Download .exe for Windows](https://sourceforge.net/p/pytube-downloader)

---

Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

   [![Download PyTube Downloader](https://img.shields.io/sourceforge/dm/pytube-downloader.svg)](https://sourceforge.net/projects/pytube-downloader/files/latest/download) [![Download PyTube Downloader](https://img.shields.io/sourceforge/dw/pytube-downloader.svg)](https://sourceforge.net/projects/pytube-downloader/files/latest/download) [![Download PyTube Downloader](https://img.shields.io/sourceforge/dt/pytube-downloader.svg)](https://sourceforge.net/projects/pytube-downloader/files/latest/download)

   `v2.1.1` [下载适用于 Windows 的 .exe](https://sourceforge.net/p/pytube-downloader)
   `v2.1.2` [下载适用于 Windows 的 .exe](https://sourceforge.net/p/pytube-downloader)

---

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.1.1'
VERSION = '2.1.2'
5 changes: 3 additions & 2 deletions data/general.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
{
"alerts": true,
"automatic_download": {
"quality": 0,
"status": "disable"
Expand All @@ -15,5 +16,5 @@
"re_download_automatically": false,
"reload_automatically": false,
"update_delay": 0.5,
"window_geometry": "900x500+0+0"
"window_geometry": "900x500+-7+0"
}
2 changes: 1 addition & 1 deletion data/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"contributors": {},
"name": "PyTube Downloader",
"site": "https://github.com/Thisal-D/PyTube-Downloader",
"version": "2.1.1"
"version": "2.1.2"
}
3 changes: 2 additions & 1 deletion data/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@
"force_exit": "Force Exit",
"minimize_to_tray": "Minimize To Tray",
"reset": "Reset",
"update_alert": "A new update is available! \nVisit the official website to download the \nlatest version."
"update_alert": "A new update is available! \nVisit the official website to download the \nlatest version.",
"alerts" : "Alerts"
}
3 changes: 2 additions & 1 deletion data/languages/si.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"force_exit": "පිටවීම",
"minimize_to_tray": "ට්‍රේ එකට Minimize කරන්න",
"reset": "නෑවත සකසන්න",
"update_alert": "නව අනුවාදයක් තිබේ!\nනවතම අනුවාදය බාගැනීමට කරුණාකර \nනිල වෙබ් අඩවියට පිවිසෙන්න."
"update_alert": "නව අනුවාදයක් තිබේ!\nනවතම අනුවාදය බාගැනීමට කරුණාකර \nනිල වෙබ් අඩවියට පිවිසෙන්න.",
"alerts": "දැනුම්දීම්"
}

3 changes: 2 additions & 1 deletion data/languages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@
"force_exit": "强制退出",
"minimize_to_tray": "最小化到托盘",
"reset": "重置",
"update_alert": "有新版本可用!\n请访问官方网站下载最新版本。"
"update_alert": "有新版本可用!\n请访问官方网站下载最新版本。",
"alerts": "警报"
}
59 changes: 52 additions & 7 deletions settings/general_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ class GeneralSettings:
backup_path = backup_dir + "\\general.json"
default_download_dir = f"C:\\users\\{os.getlogin()}\\downloads\\PyTube Downloader\\"

SETTINGS = {
"automatic_download": {
"quality": 0,
"status": "disable"
},
"create_sep_path_for_playlists": False,
"create_sep_path_for_qualities": False,
"create_sep_path_for_videos_audios": False,
"download_directory": False,
"lang_code": "en",
"language": "English",
"load_thumbnail": True,
"max_simultaneous_downloads": 1,
"max_simultaneous_loads": 1,
"re_download_automatically": False,
"reload_automatically": False,
"update_delay": 0.5,
"alerts": True,
"window_geometry": "900x500-7+0"
}

@staticmethod
def initialize() -> None:
"""
Expand All @@ -29,14 +50,15 @@ def initialize() -> None:
GeneralSettings.create_backup()

if backup_exists and FileUtility.is_accessible(GeneralSettings.backup_dir):
settings = JsonUtility.read_from_file(GeneralSettings.backup_path)
GeneralSettings.settings = JsonUtility.read_from_file(GeneralSettings.backup_path)
else:
settings = JsonUtility.read_from_file(GeneralSettings.file_path)

if settings.get("download_directory") is False:
settings["download_directory"] = GeneralSettings.default_download_dir

GeneralSettings.settings = settings
GeneralSettings.settings = JsonUtility.read_from_file(GeneralSettings.file_path)

if not GeneralSettings.are_all_keys_present():
GeneralSettings.add_missing_keys()

if GeneralSettings.settings.get("download_directory") is False:
GeneralSettings.settings["download_directory"] = GeneralSettings.default_download_dir

@staticmethod
def save_settings() -> None:
Expand All @@ -58,6 +80,29 @@ def is_backup_exists() -> bool:
return True
return False

@staticmethod
def are_all_keys_present() -> bool:
"""
Check if all required settings keys are present in the initialized settings.

Returns:
bool: True if all keys exist, False otherwise.
"""
for key in GeneralSettings.SETTINGS.keys():
if key not in GeneralSettings.settings.keys():
return False
return True

def add_missing_keys() -> None:
"""
Add any missing keys from the default settings to the initialized settings.

This ensures that the settings include all required keys with their default values.
"""
for key in GeneralSettings.SETTINGS.keys():
if key not in GeneralSettings.settings.keys():
GeneralSettings.settings[key] = GeneralSettings.SETTINGS[key]

@staticmethod
def create_backup() -> None:
FileUtility.create_directory(GeneralSettings.backup_dir)
Expand Down
2 changes: 1 addition & 1 deletion widgets/core_widgets/setting_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
self.set_widgets_accent_color()
self.set_widgets_sizes()
self.place_widgets()

def place_widgets(self) -> None:
self.navigation_panel.pack(side="left", fill="y")
self.vertical_line.pack(side="left", fill="y")
Expand Down
51 changes: 26 additions & 25 deletions widgets/play_list/downloading_play_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def videos_status_track(
self.downloading_videos.remove(video)
if video in self.paused_videos:
self.paused_videos.remove(video)
self.show_notification_for_video_state(self.failed_videos[-1])
self.show_notification(self.failed_videos[-1])
elif state == "downloading":
self.downloading_videos.append(video)
if video in self.waiting_videos:
Expand All @@ -146,7 +146,7 @@ def videos_status_track(
elif state == "downloaded":
self.downloaded_videos.append(video)
self.downloading_videos.remove(video)
self.show_notification_for_video_state(self.downloaded_videos[-1])
self.show_notification(self.downloaded_videos[-1])

# if len is 0 that means all videos are remove :D
if len(self.videos) != 0:
Expand Down Expand Up @@ -231,29 +231,30 @@ def set_downloading_completed(self):
self.playlist_download_complete_callback(self)
self.kill()

def show_notification_for_video_state(self, video: DownloadingVideo):
if video.download_state == "downloaded":
if self.playlist_video_count == len(self.downloaded_videos):
status_message = "Download Completed..!"
else:
status_message = "Downloading..."
elif video.download_state == "failed":
status_message = "Download Failed..!"
# Show Download completed Notification
NotificationManager.register(
playlist_title=self.playlist_title,
video_title=video.video_title,
channel_name=self.channel,
status_message=status_message,
total_videos_count=self.playlist_video_count,
completed_videos_count=len(self.downloaded_videos),
download_directory=video.download_directory,
download_file_name=video.download_file_name,
downloaded_file_size=video.bytes_downloaded,
download_mode=video.mode,
download_status=video.download_state,
thumbnail_path=video.notification_thumbnail_image_path
)
def show_notification(self, video: DownloadingVideo):
if GeneralSettings.settings["alerts"]:
if video.download_state == "downloaded":
if self.playlist_video_count == len(self.downloaded_videos):
status_message = "Download Completed..!"
else:
status_message = "Downloading..."
elif video.download_state == "failed":
status_message = "Download Failed..!"
# Show Download completed Notification
NotificationManager.register(
playlist_title=self.playlist_title,
video_title=video.video_title,
channel_name=self.channel,
status_message=status_message,
total_videos_count=self.playlist_video_count,
completed_videos_count=len(self.downloaded_videos),
download_directory=video.download_directory,
download_file_name=video.download_file_name,
downloaded_file_size=video.bytes_downloaded,
download_mode=video.mode,
download_status=video.download_state,
thumbnail_path=video.notification_thumbnail_image_path
)

# create widgets
def create_widgets(self):
Expand Down
55 changes: 52 additions & 3 deletions widgets/setting_panels/general_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ def __init__(
)
self.shortcut_keys_widgets_info.append(shortcut_keys_widgets_info_dict)

self.alerts_state_label = ctk.CTkLabel(
master=self,
text_color=AppearanceSettings.settings["settings_panel"]["text_color"]
)

self.dash3_label = ctk.CTkLabel(
master=self,
text=":",
text_color=AppearanceSettings.settings["settings_panel"]["text_color"]
)

self.alerts_state_switch_state = ctk.BooleanVar(value=None)
self.alerts_state_change_switch = ctk.CTkSwitch(
master=self,
text="",
command=self.change_alerts_state,
onvalue=True,
offvalue=False,
variable=self.alerts_state_switch_state
)

self.settings_reset_button = ctk.CTkButton(master=self, text_color=AppearanceSettings.settings["settings_panel"]["text_color"], command=self.reset_settings)

# callbacks for settings changes
Expand All @@ -113,8 +134,15 @@ def __init__(
def reset_settings(self):
# Reset language to english and apply it
self.languages_combo_box.set("English")
self.alerts_state_change_switch.select()
self.change_alerts_state()

self.apply_language("English")

def change_alerts_state(self):
GeneralSettings.settings["alerts"] = self.alerts_state_switch_state.get()
self.general_settings_change_callback()

def apply_language(self, language: str) -> None:
lang_code = self.language_data[language]
if lang_code != GeneralSettings.settings["lang_code"]:
Expand All @@ -136,6 +164,12 @@ def set_widgets_accent_color(self):
fg_color=AppearanceSettings.settings["root"]["accent_color"]["normal"],
hover_color=AppearanceSettings.settings["root"]["accent_color"]["hover"]
)

self.alerts_state_change_switch.configure(
button_color=AppearanceSettings.settings["root"]["accent_color"]["normal"],
button_hover_color=AppearanceSettings.settings["root"]["accent_color"]["hover"],
progress_color=AppearanceSettings.settings["root"]["accent_color"]["hover"]
)

def update_widgets_accent_color(self):
"""
Expand Down Expand Up @@ -170,8 +204,12 @@ def place_widgets(self):
shortcut_widget_info["key_frame"].grid(row=i, column=2, pady=(4 * scale, 0), sticky="w")
for button in shortcut_widget_info["buttons"]:
button.pack(side="left", padx=(2 * scale, 0))

self.settings_reset_button.grid(row=2, column=2, padx=(100, 0), pady=(pady, 0), sticky="e")

self.alerts_state_label.grid(row=2, column=0, padx=(100, 0), pady=(pady, 0), sticky="w")
self.dash3_label.grid(row=2, column=1, padx=(30, 30), pady=(pady, 0), sticky="w")
self.alerts_state_change_switch.grid(row=2, column=2, padx=(0, 0), pady=(pady, 0), sticky="w")

self.settings_reset_button.grid(row=3, column=2, padx=(100, 0), pady=(pady, 0), sticky="s")

def set_widgets_sizes(self):
scale = AppearanceSettings.settings["scale_r"]
Expand All @@ -183,6 +221,8 @@ def set_widgets_sizes(self):
for button in shortcut_widget_info["buttons"]:
button.configure(width=1, height=24 * scale)

self.alerts_state_change_switch.configure(switch_width=36 * scale, switch_height=18 * scale)

self.settings_reset_button.configure(width=80*scale, height=24 * scale)

def set_widgets_texts(self):
Expand All @@ -196,6 +236,10 @@ def set_widgets_texts(self):
text=LanguageManager.data["reset"]
)

self.alerts_state_label.configure(
text=LanguageManager.data["alerts"]
)

def update_widgets_text(self):
self.set_widgets_texts()

Expand All @@ -207,7 +251,8 @@ def set_widgets_fonts(self):
self.dash1_label.configure(font=title_font)
self.shortcut_label.configure(font=title_font)
self.dash2_label.configure(font=title_font)

self.alerts_state_label.configure(font=title_font)

value_font = ("Segoe UI", 13 * scale, "normal")
self.languages_combo_box.configure(font=value_font, dropdown_font=value_font)

Expand All @@ -230,3 +275,7 @@ def set_widgets_values(self):
set values for widgets using saved settings.
"""
self.languages_combo_box.set(GeneralSettings.settings["language"])

if GeneralSettings.settings["alerts"]:
self.alerts_state_change_switch.select()
self.alerts_state_switch_state.set(True)
39 changes: 20 additions & 19 deletions widgets/video/downloading_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def set_downloading_failed(self):
anchor="w",
relx=1,
x=-80 * AppearanceSettings.settings["scale_r"])

if self.mode == "video":
self.show_notification()

Expand Down Expand Up @@ -381,24 +381,25 @@ def set_downloading_completed(self):
self.kill()

def show_notification(self):
if self.download_state == "downloaded":
status_message = "Download Completed..!"
else:
status_message = "Download Failed..!"
# Show Download completed Notification
NotificationManager.register(
video_title=self.video_title,
channel_name=self.channel,
status_message=status_message,
download_type="{}/{}".format(self.download_type, self.download_quality),
file_size=self.file_size,
download_directory=self.download_directory,
download_file_name=self.download_file_name,
downloaded_file_size=self.bytes_downloaded,
download_mode=self.mode,
download_status=self.download_state,
thumbnail_path=self.notification_thumbnail_image_path
)
if GeneralSettings.settings["alerts"]:
if self.download_state == "downloaded":
status_message = "Download Completed..!"
else:
status_message = "Download Failed..!"
# Show Download completed Notification
NotificationManager.register(
video_title=self.video_title,
channel_name=self.channel,
status_message=status_message,
download_type="{}/{}".format(self.download_type, self.download_quality),
file_size=self.file_size,
download_directory=self.download_directory,
download_file_name=self.download_file_name,
downloaded_file_size=self.bytes_downloaded,
download_mode=self.mode,
download_status=self.download_state,
thumbnail_path=self.notification_thumbnail_image_path
)

# create widgets
def create_widgets(self):
Expand Down