diff --git a/README.md b/README.md index 29bf611..ed1f7c1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # YoutubeDL-Dowloader - This little program is supposed to help you to make a private copy of videos from sites supporting youtube-dl. Currently many sites like youtube, NYT, CNBC but also adult sites like Pornhub 91porn and much more. Feel Free to use it ^^ + This little program is supposed to help you to make a private copy of videos from sites supporting youtube-dl. Currently many sites like youtube, NYT, CNBC but also adult sites like Pornhub 91porn and much more support youtube-dl. Feel Free to use it but be aware about legal discussions - This Repo is jsut a project to show that this is in general working.^^ + I am not responsible for any damages or anything else. You use this program on your OWN RISK + + + # Architecure + In General this program is built out of different modules. Each module handles some parts of the program needed to work as a whole. + To ensure compatibility for different sites I utilize so called "schemes". Every supporterd site has its own scheme. Please feel free to built your own and send it to me :) - We can help each other with these and I am not capable of providing a scheme for each supported site ;) + I provide some of then when requested and I have spare time. + + #Schemas + Schemas are heavily used inside this project. They utilize different functions and can be used to dynamically change the behaviour of the program without any code knowledge. + Schemas are used for 2 types + 1. Configuration -> It is possible to create database blueprints with schemas (like project.json file). + 2. Websites -> To ensure future compatibility all website specific stuff is located inside a schema per website. If anything changes on the website it should be possible to alter the file and make iot work again (maybe due to a new header or something else...) + +Supported values: + Database Configuration: + If you want to create a table inside the main database you can utilize the "db" key. If defined the program will create a table with the given columns and if you want also default rows. + For reference please check the project.json file as a reference :) diff --git a/config.json b/config.json new file mode 100644 index 0000000..e69de29 diff --git a/config_handler.py b/config_handler.py new file mode 100644 index 0000000..3ba0bd2 --- /dev/null +++ b/config_handler.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +# +# Project by j54j6 +# This file provides a simple abstraction layer to handle ini configuration files +# + +# Python Modules +import logging +import pathlib +from pathlib import Path +import os +from configparser import ConfigParser + +# init logger +logger = logging.getLogger(__name__) + +# init configParser +config:ConfigParser = ConfigParser() + +#default config_name +default_config_name:str = "config.ini" + + + +def create_default_config(path): + #Add Default configuration for values needed for the whole project + config.add_section('main') + config.set('main', 'db_name', 'database.db') + config.set('main', 'db_path', './') + + try: + with open(path, 'w') as f: + config.write(f) + return True + except Exception as e: + logger.error("Error while creating default config! - Error: %s", e) + return False + + +def check_for_config(path=False): + #As fallback (per Default) the config is located in the same folder as the main.py. Set the default search path to the current file dir. + check_path:Path = pathlib.Path(__file__).parent.resolve() + check_path = Path.joinpath(check_path, default_config_name) + + #Check if a path is provided (Path != False). If so change the check_path to the given path and not to the current dir + if(path != False): + try: + if path.lower().endwith(".ini"): + check_path = Path(path) + else: + logger.error("The given file %s does not end with \".ini\". Only INI Files are supported") + exit() + except Exception as e: + logger.error("Error while converting given configuration path to Path Object. Error: %s", e) + exit() + + logger.info("Check for config file. Provided path: %s", path) + + #Check if check_path exists on the filesystem + if not os.path.exists(check_path): + logger.error("Config file does not exist! - Create default config...") + config_created:bool = create_default_config() + + if(not config_created): + exit() + + #Config File exists - check if it is valid json (load file) + try: + config.read(check_path) + except Exception as e: + logger.error("Error while reading configuration file! - Error: %s", e) + exit() + return True + + \ No newline at end of file diff --git a/database_manager.py b/database_manager.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..64f75c8 --- /dev/null +++ b/main.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +# +# 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 periodic checking of channels and auto downloading. +# 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 Experience related stuff is located in here and also the "main Controls" +# In general this projects is made out of different modules (see ReadME ). This file combines them... +# + + +# Own Modules +from project_functions import check_dependencies, check_db +from config_handler import config, check_for_config +# Python Modules +import logging + +# Init. Logging +logger = logging.getLogger(__name__) + + + +def main(): + logger.info("Running startup checks...") + #Check for config File + config_loaded = check_for_config() + if not config_loaded: + logger.error("Error while loading config! - Check log...") + exit() + + + diff --git a/project_functions.py b/project_functions.py new file mode 100644 index 0000000..2659412 --- /dev/null +++ b/project_functions.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +# +# 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 periodic checking of channels and auto downloading. +# 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 "Project specific funtions" this means that all functions I cannot reuse in other projects +# like controls or checks are located inside this file. +# + +def check_dependencies(): + return + +def check_db(): + return \ No newline at end of file diff --git a/scheme/disney.json b/scheme/disney.json new file mode 100644 index 0000000..e69de29 diff --git a/scheme/peertube.json b/scheme/peertube.json new file mode 100644 index 0000000..e69de29 diff --git a/scheme/pinterest.json b/scheme/pinterest.json new file mode 100644 index 0000000..e69de29 diff --git a/scheme/project.json b/scheme/project.json new file mode 100644 index 0000000..79f41a1 --- /dev/null +++ b/scheme/project.json @@ -0,0 +1,16 @@ +{ + "schema_name": "project", + "db": { + "table_needed": true, + "table_name": "config", + "columns": { + "id": ["integer PRIMARY KEY"], + "option": ["text"], + "value": ["text"], + "datecreated": ["DATETIME DEFAULT CURRENT_TIMESTAMP"] + }, + "rows": [ + {"option": "location", "value": "./"} + ] + } +} \ No newline at end of file diff --git a/scheme/saved_items.json b/scheme/saved_items.json new file mode 100644 index 0000000..5577f61 --- /dev/null +++ b/scheme/saved_items.json @@ -0,0 +1,17 @@ +{ + "schema_name": "items", + "db": { + "table_needed": true, + "table_name": "items", + "columns": { + "id": ["integer PRIMARY KEY"], + "scheme": ["text"], + "file_name": ["text"], + "file_path": ["text"], + "file_hash": ["text"], + "created": ["DATETIME DEFAULT CURRENT_TIMESTAMP"], + "locked": ["bool"], + "data": ["text"] + } + } +} \ No newline at end of file diff --git a/scheme/subscriptions.json b/scheme/subscriptions.json new file mode 100644 index 0000000..0230959 --- /dev/null +++ b/scheme/subscriptions.json @@ -0,0 +1,17 @@ +{ + "schema_name": "subscriptions", + "db": { + "table_needed": true, + "table_name": "subscriptions", + "columns": { + "id": ["integer PRIMARY KEY"], + "scheme": ["text"], + "subscription_name": ["text"], + "subscription_path": ["text"], + "subscriptions_last_checked": ["DATETIME DEFAULT CURRENT_TIMESTAMP"], + "subscriptions_last_created": ["DATETIME DEFAULT CURRENT_TIMESTAMP"], + "subscription_has_new_data": ["bool"], + "subscription_data": ["text"] + } + } +} \ No newline at end of file diff --git a/scheme/youtube.json b/scheme/youtube.json new file mode 100644 index 0000000..e69de29