Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Option to select exceptions for the 'cropping mode' feature #526

Open
distample opened this issue May 27, 2023 · 1 comment

Comments

@distample
Copy link

distample commented May 27, 2023

Sometimes there is a need for some pages in the book not to crop the margins, but now the checkbox affects all pages without exceptions.

Could you please add functionality where pages are added to exceptions before processing and they are not cropped?

@distample
Copy link
Author

distample commented May 28, 2023

Maybe something like a structure scanner that outputs it to the program window, and there we mark which pages DO NOT need to be cropped?

import os
import re
import zipfile
from bs4 import BeautifulSoup


def extract_cbz_structure(cbz_path, extract_dir):
    with zipfile.ZipFile(cbz_path, 'r') as cbz_file:
        cbz_file.extractall(extract_dir)

def natural_sort_key(s):
    return [int(x) if x.isdigit() else x for x in re.split(r'(\d+)', s)]

def generate_html_with_checkboxes(extract_dir):
    html = """
    <html>
    <head>
    <script>
    function toggleFolderCheckbox(folderCheckbox) {
        var checkboxes = document.querySelectorAll('input[type="checkbox"]');
        for (var i = 0; i < checkboxes.length; i++) {
            var checkbox = checkboxes[i];
            if (checkbox.name.startsWith(folderCheckbox.value) && checkbox.name !== folderCheckbox.value) {
                checkbox.checked = folderCheckbox.checked;
            }
        }
    }
    </script>
    </head>
    <body>
    """

    # Iterate over the directory structure
    for root, dirs, files in os.walk(extract_dir):
        relative_path = os.path.relpath(root, extract_dir)
        indent_level = relative_path.count(os.sep)
        indent = "&nbsp;&nbsp;&nbsp;&nbsp;" * indent_level
        folder_checkbox_id = f"folder-checkbox-{root.replace('/', '-')}"
        html += f'{indent}<input type="checkbox" id="{folder_checkbox_id}" name="{root}" value="{root}" onchange="toggleFolderCheckbox(this)">{relative_path}<br>'
        sorted_files = sorted(files, key=natural_sort_key)
        # Iterate over the sorted files
        for file in sorted_files:
            if file == 'ComicInfo.xml':
                continue  # Skip the ComicInfo.xml file
            file_path = os.path.join(root, file)
            indent_level_file = relative_path.count(os.sep) + 1
            indent_file = "&nbsp;&nbsp;&nbsp;&nbsp;" * indent_level_file
            html += f'{indent_file}<input type="checkbox" name="{file_path}" value="{file_path}">{file}<br>'

    html += """
    </body>
    </html>
    """
    return html

# Path to your cbz file
cbz_path = "/path/to/file.cbz"
# Folder to extract the cbz file structure
extract_dir = "/path/to/folder"

# Extract the cbz file structure
extract_cbz_structure(cbz_path, extract_dir)

# Generate HTML with checkboxes
html = generate_html_with_checkboxes(extract_dir)

# Write HTML to file
with open("/path/to/output.html", "w") as f:
    f.write(html)

@distample distample changed the title Some pages without processing/cropping Option to select "cropping mode" option exceptions May 31, 2023
@distample distample changed the title Option to select "cropping mode" option exceptions Option to select exceptions for the 'cropping mode' feature May 31, 2023
@distample distample changed the title Option to select exceptions for the 'cropping mode' feature [Feature request] Option to select exceptions for the 'cropping mode' feature Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant