Exemplo n.º 1
0
def write_changes_pdf(ebook, changes):
    """Write the metadata in the given dictionary into the pdf file."""

    path = ebmeta.arguments.filename

    for key in changes.keys():
        if changes[key] == None: changes[key] = ""

    args = [
        'exiftool',
        '"{}"'.format(path)
    ]
    for a, b in (
        ('Author', 'authors'),
        ('Title',  'title'),
        ('Description', 'description')
    ):
        if b in changes: args.append('-{}="{}"'.format(a, quote(changes[b])))

    if 'tags' in changes:
        args.append('-Keywords=""')
        for tag in changes['tags']:
            args.append('-Keywords+="{}"'.format(quote(tag)))

    if len(args) > 2:
        # Run ebook-meta
        shell.pipe(' '.join(args), shell=True)
Exemplo n.º 2
0
def write_changes(ebook, changes):
    """Write the metadata in the given dictionary into the ebook file."""

    path = ebmeta.arguments.filename

    for key in changes.keys():
        if changes[key] == None: changes[key] = ""

    args = ['ebook-meta', '"{}"'.format(path)]
    for a, b in (('authors', 'authors'), ('book-producer', 'book producer'),
                 ('isbn', 'isbn'), ('language', 'language'),
                 ('date', 'publication date'), ('publisher', 'publisher'),
                 ('series', 'series'), ('title', 'title')):
        if b in changes: args.append('--{}="{}"'.format(a, quote(changes[b])))

    for a, b in (
        ('rating',
         'rating'),  # rating can't be unset once it's set, from ebook-meta CLI
        ('index', 'series index'),  # series index can't be unset either
        ('author-sort', 'author sort'),
        ('title-sort', 'title sort')):
        if b in changes:
            if changes[b]:
                args.append('--{}="{}"'.format(a, quote(changes[b])))

    if 'description' in changes:
        description = shell.pipe(['pandoc'], changes['description'])
        args.append('--comments="{}"'.format(quote(description)))

    if 'tags' in changes:
        args.append('--tags="{}"'.format(quote(','.join(changes['tags']))))

    if len(args) > 2:
        # Run ebook-meta
        shell.pipe(' '.join(args), shell=True)
Exemplo n.º 3
0
    def __get_content_opf_str(self):
        if self.__content_opf_str: return self.__content_opf_str

        with tempfile.NamedTemporaryFile() as f:
            shell.pipe(["ebook-meta", "--to-opf=" + f.name, self.path])
            self.__content_opf_str = unicode(f.read(), "utf_8", "replace")

        return self.__content_opf_str
Exemplo n.º 4
0
    def get_metadata(self):
        if self.__opf:
            return self.__opf

        with tempfile.NamedTemporaryFile() as f:
            shell.pipe(["ebook-meta", "--to-opf=" + f.name, self.path])
            opf_str = f.read().decode('utf-8')

        self.__opf = OpfReader(opf_str)
        return self.__opf
Exemplo n.º 5
0
def write_changes(ebook, changes):
    """Write the metadata in the given dictionary into the ebook file."""

    path = ebmeta.arguments.filename

    for key in changes.keys():
        if changes[key] == None: changes[key] = ""

    args = [
        u"ebook-meta",
        u'"{}"'.format(path)
    ]
    for a, b in (
        (u'authors',       'authors'),
        (u'book-producer', 'book producer'),
        (u'isbn',          'isbn'),
        (u'language',      'language'),
        (u'date',          'publication date'),
        (u'publisher',     'publisher'),
        (u'series',        'series'),
        (u'title',         'title')
    ):
        if changes.has_key(b): args.append(u"--{}=\"{}\"".format(a, quote(changes[b])))

    for a, b in (
        ('rating',        'rating'), # rating can't be unset once it's set, from ebook-meta CLI
        ('index',         'series index'), # series index can't be unset either
        ('author-sort',   'author sort'),
        ('title-sort',    'title sort')
    ):
        if changes.has_key(b):
            if changes[b]:
                args.append(u"--{}=\"{}\"".format(a, quote(changes[b])))

    if changes.has_key('description'):
        description = shell.pipe(["pandoc"], changes['description'])
        args.append(  u"--comments=\"{}\"".format(quote(description))  )

    if changes.has_key('tags'):
        args.append(  u"--tags=\"{}\"".format(quote(u','.join(changes['tags'])))  )

    if len(args) > 2:
        # Run ebook-meta
        # shell.run(" ".join(args), shell=True)
        shell.pipe(u" ".join(args), shell=True)

    if ebook.type == 'epub':
        # set uuid only for Epub files
        if(changes.has_key('uuid')):
            try:
                setUuid(changes['uuid'])
            except:
                pass
Exemplo n.º 6
0
    def get_metadata(self):
        if self.__pdfmeta:
            return self.__pdfmeta

        pdfmeta_txt = shell.pipe(['exiftool', '-json', self.path])
        self.__pdfmeta = ExifToolJsonReader(pdfmeta_txt)
        return self.__pdfmeta
Exemplo n.º 7
0
    def get_metadata(self):
        if self.__pdfmeta:
            return self.__pdfmeta

        pdfmeta_txt = shell.pipe(['exiftool', '-json', self.path])
        self.__pdfmeta = ExifToolJsonReader(pdfmeta_txt)
        return self.__pdfmeta
