moehmeni / syncedlyrics

Get an LRC format (synchronized) lyrics for your music
MIT License
188 stars 18 forks source link

added 10 second timeout to requests #44

Closed jmaximusix closed 1 month ago

jmaximusix commented 1 month ago

Added 10 second timeout to requests so the program doesn't get stuck indefinitely when a provider is temporarily unavailable

moehmeni commented 1 month ago

Thanks for the contribution! It would be great to have a general get method in the base class and replace all session.get to that method so we have just one function for making any request since I have called self.session.get in different providers.

jmaximusix commented 1 month ago

You're right, sadly there doesn't appear to be a built-in option to set a default timeout, but by creating the TimeoutSession class which inherits from requests.Session and overrides the request method, this should now be the default for all requests and can still be overridden by the keyword argument.

I also just learned that you can seperate the timeout into connect and read timeouts, This reduces the time it takes to timeout if a provider is temporarily down and therefore no connection is made. I now set 2 seconds as the default to connect and an additional 5 seconds to read, but feel free to change these values if you want.

moehmeni commented 1 month ago

That's great! thanks.