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

Add support for info.json metadata file #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type %meta_js_path%>%output_path%
type %parts_js_dir%first.js>>%output_path%
type %parts_js_dir%JSZip.js>>%output_path%
type %parts_js_dir%FileSaver.js>>%output_path%
type %parts_js_dir%xScripts.js>>%output_path%
type %parts_js_dir%main.js>>%output_path%
1 change: 1 addition & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cat $meta_js_path>$output_path
cat $parts_js_dir"first.js">>$output_path
cat $parts_js_dir"JSZip.js">>$output_path
cat $parts_js_dir"FileSaver.js">>$output_path
cat $parts_js_dir"xScripts.js">>$output_path
cat $parts_js_dir"main.js">>$output_path
19 changes: 19 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,21 @@ function generateZip(isFromFS, fs, isRetry, forced){
if (setting['save-info'] === 'file' || !setting['save-info']) {
(dirName && !ehDownloadRegex.slashOnly.test(dirName) ? zip.folder(dirName) : zip).file('info.txt', infoStr.replace(/\n/gi, '\r\n'));
}

if (setting['save-x-info']) {
try {
var data = xScripts.getFromHtml(document.documentElement, window.location.href);
if (data !== null) {
var xInfo = xScripts.toCommonJson(data);
xInfo.source_script = 'e-hentai-downloader';
var xInfoStr = JSON.stringify(xInfo, null, ' ');
zip.file('info.json', xInfoStr.replace(/\r?\n/gi, '\r\n'));
}
}
catch (error) {
console.log(error);
}
}
}

pushDialog('\n\nGenerating Zip file...\n');
Expand Down Expand Up @@ -2122,6 +2137,7 @@ function showSettings() {
<div class="g2"><label><input type="checkbox" data-ehd-setting="replace-with-full-width"> Replace forbidden characters with full-width characters instead of dash (-)</label></div>\
<div class="g2"><label><input type="checkbox" data-ehd-setting="force-pause"> Force drop downloaded images data when pausing download</label></div>\
<div class="g2"><label><input type="checkbox" data-ehd-setting="save-as-cbz"> Save as CBZ (Comic book archive) file<sup>(5)</sup></label></div>\
<div class="g2"><label><input type="checkbox" data-ehd-setting="save-x-info"> Save gallery metadata JSON file </label><sup>(6)</sup></div>\
<div class="ehD-setting-note">\
<div class="g2">\
(1) This may reduce memory usage but some decompress softwares may not support the Zip file. See <a href="https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html" target="_blank" style="color: #ffffff;">JSZip Docs</a> for more info.\
Expand All @@ -2138,6 +2154,9 @@ function showSettings() {
<div class="g2">\
(5) <a href="https://en.wikipedia.org/wiki/Comic_book_archive">Comic book archive</a> is a file type to archive comic images, you can open it with some comic viewer like CDisplay/CDisplayEX, or just extract it as a Zip file. To keep the order of images, you can also enable numbering images.\
</div>\
<div class="g2">\
(6) Some external archive managers read tags and other gallery metadata from an info.json file.\
</div>\
</div>\
</div>\
</div>\
Expand Down
46 changes: 46 additions & 0 deletions src/xScripts-update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@echo off

:: Paths
set SCRIPT_DIR=%~dp0
set X_DIR=.x
set X_DIR_FULL=%SCRIPT_DIR%%X_DIR%


:: Clone repository
if not exist "%X_DIR_FULL%" git clone https://github.com/dnsev-h/x.git "%X_DIR_FULL%" --depth 1


:: Setup node dependencies
pushd "%X_DIR_FULL%"

call npm install "[email protected]" babelify @babel/core @babel/preset-env --no-save

set NODE_BIN_DIR=%X_DIR_FULL%\node_modules\.bin
for /F "usebackq delims=" %%a in (`call npm bin`) do SET NODE_BIN_DIR=%%a


:: Setup file names
set MAIN_FILE_TEMP=%SCRIPT_DIR%main-temp.js
set XSCRIPTS_FILE=%SCRIPT_DIR%xScripts.js

:: Clean files before running
del "%MAIN_FILE_TEMP%" > NUL 2> NUL
del "%XSCRIPTS_FILE%" > NUL 2> NUL

:: Create main entry point
echo module.exports.getFromHtml=require('./%X_DIR%/src/api/gallery-info/get-from-html');>"%MAIN_FILE_TEMP%"
echo module.exports.toCommonJson=require('./%X_DIR%/src/api/gallery-info/common-json').toCommonJson;>>"%MAIN_FILE_TEMP%"

:: Add license
echo /*>"%XSCRIPTS_FILE%"
type "%X_DIR_FULL%\LICENSE">>"%XSCRIPTS_FILE%"
echo.>>"%XSCRIPTS_FILE%"
echo */>>"%XSCRIPTS_FILE%"

:: Browserify
call "%NODE_BIN_DIR%\browserify" "%MAIN_FILE_TEMP%" --standalone xScripts -t [ babelify --presets [ @babel/preset-env ] ] >> "%XSCRIPTS_FILE%"

:: Clean temp file
del "%MAIN_FILE_TEMP%" > NUL 2> NUL

popd
Loading