Skip to content

Commit

Permalink
Merge pull request #52
Browse files Browse the repository at this point in the history
Removed Podcast Session Info
  • Loading branch information
donkevlar authored Oct 27, 2024
2 parents 7f0d319 + f9513f4 commit ca87ee4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Scripts/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,14 @@ async def search_media_auto_complete(self, ctx: AutocompleteContext):
formatted_sessions_string, data = await c.bookshelf_listening_stats()

for sessions in data['recentSessions']:
bookID = sessions['bookId']
mediaMetadata = sessions['mediaMetadata']
title = sessions.get('displayTitle')
subtitle = mediaMetadata.get('subtitle')
display_author = sessions.get('displayAuthor')
bookID = sessions.get('libraryItemId')
itemID = sessions.get('libraryItemId')
name = f"{title} | {display_author}"

if len(name) <= 100:
pass
elif len(title) <= 100:
Expand All @@ -704,9 +706,9 @@ async def search_media_auto_complete(self, ctx: AutocompleteContext):
else:
name = "Recent Book Title Too Long :("

formatted_item = {"name": name, "value": bookID}
formatted_item = {"name": name, "value": itemID}

if formatted_item not in choices:
if formatted_item not in choices and bookID is not None:
choices.append(formatted_item)

await ctx.send(choices=choices)
Expand Down
8 changes: 8 additions & 0 deletions Scripts/bookshelfAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ async def bookshelf_get_item_details(book_id) -> dict:


async def bookshelf_listening_stats():
"""
Gets the 10 most recent sessions for the logged in ABS user.
:return: formatted_session_info, data
"""
bookshelfToken = os.environ.get("bookshelfToken")
endpoint = "/me/listening-stats"
formatted_sessions = []
Expand Down Expand Up @@ -914,6 +918,10 @@ async def bookshelf_get_valid_books() -> list:
async def main():
if __name__ == '__main__':
print("TESTING COMMENCES")
response, data = await bookshelf_listening_stats()
count = 0
for items in data['recentSessions']:
print(items.get('bookId'))


asyncio.run(main())
9 changes: 5 additions & 4 deletions Scripts/default_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ async def search_media_auto_complete(self, ctx: AutocompleteContext):
count = 0

for sessions in data['recentSessions']:
count += 1
bookID = sessions['bookId']
mediaMetadata = sessions['mediaMetadata']
title = sessions.get('displayTitle')
subtitle = mediaMetadata.get('subtitle')
display_author = sessions.get('displayAuthor')
bookID = sessions.get('libraryItemId')
itemID = sessions.get('libraryItemId')

name = f"{title} | {display_author}"

Expand All @@ -380,9 +380,10 @@ async def search_media_auto_complete(self, ctx: AutocompleteContext):
logger.debug("Recent Session {count}: Subtitle was too long, falling back to recent session")
name = f"Recent Session {count}"

formatted_item = {"name": name, "value": bookID}
formatted_item = {"name": name, "value": itemID}

if formatted_item not in choices:
if formatted_item not in choices and bookID is not None:
count += 1
choices.append(formatted_item)

await ctx.send(choices=choices)
Expand Down

0 comments on commit ca87ee4

Please sign in to comment.