Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback function on new API #53

Closed
lekoOwO opened this issue Jan 31, 2021 · 2 comments
Closed

callback function on new API #53

lekoOwO opened this issue Jan 31, 2021 · 2 comments

Comments

@lekoOwO
Copy link

lekoOwO commented Jan 31, 2021

I'm using the latest commit in master branch.

Before this update, I used to do:

ChatReplayDownloader().get_youtube_messages(video_id, callback=my_callback)

But now I don't see a callback parameter provided, is there any fix? Thanks!

@xenova
Copy link
Owner

xenova commented Jan 31, 2021

Hi there! The new version now uses generators to manage chat objects :) This makes it a lot easier to define better/more complex callback options. As an example:

from chat_replay_downloader import ChatDownloader
video_id = 'J2umj9SgdFU'  
chat = ChatDownloader().get_chat(video_id) # creates a generator
for message in chat: # you can now iterate over it!
    print(message) # callback goes here

would continue outputting:

{'action_type': 'add_chat_item', 'message': 'finally Vishy with new camera angle', 'message_id': 'CkUKGkNQX2cyLS1QeHU0Q0ZmSU1mUW9kVTMwTDRBEidDSi1ScWRLUHh1NENGZXFEckFJZF9pUUhZUTE2MTIwOTQ0NjQ0ODY%3D', 'timestamp': 1612094465568923, 'author': {'name': 'Samir Ghimire', 'images': [{'url': 'https://yt3.ggpht.com/ytc/AAUvwni2C4pmWWWjaxY2ZUnFjYqiyCpD3Y-mXhozkw=s32-c-k-c0xffffffff-no-rj-mo', 'width': 32, 'height': 32, 'id': '32x32'}, {'url': 'https://yt3.ggpht.com/ytc/AAUvwni2C4pmWWWjaxY2ZUnFjYqiyCpD3Y-mXhozkw=s64-c-k-c0xffffffff-no-rj-mo', 'width': 64, 'height': 64, 'id': '64x64'}], 'id': 'UCD-RwEzxUzl1MsSpc-AwMtw'}, 'message_type': 'text_message'}
{'action_type': 'add_chat_item', 'message': 'ohh thank you', 'message_id': 'CkUKGkNPWHotLS1QeHU0Q0ZYMGVyUVlkVmxzR1BnEidDTUhEOXE2UHh1NENGZUhyT0FZZGNUd0NDZzE2MTIwOTQ0NjU1NDI%3D', 'timestamp': 1612094466095675, 'author': {'name': 'Bilal Dwianugrah', 'images': [{'url': 'https://yt3.ggpht.com/ytc/AAUvwngONPUrnE6jnDHU48XbXmcj5XAjz1K86KMjFA=s32-c-k-c0xffffffff-no-rj-mo', 'width': 32, 'height': 32, 'id': '32x32'}, {'url': 'https://yt3.ggpht.com/ytc/AAUvwngONPUrnE6jnDHU48XbXmcj5XAjz1K86KMjFA=s64-c-k-c0xffffffff-no-rj-mo', 'width': 64, 'height': 64, 'id': '64x64'}], 'id': 'UCFb-yF95C1QOrFNWYCAc3Zw'}, 'message_type': 'text_message'}

I will be adding a lot of documentation soon! I just had to release this relatively unpolished version because of YouTube API endpoint changes.

@lekoOwO
Copy link
Author

lekoOwO commented Jan 31, 2021

Ohhhh it's now a generator, that's really great!
Thank you!

@xenova xenova closed this as completed Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants