|
|
@ -35,7 +35,7 @@ SOFTWARE. |
|
|
|
|
|
|
|
|
|
|
|
""" --- HUEY IMPORT --- """ |
|
|
|
""" --- HUEY IMPORT --- """ |
|
|
|
""" --- PYTHON IMPORTS --- """ |
|
|
|
""" --- PYTHON IMPORTS --- """ |
|
|
|
import datetime, time, pathlib, os, shutil, requests, json |
|
|
|
import datetime, time, pathlib, os, shutil, requests, json, sys, subprocess |
|
|
|
from slugify import slugify |
|
|
|
from slugify import slugify |
|
|
|
|
|
|
|
|
|
|
|
""" --- STASHR DEPENDENCY IMPORTS --- """ |
|
|
|
""" --- STASHR DEPENDENCY IMPORTS --- """ |
|
|
@ -49,6 +49,7 @@ from stashr.config import stashrconfig |
|
|
|
from flask import flash |
|
|
|
from flask import flash |
|
|
|
from flask_login import current_user |
|
|
|
from flask_login import current_user |
|
|
|
from flask_bcrypt import generate_password_hash |
|
|
|
from flask_bcrypt import generate_password_hash |
|
|
|
|
|
|
|
from flask_pluginkit import PluginInstaller |
|
|
|
|
|
|
|
|
|
|
|
from sqlalchemy.orm import contains_eager |
|
|
|
from sqlalchemy.orm import contains_eager |
|
|
|
|
|
|
|
|
|
|
@ -925,91 +926,6 @@ def update_volumes_from_release_list(): |
|
|
|
refresh_single_volume(update.NewReleases.new_release_volume_id) |
|
|
|
refresh_single_volume(update.NewReleases.new_release_volume_id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" --------------------- SCRAPE FOLDERS (RE)WRITE --------------------- """ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_scrape_entries(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
missing_links = database.session \ |
|
|
|
|
|
|
|
.query(database.Directories) \ |
|
|
|
|
|
|
|
.filter(database.Directories.directory_in_library == False) \ |
|
|
|
|
|
|
|
.all() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# for item in missing_links: |
|
|
|
|
|
|
|
# create_empty_scrape_entry(item) |
|
|
|
|
|
|
|
# get_scrape_candidates(item) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for item in missing_links: |
|
|
|
|
|
|
|
candidates = cv.search(item.directory_path, limit=10, resources=['volume']) |
|
|
|
|
|
|
|
match_found = False |
|
|
|
|
|
|
|
scrape_candidate = candidates.results[0]['id'] |
|
|
|
|
|
|
|
for candidate in candidates.results: |
|
|
|
|
|
|
|
if str(candidate['id']) in item.directory_path: |
|
|
|
|
|
|
|
scrape_candidate = candidate['id'] |
|
|
|
|
|
|
|
match_found = True |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
if not match_found: |
|
|
|
|
|
|
|
if str(candidate['start_year']) in item.directory_path: |
|
|
|
|
|
|
|
scrape_candidate = candidate['id'] |
|
|
|
|
|
|
|
match_found = True |
|
|
|
|
|
|
|
new_scrape_item = database.ScrapeItems( |
|
|
|
|
|
|
|
scrape_directory = item.directory_path, |
|
|
|
|
|
|
|
scrape_directory_id = item.directory_id, |
|
|
|
|
|
|
|
scrape_json = json.dumps(candidates.results), |
|
|
|
|
|
|
|
scrape_candidate = scrape_candidate, |
|
|
|
|
|
|
|
scrape_match = match_found |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
database.session.merge(new_scrape_item) |
|
|
|
|
|
|
|
database.session.commit() |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
database.session.rollback() |
|
|
|
|
|
|
|
logger.warning('Scrape Item in database') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_scrape_candidates(directory): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scrape_item = database.session \ |
|
|
|
|
|
|
|
.query(database.ScrapeItems) \ |
|
|
|
|
|
|
|
.filter(database.ScrapeItems.scrape_directory == directory) \ |
|
|
|
|
|
|
|
.first() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
candidates = cv.search(directory, limit=10, resources=['volume']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setattr(scrape_item, 'scrape_json', candidates) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
database.session.merge(scrape_item) |
|
|
|
|
|
|
|
database.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_scrape_match(match_item): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match_item.directory.directory_volume_id = match_item.scrape_candidate |
|
|
|
|
|
|
|
match_item.directory.directory_in_library = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
database.session.merge(match_item) |
|
|
|
|
|
|
|
database.session.delete(match_item) |
|
|
|
|
|
|
|
database.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add_volume_to_library(match_item.scrape_candidate) |
|
|
|
|
|
|
|
scrape_volume_issues(match_item.scrape_candidate) |
|
|
|
|
|
|
|
scan_volume_files(match_item.scrape_candidate) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_empty_scrape_entry(item): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_scrape_item = database.ScrapeItems( |
|
|
|
|
|
|
|
scrape_directory = item.directory_path, |
|
|
|
|
|
|
|
scrape_directory_id = item.directory_id |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
database.session.merge(new_scrape_item) |
|
|
|
|
|
|
|
database.session.commit() |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
database.session.rollback() |
|
|
|
|
|
|
|
logger.warning('Scrape Item in database') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" --------------------- SCRAPE FOLDERS (RE)(RE)WRITE --------------------- """ |
|
|
|
""" --------------------- SCRAPE FOLDERS (RE)(RE)WRITE --------------------- """ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1140,3 +1056,41 @@ def new_add_scrape_match(item): |
|
|
|
add_volume_to_library(item.scrape_candidate) |
|
|
|
add_volume_to_library(item.scrape_candidate) |
|
|
|
scrape_volume_issues(item.scrape_candidate) |
|
|
|
scrape_volume_issues(item.scrape_candidate) |
|
|
|
scan_volume_files(item.scrape_candidate) |
|
|
|
scan_volume_files(item.scrape_candidate) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" --------------------- (UN)INSTALL PLUGINS --------------------- """ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install_plugin(filepath): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin_file = os.path.join( |
|
|
|
|
|
|
|
folders.StashrFolders().temp_folder(), |
|
|
|
|
|
|
|
filepath |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.isfile(plugin_file): |
|
|
|
|
|
|
|
logger.warning(f'Plugin {filepath} not found') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f'Installing Plugin: {filepath}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
install = PluginInstaller(plugin_abspath=folders.StashrFolders().plugins_folder()).addPlugin(method='local', filepath=plugin_file, remove=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if install['code'] == 0: |
|
|
|
|
|
|
|
logger.info(f'Plugin {filepath} installed') |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
logger.warning(f'Error occurred installing {filepath}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def uninstall_plugin(package_name): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uninstall = PluginInstaller(plugin_abspath=stashrconfig['DIRECTORY']['plugins']).removePlugin('notify_pushbullet_2') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if uninstall['code'] == 0: |
|
|
|
|
|
|
|
logger.info(f'Plugin {package_name} uninstalled') |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
logger.warning(f'Error uninstalling {package_name}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install_package(package): |
|
|
|
|
|
|
|
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package]) |