Skip to content

Commit

Permalink
Code Quality fixes for yt_manager.py
Browse files Browse the repository at this point in the history
renamed yt-manager.py to yt_manager.py to match convention
  • Loading branch information
j54j6 committed May 12, 2024
1 parent 32ad80b commit 6aaf5bc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
14 changes: 7 additions & 7 deletions project_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,19 @@ def validate_scheme(url, scheme, silent=False):
logging.error("Provided Scheme is not valid! - Check log")
return False

parsed_url = tldextract.extract(url)
parsedUurl = tldextract.extract(url)
#Check if the provided url matches the filter of the given scheme
if not parsed_url.suffix in scheme["url_scheme"]["tld"]:
if not parsedUurl.suffix in scheme["url_scheme"]["tld"]:
if not silent:
logging.error(f"Provided url does not match the requirements for the {parsed_url.domain} scheme! - TLD '{parsed_url.suffix}' is not supported! - scheme name: {scheme["schema_name"]}")
logging.error(f"Provided url does not match the requirements for the {parsedUurl.domain} scheme! - TLD '{parsedUurl.suffix}' is not supported! - scheme name: {scheme["schema_name"]}")
return False
if not parsed_url.domain in scheme["url_scheme"]["sld"]:
if not parsedUurl.domain in scheme["url_scheme"]["sld"]:
if not silent:
logging.error(f"Provided url does not match the requirements for the {parsed_url.domain} scheme! - SLD '{parsed_url.domain}' is not supported! - scheme name: {scheme["schema_name"]}")
logging.error(f"Provided url does not match the requirements for the {parsedUurl.domain} scheme! - SLD '{parsedUurl.domain}' is not supported! - scheme name: {scheme["schema_name"]}")
return False
if not parsed_url.subdomain in scheme["url_scheme"]["subd"]:
if not parsedUurl.subdomain in scheme["url_scheme"]["subd"]:
if not silent:
logging.error(f"Provided url does not match the requirements for the {parsed_url.domain} scheme! - Subdomain '{parsed_url.subdomain}' is not supported! - scheme name: {scheme["schema_name"]}")
logging.error(f"Provided url does not match the requirements for the {parsedUurl.domain} scheme! - Subdomain '{parsedUurl.subdomain}' is not supported! - scheme name: {scheme["schema_name"]}")
return False
return True

Expand Down
70 changes: 41 additions & 29 deletions yt-manager.py → yt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@

#
# Project by j54j6
# This program is used to make a private copy of youtube videos and potentially
# other websites supported by youtubedl Furthermore it supports automatic
# This program is used to make a private copy of youtube videos and potentially
# other websites supported by youtubedl Furthermore it supports automatic
# periodic checking of channels and auto downloading.
# It also checks if the downlaoded video already exists in the
# It also checks if the downlaoded video already exists in the
# specified storage space and checks
# integrity of videos and redownload them if needed
#


#
# This file contains the "User Logic" this means that all User
# This file contains the "User Logic" this means that all User
# Experience related stuff is located in here and also the "main Controls"
# In general this projects is made out of different modules (see ReadME ).
# In general this projects is made out of different modules (see ReadME ).
# This file combines them...
#


# Own Modules
from project_functions import check_dependencies, show_help, direct_download, scheme_setup
from database_manager import check_db
from config_handler import check_for_config
# Python Modules
import logging
import sys
import pathlib
#import argparse

# Own Modules
from project_functions import show_help, direct_download, scheme_setup
from database_manager import check_db
from config_handler import check_for_config


# Init. Logging
logging.getLogger(__name__).addHandler(logging.StreamHandler(sys.stdout))
Expand All @@ -38,31 +37,44 @@
logger.info("Running startup checks...")

#Check for config File
config_loaded = check_for_config()
if not config_loaded:
configLoaded = check_for_config()
if not configLoaded:
logger.error("Error while loading config! - Check log...")
exit()
sys.exit()

#Check for database and init
database_check_successful = check_db()
if not database_check_successful:
databaseCheckSuccessful = check_db()
if not databaseCheckSuccessful:
logging.error("Error while initializing DB! - Please check log...")
exit()
sys.exit()

#Check database content
dependencies = scheme_setup()

if not dependencies:
logging.error("Error while prepare dependencies... Check log.")
exit()
sys.exit()

#All Tables exists needed to run this thing...
logging.info("All mandatory tables are existing...")

#TODO
#parser = parser = argparse.ArgumentParser(description="YT-DL Manager - Download and manage Videos from different sources. Further you can download new content completly automatic")
#parser.add_argument("command", type=str, choices=["help", "add-subscription", "del-subscription", "list-subscriptions", "custom", "start", "validate"], help="Command - What do you want to do?")
#parser.add_argument("--url", help="Url to add a subscription or directly download a video", default=None)
#POSTPONED
#parser = argparse.ArgumentParser(
#description="""YT-DL Manager - Download and manage Videos from different sources.
# Further you can download new content completly automatic""")
#parser.add_argument("command",
# type=str,
# choices=["help",
# "add-subscription",
# "del-subscription",
# "list-subscriptions",
# "custom",
# "start",
# "validate"],
#help="Command - What do you want to do?")
#parser.add_argument("--url",
# help="Url to add a subscription or directly download a video",
# default=None)

#args = parser.parse_args()

Expand All @@ -74,17 +86,17 @@
case "help":
#provide help
show_help()
exit()
sys.exit()
case "add-subscription":
#Add a new subscription

exit()
sys.exit()
case "del-subscription":
#Delete a subscription
exit()
sys.exit()
case "list-subscriptions":
#Show all subscriptions
exit()
sys.exit()
case "custom":
#Download a custom Item without being part of a subscription
#parser = argparse
Expand All @@ -93,12 +105,12 @@
else:
logging.error("No url provided!")
show_help()
exit()
sys.exit()
case "start":
#Run the script to check for new content and download it
exit()
sys.exit()
case "validate":
#Rehash all files and compare them to the already stored files.
exit()
sys.sys.exit()
else:
show_help()

0 comments on commit 6aaf5bc

Please sign in to comment.