Exemplo n.º 8
0
def write_changes(ebook, changes):
    """Write the metadata in the given dictionary into the ebook file."""

    path = ebmeta.arguments.filename

    for key in changes.keys():
        if changes[key] == None: changes[key] = ""

    args = [
        'ebook-meta',
        '"{}"'.format(path)
    ]
    for a, b in (
        ('authors',       'authors'),
        ('book-producer', 'book producer'),
        ('isbn',          'isbn'),
        ('language',      'language'),
        ('date',          'publication date'),
        ('publisher',     'publisher'),
        ('series',        'series'),
        ('title',         'title')
    ):
        if b in changes: args.append('--{}="{}"'.format(a, quote(changes[b])))

    for a, b in (
        ('rating',        'rating'), # rating can't be unset once it's set, from ebook-meta CLI
        ('index',         'series index'), # series index can't be unset either
        ('author-sort',   'author sort'),
        ('title-sort',    'title sort')
    ):
        if b in changes:
            if changes[b]:
                args.append('--{}="{}"'.format(a, quote(changes[b])))

    if 'description' in changes:
        description = shell.pipe(['pandoc'], changes['description'])
        args.append('--comments="{}"'.format(quote(description)))

    if 'tags' in changes:
        args.append('--tags="{}"'.format(quote(','.join(changes['tags']))))

    if len(args) > 2:
        # Run ebook-meta
        shell.pipe(' '.join(args), shell=True)
Exemplo n.º 9
0
    def __get_content_opf_str(self):
        if self.__content_opf_str:
            return self.__content_opf_str

        try:
            with ZipFile(self.path, "r") as zip:
                try:
                    self.__content_opf_str = unicode(zip.read("content.opf"), "utf_8", "replace")
                except KeyError:
                    self.__content_opf_str = unicode(zip.read("OEBPS/content.opf"), "utf_8", "replace")
            return self.__content_opf_str
        except:
            pass

        # give up and use the ebook-meta to get the metadata
        with tempfile.NamedTemporaryFile() as f:
            shell.pipe(["ebook-meta", "--to-opf=" + f.name, self.path])
            self.__content_opf_str = unicode(f.read(), "utf_8", "replace")

        return self.__content_opf_str
Exemplo n.º 10
0
def write_changes_pdf(ebook, changes):
    """Write the metadata in the given dictionary into the pdf file."""

    path = ebmeta.arguments.filename

    for key in changes.keys():
        if changes[key] == None: changes[key] = ""

    args = ['exiftool', '"{}"'.format(path)]
    for a, b in (('Author', 'authors'), ('Title', 'title'), ('Description',
                                                             'description')):
        if b in changes: args.append('-{}="{}"'.format(a, quote(changes[b])))

    if 'tags' in changes:
        args.append('-Keywords=""')
        for tag in changes['tags']:
            args.append('-Keywords+="{}"'.format(quote(tag)))

    if len(args) > 2:
        # Run ebook-meta
        shell.pipe(' '.join(args), shell=True)
Exemplo n.º 11
0
def write_changes_pdf(ebook, changes):
    """Write the metadata in the given dictionary into the pdf file."""

    path = ebmeta.arguments.filename

    for key in changes.keys():
        if changes[key] == None: changes[key] = ""

    args = [
        u"exiftool",
        u'"{}"'.format(path)
    ]
    for a, b in (
        (u'Author', 'authors'),
        (u'Title',  'title')
    ):
        if changes.has_key(b): args.append(u"-{}=\"{}\"".format(a, quote(changes[b])))

    if len(args) > 2:
        # Run ebook-meta
        # shell.run(" ".join(args), shell=True)
        shell.pipe(u" ".join(args), shell=True)
Exemplo n.º 12
0
    def get_metadata(self):
        if self.__opf:
            return self.__opf

        opf_str = None

        try:
            with ZipFile(self.path, 'r') as zip:
                try:
                    opf_str = zip.read('content.opf').decode('utf-8')
                except KeyError:
                    opf_str = zip.read('OEBPS/content.opf').decode('utf-8')
        except:
            pass

        # give up and use the ebook-meta to get the metadata
        if opf_str is None:
            with tempfile.NamedTemporaryFile() as f:
                shell.pipe(["ebook-meta", "--to-opf=" + f.name, self.path])
                opf_str = f.read().decode('utf-8')

        self.__opf = OpfReader(opf_str)
        return self.__opf
Exemplo n.º 13
0
    def get_metadata(self):
        if self.__opf:
            return self.__opf

        opf_str = None

        try:
            with ZipFile(self.path, 'r') as zip:
                try:
                    opf_str = zip.read('content.opf').decode('utf-8')
                except KeyError:
                    opf_str = zip.read('OEBPS/content.opf').decode('utf-8')
        except:
            pass

        # give up and use the ebook-meta to get the metadata
        if opf_str is None:
            with tempfile.NamedTemporaryFile() as f:
                shell.pipe(["ebook-meta", "--to-opf=" + f.name, self.path])
                opf_str = f.read().decode('utf-8')

        self.__opf = OpfReader(opf_str)
        return self.__opf
Exemplo n.º 14
0
def htmlToMarkdown(txt):
    if not txt: return txt
    return shell.pipe(["pandoc", "--no-wrap", "--from", "html", "--to", "markdown"], txt).strip()
Exemplo n.º 15
0
def html_to_markdown(txt):
    if not txt:
        return txt
    return shell.pipe(['pandoc', '--no-wrap', '--from', 'html', '--to', 'markdown'], txt).strip()
Exemplo n.º 16
0
def html_to_markdown(txt):
    if not txt:
        return txt
    return shell.pipe(
        ['pandoc', '--no-wrap', '--from', 'html', '--to', 'markdown'],
        txt).strip()
Exemplo n.º 17
0
def htmlToMarkdown(txt):
    if not txt: return txt
    return shell.pipe(
        ["pandoc", "--no-wrap", "--from", "html", "--to", "markdown"],
        txt).strip()