diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/other/clipart/sources/inkscape-web.py | |
parent | Initial commit. (diff) | |
download | inkscape-upstream/1.2.2.tar.xz inkscape-upstream/1.2.2.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | share/extensions/other/clipart/sources/inkscape-web.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/share/extensions/other/clipart/sources/inkscape-web.py b/share/extensions/other/clipart/sources/inkscape-web.py new file mode 100644 index 0000000..5960c3e --- /dev/null +++ b/share/extensions/other/clipart/sources/inkscape-web.py @@ -0,0 +1,74 @@ +# +# Copyright 2021 Martin Owens <doctormo@gmail.com> +# Copyright 2022 Simon Duerr <dev@simonduerr.eu> +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/> +# + +from import_sources import RemoteSource + + +license_mapping = { + "PD": "cc-0", + "CC-0": "cc-0", + "CC-BY 3.0": "cc-by-3.0", + "CC-BY 4.0": "cc-by-4.0", + "CC-BY-SA 4.0": "cc-by-sa-4.0", + "CC-BY-NC 3.0": "cc-by-nc-3.0", + "CC-BY-NC-SA 3.0": "cc-by-nc-sa-3.0", + "CC-BY-NC-SA 4.0": "cc-by-nc-sa-4.0", + "CC-BY-SA 3.0": "cc-by-sa-3.0", + "CC-BY-ND 3.0": "cc-by-nd-3.0", + "ASL": "asl", + "nbsd": "bsd", + "GPLv2": "gpl-2", + "GPLv3": "gpl-3", + "AGPLv3": "agpl-3", + "MIT": "mit", +} + + +class InkscapeWebsite(RemoteSource): + name = "Inkscape Community" + icon = "sources/inkscape-web.svg" + is_default = True + + base_url = "https://inkscape.org/gallery/=artwork/json/" + + def search(self, query): + """Ask the inkscape website for some artwork""" + items = [] + try: + response = self.session.get(self.base_url, params={"q": query}) + items = response.json()["items"] + except Exception: + pass + + for item in items: + if "svg" not in item["type"]: + continue + if ( + item["license"] == "(C)" + ): # ignore copyrighted items because they cannot be reused + continue + yield { + "id": item["id"], + "name": item["name"], + "author": item["author"], + "license": license_mapping.get(item["license"], item["license"].lower()), + "summary": item["summary"], + "thumbnail": item["icon"] or item["links"]["file"], + "created": item["dates"]["created"], + "popularity": item["stats"]["liked"], + "file": item["links"]["file"], + } |