Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 12-27-2021, 07:48 PM   #1
Tommalka
Enthusiast
Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.
 
Posts: 36
Karma: 1088351
Join Date: Dec 2021
Device: Kobo Libra 2
[Concept] Telegram Bot for converting epubs to kepubs (and transferring)

I just wanted to share with you an approach to easily convert ePubs to Kepubs and a possibility to transfer them very easy wirelessly to a cloud: A Telegram Bot!

The simple script below will use Kepubify and is written in python using telegram-python-bot (can be installed with pip).
Function summarised: If you send an .epub in the Telegram chat of the bot, a Kepub will come back.
One could now very easy implement an upload to a cloud and use the KoboCloud hack on his Kobo for the perfect wireless expericence.

(I don't want to go into details about Telegram bots in general, just wanted to share the idea. There are many tutorials out there about hosting such a bot if you don't know how to)

Code:
from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import os

telegramToken = "1234567Placeholder"
nameOfKepubifyBinary = "kepubify-linux-64bit" #binary in the same folder as this script

def conversion(update, context):
    try:
        fileName = update.message.document.file_name #get name of document
        fileExtension = os.path.splitext(fileName)[1] #get only the extension
        if fileExtension.lower() == ".epub": 
            fileEpub = context.bot.getFile(update.message.document.file_id)
            update.message.reply_text("Processing the following file:\n\n" + fileName)
            fileEpub.download(fileName) #download the epub to the server
            #do the conversion to kepub
            os.system("./"+nameOfKepubifyBinary + " '" + fileName + "'") 
            #get the kepub
            fileKepub = fileName.replace(".epub", "_converted.kepub.epub")
            #send the kepub
            context.bot.send_document(chat_id=update.message.chat_id, document=open(fileKepub, 'rb'), caption="Here is your Kepub.")
            
            #now you can upload it to any cloud...
            
            #remove the files from the server
            os.remove(fileName)
            os.remove(fileKepub)
        else:
              update.message.reply_text("Error. You send me a "+fileExtension+"\nbut only .epubs are supported.")
    except: 
        update.message.reply_text("Unknown error")
    
def main():
    print("Bot started")
    updater = Updater(token=telegramToken, use_context=True)
    dp = updater.dispatcher
   
    #we get a document
    dp.add_handler(MessageHandler(Filters.document, conversion))

    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
  main()

Last edited by Tommalka; 12-27-2021 at 07:52 PM.
Tommalka is offline   Reply With Quote
Old 12-28-2021, 11:00 AM   #2
Tommalka
Enthusiast
Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.Tommalka ought to be getting tired of karma fortunes by now.
 
Posts: 36
Karma: 1088351
Join Date: Dec 2021
Device: Kobo Libra 2
For now, I'm hosting a Telegram bot with the code above:
https://t.me/epub_kepub_bot

The traffic on my tiny server is limited, so I added a limit of 5 conversions per hour per user
Tommalka is offline   Reply With Quote
Advert
Old 01-01-2022, 04:03 AM   #3
Ceiyne
Enthusiast
Ceiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notesCeiyne can name that song in three notes
 
Posts: 35
Karma: 24602
Join Date: May 2015
Device: Kobo Glo HD
This isn't something I'd need personally, but I love to see people creating stuff like this!
Ceiyne is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
kepubify 2.0 - A standalone tool to convert ePubs to Kepubs geek1011 Kobo Reader 149 10-03-2020 04:12 PM
Kopo Android App sees/imports only epubs, not kepubs stuartjmz Kobo Reader 5 10-22-2018 01:36 PM
Sending epubs to Kobo saves kepubs on hard drive jkrzok Devices 4 03-27-2018 07:52 PM
Kepubs vers Epubs lohtse Kobo Reader 28 11-13-2013 06:58 PM
Pros and Cons of using Kepubs vs ePubs kaufman Kobo Reader 8 04-30-2013 04:41 PM


All times are GMT -4. The time now is 02:02 AM.


MobileRead.com is a privately owned, operated and funded community.