Skip to content

Commit

Permalink
[added] Handle more than 300 books in the library.
Browse files Browse the repository at this point in the history
  • Loading branch information
TnS-hun committed Nov 14, 2017
1 parent a03e821 commit c4ec168
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions kobo-book-downloader/Kobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,39 @@ def GetBookInfo( self, productId: str ) -> dict:
jsonResponse = response.json()
return jsonResponse

def GetMyBookList( self ) -> dict:
# There is also "library_items" but that is paged and gives back less info (even with the embed=ProductMetadata
# query parameter set).

def __GetMyBookListPage( self, syncToken: str ) -> Tuple[ dict, str ]:
url = self.InitializationSettings[ "library_sync" ]
headers = Kobo.GetHeaderWithAccessToken()
hooks = Kobo.__GetReauthenticationHook()

if len( syncToken ) > 0:
headers[ "x-kobo-synctoken" ] = syncToken

response = Globals.Kobo.Session.get( url, headers = headers, hooks = hooks )
response.raise_for_status()
bookList = response.json()

return bookList
syncToken = ""
syncResult = response.headers.get( "x-kobo-sync" )
if syncResult == "continue":
syncToken = response.headers.get( "x-kobo-synctoken", "" )

return bookList, syncToken

def GetMyBookList( self ) -> dict:
# The "library_sync" name and the synchronization tokens make it somewhat suspicious that we should use
# "library_items" instead to get the My Books list, but "library_items" gives back less info (even with the
# embed=ProductMetadata query parameter set).

fullBookList = []
syncToken = ""
while True:
bookList, syncToken = self.__GetMyBookListPage( syncToken )
fullBookList += bookList
if len( syncToken ) == 0:
break

return fullBookList

def __GetContentAccessBook( self, productId: str, displayProfile: str ) -> dict:
url = self.InitializationSettings[ "content_access_book" ].replace( "{ProductId}", productId )
Expand Down

0 comments on commit c4ec168

Please sign in to comment.