Support remote files + binary files

This commit is contained in:
hyugogirubato
2023-02-08 19:51:08 +01:00
parent 40cb3759f2
commit f5debc6f56
10 changed files with 119 additions and 1 deletions
View File
+12
View File
@@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="str.unescape" />
</list>
</option>
</inspection_tool>
</profile>
</component>
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pycbzhelper.iml" filepath="$PROJECT_DIR$/.idea/pycbzhelper.iml" />
</modules>
</component>
</project>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+55
View File
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="1e3b2b5c-bbd5-4f54-89d8-f73775e9feba" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.travis.yml" beforeDir="false" afterPath="$PROJECT_DIR$/.travis.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LICENSE" beforeDir="false" afterPath="$PROJECT_DIR$/LICENSE" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pycbzhelper/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/pycbzhelper/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pycbzhelper/comicinfo.py" beforeDir="false" afterPath="$PROJECT_DIR$/pycbzhelper/comicinfo.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pycbzhelper/exceptions.py" beforeDir="false" afterPath="$PROJECT_DIR$/pycbzhelper/exceptions.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pycbzhelper/helper.py" beforeDir="false" afterPath="$PROJECT_DIR$/pycbzhelper/helper.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pycbzhelper/utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/pycbzhelper/utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/setup.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests.py" beforeDir="false" afterPath="$PROJECT_DIR$/tests.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="2LRm1wsZXqsVSpU3IHCZQJU0e6s" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="1e3b2b5c-bbd5-4f54-89d8-f73775e9feba" name="Default Changelist" comment="" />
<created>1675842063151</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1675842063151</updated>
<workItem from="1675842067503" duration="60000" />
<workItem from="1675871067263" duration="307000" />
<workItem from="1675879384779" duration="29000" />
<workItem from="1675881442099" duration="621000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>
+4
View File
@@ -12,3 +12,7 @@ class MissingPageFile(PyCBZHelperException):
class InvalidFilePermission(PyCBZHelperException):
"""Unable to delete existing file."""
class FileNotFound(PyCBZHelperException):
"""The specified source file was not found."""
+12 -1
View File
@@ -3,12 +3,13 @@ import pathlib
import shutil
import zipfile
import requests
from json2xml import json2xml
from langcodes import Language
from PIL import Image
from pycbzhelper.comicinfo import KEYS_STRING, KEYS_INT, KEYS_SPECIAL, KEYS_AGE, KEYS_FORMAT, KEYS_PAGE_TYPE
from pycbzhelper.exceptions import InvalidKeyValue, MissingPageFile, InvalidFilePermission
from pycbzhelper.exceptions import InvalidKeyValue, MissingPageFile, InvalidFilePermission, FileNotFound
from pycbzhelper.utils import get_key_value, delete_none, slugify
@@ -60,6 +61,16 @@ class Helper:
kwargs['PageCount'] = len(kwargs.get('Pages'))
for i in range(kwargs.get('PageCount')):
page = kwargs.get('Pages')[i]
if isinstance(page['File'], bytes) or (isinstance(page['File'], str) and page['File'].startswith('https://')):
file = os.path.join("tmp", f"page-{i:03d}.jpg")
with open(file, mode="wb") as f:
f.write(page['File'] if isinstance(page['File'], bytes) else requests.get(url=page['File']).content)
f.close()
page['File'] = file
if not os.path.exists(page['File']):
raise FileNotFound(f"ERROR: Source file is invalid: {page['File']}")
properties = Image.open(page['File'])
self._files.append(page['File'])
if not page.get('Type'):