forked from MiczFlor/RPi-Jukebox-RFID
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cover Art with Cache (MiczFlor#2177)
* CoverArt with Cache in Docker, Cache Path on Pi missing * Make cache path available in both Docker and Pi * Fix flake8 errors
- Loading branch information
1 parent
76ca98c
commit e18ab88
Showing
12 changed files
with
119 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/jukebox/components/playermpd/coverart_cache_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
|
||
|
||
class CoverartCacheManager: | ||
def __init__(self, cache_folder_path): | ||
self.cache_folder_path = cache_folder_path | ||
|
||
def find_file_by_hash(self, hash_value): | ||
for filename in os.listdir(self.cache_folder_path): | ||
if filename.startswith(hash_value): | ||
return filename | ||
return None | ||
|
||
def save_to_cache(self, base_filename, album_art_data): | ||
mime_type = album_art_data['type'] | ||
file_extension = 'jpg' if mime_type == 'image/jpeg' else mime_type.split('/')[-1] | ||
cache_filename = f"{base_filename}.{file_extension}" | ||
|
||
with open(os.path.join(self.cache_folder_path, cache_filename), 'wb') as file: | ||
file.write(album_art_data['binary']) | ||
|
||
return cache_filename |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters