desbma / GoogleSpeech

Read text using Google Translate TTS API
GNU Lesser General Public License v2.1
161 stars 37 forks source link

Should probably use ~/.cache or $XDG_CACHE_HOME #1

Closed alphapapa closed 8 years ago

alphapapa commented 8 years ago

First, thanks for this script. It works really well! I had a Bash script that just used curl and sox to play MP3s from GT, but then Google went and broke it with their CAPTCHA stuff (even for just a single query it failed), and I wasn't able to easily figure out how to fix that. So I went looking for other options and I found yours from https://github.com/Glutanimate/simple-google-tts

I noticed that it has caching, and I was curious how, so I looked into the code. I see that you store the database in /var/tmp. I think you should store it in ~/.cache or $XDG_CACHE_HOME instead. Those are the standard locations for per-user caches.

Also as it is, if more than one user on a system used your script, the caches would conflict with each other, being stored in the same place with the same filename.

Thanks again, keep up the great work!

desbma commented 8 years ago

Well, there is no conflict issue possible, because the cache is actually a SQLite database, which is designed to handle concurrent read/writes. So even if two users call google_speech and access the cache at the same, there is no possibility of corruption, in fact one of the users could benefit from already having the sound in the cache because another user accessed it previously.

However I think you are right, /var/tmp kind of breaks the expectation on Unix systems.

Originally, I was using tempfile.gettempdir() which is cross-platform (I support Windows) and returns /tmp on Linux, but as the comment tells, I changed it because /tmp is often wiped out at each reboot.

To be perfectly Unixy, I should use /var/cache, but it is owned by root, and there is also the privacy issue of user data being accessible by all users.

I'll do the change and use the XDG convention.

desbma commented 8 years ago

Done