#1925 File: Implemented get_images for file library

Open Parth parth-verma
Showing 1 of 5 files from the diff.

@@ -1,9 +1,12 @@
Loading
1 +
import base64
1 2
import logging
2 3
import os
3 4
4 5
from mopidy import backend, exceptions, models
5 6
from mopidy.audio import scan, tags
7 +
from mopidy.exceptions import ScannerError
6 8
from mopidy.internal import path
9 +
from mopidy.models import Image
7 10
8 11
logger = logging.getLogger(__name__)
9 12
@@ -36,6 +39,8 @@
Loading
36 39
37 40
        self._scanner = scan.Scanner(timeout=config["file"]["metadata_timeout"])
38 41
42 +
        self._folder_image_names = config["file"].get("folder_image_names", [])
43 +
39 44
    def browse(self, uri):
40 45
        logger.debug("Browsing files at: %s", uri)
41 46
        result = []
@@ -146,3 +151,32 @@
Loading
146 151
            path.is_path_inside_base_dir(local_path, media_dir["path"])
147 152
            for media_dir in self._media_dirs
148 153
        )
154 +
155 +
    def get_images(self, uris):
156 +
        images = {}
157 +
        for uri in uris:
158 +
            images[uri] = ()
159 +
            try:
160 +
                result = self._scanner.scan(uri)
161 +
            except ScannerError as e:
162 +
                logger.warning(str(e))
163 +
                continue
164 +
            if len(result.tags.get("image", [])) > 0:
165 +
                image = result.tags["image"][0]
166 +
                images[uri] = (
167 +
                    Image(
168 +
                        uri=f"data:;base64, {base64.b64encode(image).decode('utf-8')}"
169 +
                    ),
170 +
                )
171 +
                continue
172 +
            for i in self._folder_image_names:
173 +
                if (path.uri_to_path(uri).parent / i).exists():
174 +
                    with open(path.uri_to_path(uri).parent / i, "rb",) as f:
175 +
                        images[uri] = (
176 +
                            Image(
177 +
                                uri=f"data:;base64,"
178 +
                                f"{base64.b64encode(f.read()).decode('utf-8')}"
179 +
                            ),
180 +
                        )
181 +
                    break
182 +
        return images

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
mopidy -0.27% 76.52%
Project Totals (55 files) 76.52%
Loading