Skip to content

Commit

Permalink
AlphaWorking
Browse files Browse the repository at this point in the history
First working version

-> >Can download videos based on a scheme file and categorize it.
-> DB add #TODO

- Added first schemes for youtube, pinterest, pornhub and reddit -> In the future all sites supported by youtube dl should be supporterd (List: https://github.com/ytdl-org/youtube-dl/blob/master/docs/supportedsites.md)
  • Loading branch information
j54j6 committed May 11, 2024
1 parent 034608c commit 9171aa6
Show file tree
Hide file tree
Showing 18 changed files with 731 additions and 20 deletions.
4 changes: 1 addition & 3 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[main]

[db]
db_driver = sqlite
db_path = ./test.db
db_path = .\test.db
db_name = database.db
db_host = localhost
db_user = username
Expand Down
1 change: 0 additions & 1 deletion config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def create_default_config(path=Path.joinpath(pathlib.Path(__file__).parent.resol
except Exception as e:
logger.error(f"Error while creating default config! - Error: {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.
Expand Down
72 changes: 67 additions & 5 deletions database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def create_table(name:str, scheme:json):
logging.warning(f"There are at least 2 primary keys defined! - Please check config. Ignore Primary Key {column_name}")

if "auto_increment" in options and options["auto_increment"] == True:
c_query += " AUTO_INCREMENT"
c_query += " AUTOINCREMENT"

if "unique" in options and options["unique"] == True:
c_query += " UNIQUE"
Expand All @@ -157,8 +157,70 @@ def create_table(name:str, scheme:json):
logging.error(f"Error while executing creation Statement! - Error: {e}")
return False

#Fetch a value from a database based on a json filter {""}
def fetch_value(table:str, row_name:str, value:str, filter:list = None, is_unique=False):
if not db_init:
check_db()
#Check if the table already exist. If so - SKIP
if not check_table_exist(table):
logger.warning(f"Table {table} does not exist!")
return False

#create SELECT query
if filter != None:
query_filter = ""
for element in filter:
query_filter += element + ","
query_filter = query_filter[:-1]
else:
query_filter = "*"
query = F"SELECT {query_filter} from {table} WHERE {row_name} = \"{value}\""
logging.debug(f"Prepared Query: {query}")
try:
with engine.connect() as conn:
logging.debug(f"Prepared query: {query}")
data = conn.execute(text(query))
if not is_unique:
return data.all()
else:
return data.first()
except Exception as e:
logging.error(f"Error while executing Insert Statement! - Error: {e}")
return False

def insert_value(table:str, data:json):
if not db_init:
check_db()
if not check_table_exist(table):
logger.error(f"Table {table} does not exist!")
return False
keys = []
for data_keys in data:
keys.append(data_keys)
values = []
for data_values in data:
values.append(data[data_values])
keys = ",".join(keys)
values = ""
for value in data:
if type(data[value]) == str or type(data[value]) == json:
values += f"\"{data[value]}\","
elif type(data[value]) == int:
values += data[value] +","
elif type(data(value)) == bool:
values += data[value] +","
else:
logging.warning(f"Unsuported type {type(data[value])} for value {value}!")
continue
values = values[:-1]
query = f"Insert into {table} ({keys}) VALUES ({values});"
logging.debug(f"Prepared Query: {query}")
try:
with engine.connect() as conn:
conn.execute(text(query))
conn.commit()
return True
except Exception as e:
logging.error(f"Error while executing Insert Statement! - Error: {e}")
return False





Loading

0 comments on commit 9171aa6

Please sign in to comment.