Skip to content

Commit

Permalink
Created project
Browse files Browse the repository at this point in the history
Hello World :)

Created base repositoy and added some basics
  • Loading branch information
j54j6 committed Apr 12, 2024
1 parent fe6ac74 commit a7be54b
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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 :)
Empty file added config.json
Empty file.
76 changes: 76 additions & 0 deletions config_handler.py
Original file line number Diff line number Diff line change
@@ -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


Empty file added database_manager.py
Empty file.
37 changes: 37 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()



19 changes: 19 additions & 0 deletions project_functions.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added scheme/disney.json
Empty file.
Empty file added scheme/peertube.json
Empty file.
Empty file added scheme/pinterest.json
Empty file.
16 changes: 16 additions & 0 deletions scheme/project.json
Original file line number Diff line number Diff line change
@@ -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": "./"}
]
}
}
17 changes: 17 additions & 0 deletions scheme/saved_items.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
17 changes: 17 additions & 0 deletions scheme/subscriptions.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
Empty file added scheme/youtube.json
Empty file.

0 comments on commit a7be54b

Please sign in to comment.