summaryrefslogtreecommitdiffstats
path: root/share/extensions/other/clipart/sources/inkscape-web.py
blob: 5960c3ed7116e0ac769e7ae0fd2a135d22cbe654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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"],
            }