Beispiel #1
0
class Book(Book_):
    def __init__(self,
                 prefix,
                 lpath,
                 title=None,
                 authors=None,
                 mime=None,
                 date=None,
                 ContentType=None,
                 thumbnail_name=None,
                 size=None,
                 other=None):
        from calibre.utils.date import parse_date
        #         debug_print('Book::__init__ - title=', title)
        show_debug = title is not None and title.lower().find("xxxxx") >= 0
        if other is not None:
            other.title = title
            other.published_date = date
        if show_debug:
            debug_print("Book::__init__ - title=", title, 'authors=', authors)
            debug_print("Book::__init__ - other=", other)
        super(Book, self).__init__(prefix, lpath, size, other)

        if title is not None and len(title) > 0:
            self.title = title

        if authors is not None and len(authors) > 0:
            self.authors_from_string(authors)
            if self.author_sort is None or self.author_sort == "Unknown":
                self.author_sort = author_to_author_sort(authors)

        self.mime = mime

        self.size = size  # will be set later if None

        if ContentType == '6' and date is not None:
            try:
                self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
            except:
                try:
                    self.datetime = time.strptime(
                        date.split('+')[0], "%Y-%m-%dT%H:%M:%S")
                except:
                    try:
                        self.datetime = time.strptime(
                            date.split('+')[0], "%Y-%m-%d")
                    except:
                        try:
                            self.datetime = parse_date(
                                date, assume_utc=True).timetuple()
                        except:
                            try:
                                self.datetime = time.gmtime(
                                    os.path.getctime(self.path))
                            except:
                                self.datetime = time.gmtime()

        self.kobo_metadata = Metadata(title, self.authors)
        self.contentID = None
        self.current_shelves = []
        self.kobo_collections = []
        self.can_put_on_shelves = True
        self.kobo_series = None
        self.kobo_series_number = None  # Kobo stores the series number as string. And it can have a leading "#".
        self.kobo_subtitle = None

        if thumbnail_name is not None:
            self.thumbnail = ImageWrapper(thumbnail_name)

        if show_debug:
            debug_print("Book::__init__ end - self=", self)
            debug_print("Book::__init__ end - title=", title, 'authors=',
                        authors)

    @property
    def is_sideloaded(self):
        # If we don't have a content Id, we don't know what type it is.
        return self.contentID and self.contentID.startswith("file")

    @property
    def is_purchased_kepub(self):
        return self.contentID and not self.contentID.startswith("file")

    def __unicode__(self):
        '''
        A string representation of this object, suitable for printing to
        console
        '''
        ans = [u"Kobo metadata:"]

        def fmt(x, y):
            ans.append(u'%-20s: %s' % (unicode_type(x), unicode_type(y)))

        if self.contentID:
            fmt('Content ID', self.contentID)
        if self.kobo_series:
            fmt('Kobo Series',
                self.kobo_series + ' #%s' % self.kobo_series_number)
        if self.kobo_subtitle:
            fmt('Subtitle', self.kobo_subtitle)
        if self.mime:
            fmt('MimeType', self.mime)

        ans = u'\n'.join(ans) + u"\n" + self.kobo_metadata.__unicode__()

        return super(Book, self).__unicode__() + u"\n" + ans
Beispiel #2
0
class Book(Book_):

    def __init__(self, prefix, lpath, title=None, authors=None, mime=None, date=None, ContentType=None,
                 thumbnail_name=None, size=None, other=None):
        from calibre.utils.date import parse_date
#         debug_print('Book::__init__ - title=', title)
        show_debug = title is not None and title.lower().find("xxxxx") >= 0
        if other is not None:
            other.title = title
            other.published_date = date
        if show_debug:
            debug_print("Book::__init__ - title=", title, 'authors=', authors)
            debug_print("Book::__init__ - other=", other)
        super(Book, self).__init__(prefix, lpath, size, other)

        if title is not None and len(title) > 0:
            self.title = title

        if authors is not None and len(authors) > 0:
            self.authors_from_string(authors)
            if self.author_sort is None or self.author_sort == "Unknown":
                self.author_sort = author_to_author_sort(authors)

        self.mime = mime

        self.size = size  # will be set later if None

        if ContentType == '6' and date is not None:
            try:
                self.datetime = time.strptime(date, "%Y-%m-%dT%H:%M:%S.%f")
            except:
                try:
                    self.datetime = time.strptime(date.split('+')[0], "%Y-%m-%dT%H:%M:%S")
                except:
                    try:
                        self.datetime = time.strptime(date.split('+')[0], "%Y-%m-%d")
                    except:
                        try:
                            self.datetime = parse_date(date,
                                    assume_utc=True).timetuple()
                        except:
                            try:
                                self.datetime = time.gmtime(os.path.getctime(self.path))
                            except:
                                self.datetime = time.gmtime()

        self.kobo_metadata = Metadata(title, self.authors)
        self.contentID          = None
        self.current_shelves    = []
        self.kobo_collections   = []
        self.can_put_on_shelves = True
        self.kobo_series        = None
        self.kobo_series_number = None  # Kobo stores the series number as string. And it can have a leading "#".
        self.kobo_subtitle      = None

        if thumbnail_name is not None:
            self.thumbnail = ImageWrapper(thumbnail_name)

        if show_debug:
            debug_print("Book::__init__ end - self=", self)
            debug_print("Book::__init__ end - title=", title, 'authors=', authors)

    @property
    def is_sideloaded(self):
        # If we don't have a content Id, we don't know what type it is.
        return self.contentID and self.contentID.startswith("file")

    @property
    def is_purchased_kepub(self):
        return self.contentID and not self.contentID.startswith("file")

    def __unicode__(self):
        '''
        A string representation of this object, suitable for printing to
        console
        '''
        ans = [u"Kobo metadata:"]

        def fmt(x, y):
            ans.append(u'%-20s: %s'%(unicode(x), unicode(y)))

        if self.contentID:
            fmt('Content ID', self.contentID)
        if self.kobo_series:
            fmt('Kobo Series', self.kobo_series + ' #%s'%self.kobo_series_number)
        if self.kobo_subtitle:
            fmt('Subtitle', self.kobo_subtitle)
        if self.mime:
            fmt('MimeType', self.mime)

        ans = u'\n'.join(ans) + u"\n" + self.kobo_metadata.__unicode__()

        return super(Book,self).__unicode__() + u"\n" + ans