Skip to content

Commit

Permalink
bug fixes and process updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pewsplosions committed Nov 3, 2019
1 parent c19b572 commit 82a38d8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Comicalibre(InterfaceActionBase):
description = "Gather Comic Vine metadata for comic books."
supported_platforms = ["windows", "osx", "linux"]
author = "Michael Merrill"
version = (2019, 10, 3) # Year, Month, Build within month
version = (2019, 11, 0) # Year, Month, Build within month
minimum_calibre_version = (0, 7, 53)
actual_plugin = "calibre_plugins.comicalibre.ui.main:ComicalibreInterface"

Expand Down
7 changes: 5 additions & 2 deletions src/ui/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from calibre_plugins.comicalibre.work.main import ComicalibreWork
from PyQt5.Qt import (QCheckBox, QDialog, QFrame, QGroupBox, QHBoxLayout,
QLabel, QLineEdit, QProgressBar, QPushButton,
QVBoxLayout)
QScrollArea, QVBoxLayout)

__license__ = "GPL v3"
__copyright__ = "2019, Michael Merrill <[email protected]>"
Expand Down Expand Up @@ -137,8 +137,11 @@ def create_gui(self):
self.result_box = QGroupBox()
self.result_box.setTitle("Results")
self.result_text = QLabel("Run Comicalibre to see results.")
self.result_scroll = QScrollArea()
self.result_scroll.setWidget(self.result_text)
self.result_scroll.setWidgetResizable(True)
self.result_layout = QVBoxLayout()
self.result_layout.addWidget(self.result_text)
self.result_layout.addWidget(self.result_scroll)
self.result_box.setLayout(self.result_layout)
self.layout.addWidget(self.result_box)

Expand Down
3 changes: 1 addition & 2 deletions src/work/calibre.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def get_selected_books(self):
""" Get selected books as a map of book id to row. """
rows = self.gui.library_view.selectionModel().selectedRows()
if not rows or len(rows) == 0:
return error_dialog(self.gui, _L['Cannot update metadata'],
_L['No books selected'], show=True)
return -1
return map(self.gui.library_view.model().id, rows)

def get_current_metadata(self, book):
Expand Down
15 changes: 11 additions & 4 deletions src/work/comicvine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ComicalibreVineWork():
""" Control the interaction with Comic Vine API. """

BASE_URL = "https://comicvine.gamespot.com/api/"
warnings = []

def __init__(self):
""" Initialize data attributes for process. """
Expand All @@ -30,12 +31,14 @@ def build_url(self, resource, params):

def get_metadata(self, md, volume_id, issue, issue_is_id):
""" Main process to get metadata from Comic Vine and add to Calibre. """
self.warnings = []
issue_id = issue
if (not issue_is_id):
issue_id = self.get_issue_id(volume_id, issue)
self.add_issue_data(md, issue_id)
self.add_volume_data(md, volume_id)
md.set("#comicvineissueid", issue_id)
return self.warnings

def add_volume_data(self, md, volume_id):
""" Find and add found volume data to the metadata object. """
Expand Down Expand Up @@ -98,15 +101,19 @@ def add_issue_data(self, md, issue_id):
md.set("authors", authors)
if (data["results"]["cover_date"] is not None):
md.set("pubdate", parse(data["results"]["cover_date"]))
md.set("comments", data["results"]["description"] + cvhtml)
md.set("series_index", float(data["results"]["issue_number"]))
if (data["results"]["description"] is not None):
md.set("comments", data["results"]["description"] + cvhtml)
else: md.set("comments", cvhtml)
try:
md.set("series_index", float(data["results"]["issue_number"]))
except:
num = data["results"]["issue_number"]
self.warnings.append(md.title + " " + num + ": check series index.")

def get_issue_id(self, volume_id, issue):
""" Get issue ID from Comic Vine. """
if (isinstance(issue, basestring) and issue != "0"):
issue = issue.lstrip("0")
elif (isinstance(issue, float)):
issue = int(issue)
params = {
"format": "json",
"limit": "1",
Expand Down
18 changes: 16 additions & 2 deletions src/work/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import sys
import traceback
from threading import Thread

from calibre_plugins.comicalibre.ui.config import prefs
Expand All @@ -13,7 +15,7 @@
__copyright__ = "2019, Michael Merrill <[email protected]>"
__docformat__ = "restructuredtext en"

class ComicalibreWork(Thread): # TODO Should this be a Thread?
class ComicalibreWork(Thread):
""" Control the order of processing for the work being done. """
errors = []

Expand All @@ -30,6 +32,10 @@ def process(self, progress_bar, process_type, keep_tags):

# Get selected books.
books = self.calibre_worker.get_selected_books()
if (books == -1):
self.errors.append("No selected books.")
return self.errors

self.prog_worker.calculate_steps(books)

# Loop through to get all current metadata.
Expand All @@ -47,10 +53,15 @@ def process(self, progress_bar, process_type, keep_tags):

# Fill metadata from Comic Vine.
try:
self.vine_worker.get_metadata(md, volume_id, issue, process_type == 2)
issue_is_id = process_type == 2
warn = self.vine_worker.get_metadata(md, volume_id, issue, issue_is_id)
self.errors.extend(warn)
except:
self.errors.append(md.title + id_for_errors +
": Unable to get info from Comic Vine with given IDs.")
traceback.print_exc(file=sys.stdout)
self.prog_worker.iterate()
continue

self.set_given_metadata(md, keep_tags)

Expand All @@ -59,6 +70,9 @@ def process(self, progress_bar, process_type, keep_tags):
except:
self.errors.append(md.title + id_for_errors +
": Received data from Comic Vine that was unable to be saved.")
traceback.print_exc(file=sys.stdout)
self.prog_worker.iterate()
continue

self.prog_worker.iterate()

Expand Down

0 comments on commit 82a38d8

Please sign in to comment.