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

Extract covers from .cbz and .cbr #2

Closed
rishighan opened this issue Jul 23, 2021 · 11 comments
Closed

Extract covers from .cbz and .cbr #2

rishighan opened this issue Jul 23, 2021 · 11 comments

Comments

@rishighan
Copy link

Hello,

Do you have a module that you use to unrar or unzip .cbr and .cbz files to extract the covers from the archives?
I think I saw a demo of your application, where you are displaying thumbnails and was wondering where in the code that resides?

@bluelovers
Copy link
Owner

@rishighan
Copy link
Author

This seems to be for the browser, what I'm trying to do is: extract the first file from the cbr or the cbz. The problem I'm running into is that the sort order of the archive is incorrect and I get a random page as the cover.

Is there a way to ensure that the files in the archive maintain the sort order after extraction?

Do you have any pointers on how I solve it? This is my code so far:

https://github.com/rishighan/threetwo-import-service/blob/a3d07d62c8be0c36fef9884821c852de81c804f5/utils/uncompression.utils.ts#L85

@bluelovers
Copy link
Owner

i can't found any info for how to get cover from cbr meta

but u can use ebook-meta

ebook-meta is form Calibre

return crossSpawn('ebook-meta', [
		`--get-cover=${outputFile}`,
		target,
	], options.spawnOptions)

@rishighan
Copy link
Author

What uncompression libraries do you use in your projects for rar and zip files?

@bluelovers
Copy link
Owner

i only use jszip for zip

i didn't use rar in js

and ebook-meta can handle all comic book cover

@rishighan
Copy link
Author

Is it an npm module?

@bluelovers
Copy link
Owner

bluelovers commented Jul 26, 2021

when u install https://calibre-ebook.com/

u will have ebook-meta, this exists in calibre install path

@rishighan
Copy link
Author

Is it available as part of ws-calibre ?

@rishighan
Copy link
Author

Alright, found https://github.com/bluelovers/node-calibre and I am wondering if I need to create a calibre library out of my comics? I am on macOS, so I can install calibre using brew, that part is solved.

So the correct flow for me is:

  1. Get the calibre package and install it on my host OS
  2. Install https://github.com/bluelovers/node-calibre
  3. Create a library?
  4. Iterate over library and get covers?

@rishighan
Copy link
Author

Think I got a little further, using the following:

export const getCoversFromFile = async () => {
	try {
		const calibre = new Calibre({
			library: path.resolve("userdata/calibre-lib"),
		});

		let result: string;
		result = await calibre.run("ebook-meta", [
			`--get-cover=${path.resolve(
				"comics/A Hypothetical Lizard (2004)/Hypothetical_Lizard_T01.cbr"
			)}`,
			path.resolve("userdata/covers/shoo/"),
		]);
		console.log("AJSDASDLASDASDASLK!@#!@#!@#!#@#!@#!@", result);
	} catch (error) {
		console.log(error);
	}
};

I get:

{ Error: Command failed: ebook-meta "--get-cover=/Users/rishi/work/threetwo-import-service/comics/A Hypothetical Lizard (2004)/Hypothetical_Lizard_T01.cbr" "/Users/rishi/work/threetwo-import-service/userdata/covers/shoo/jp.jpg"
Traceback (most recent call last):
  File "runpy.py", line 194, in _run_module_as_main
  File "runpy.py", line 87, in _run_code
  File "site.py", line 39, in <module>
  File "site.py", line 35, in main
  File "calibre/ebooks/metadata/cli.py", line 182, in main
FileNotFoundError: [Errno 2] No such file or directory: '/Users/rishi/work/threetwo-import-service/userdata/covers/shoo/jp.jpg'

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at ChildProcess.EventEmitter.emit (domain.js:448:20)
    at maybeClose (internal/child_process.js:982:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20)
    at Pipe._handle.close (net.js:606:12)
  killed: false,
  code: 1,
  signal: null,
  cmd:
   'ebook-meta "--get-cover=/Users/rishi/work/threetwo-import-service/comics/A Hypothetical Lizard (2004)/Hypothetical_Lizard_T01.cbr" "/Users/rishi/work/threetwo-import-service/userdata/covers/shoo/jp.jpg"' }

@rishighan
Copy link
Author

rishighan commented Jul 27, 2021

Finally got it!

This is how:

let result: string;
result = await calibre.run(
  "ebook-meta",
  [path.resolve("comics/Aliens - Salvation (1993) Mignola.cbz")],
  {
    getCover: path.resolve("userdata/covers/shoo/p.jpg"),
  }
);

Per usual, thanks so much for your help!

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

2 participants