From 4dc792e1e2d3771b6d6620f5d564ea091597c4dc Mon Sep 17 00:00:00 2001 From: cy8aer Date: Fri, 2 Aug 2019 13:25:25 +0200 Subject: [PATCH] [enh] add invidious engine. (#1657) closes #1372 --- searx/engines/invidious.py | 100 ++++++++++++++++++ searx/settings.yml | 6 ++ .../themes/oscar/img/icons/invidious.png | Bin 0 -> 3427 bytes 3 files changed, 106 insertions(+) create mode 100644 searx/engines/invidious.py create mode 100644 searx/static/themes/oscar/img/icons/invidious.png diff --git a/searx/engines/invidious.py b/searx/engines/invidious.py new file mode 100644 index 000000000..8d81691fc --- /dev/null +++ b/searx/engines/invidious.py @@ -0,0 +1,100 @@ +# Invidious (Videos) +# +# @website https://invidio.us/ +# @provide-api yes (https://github.com/omarroth/invidious/wiki/API) +# +# @using-api yes +# @results JSON +# @stable yes +# @parse url, title, content, publishedDate, thumbnail, embedded + +from searx.url_utils import quote_plus +from dateutil import parser +import time + +# engine dependent config +categories = ["videos", "music"] +paging = True +language_support = True +time_range_support = True + +# search-url +base_url = "https://invidio.us/" + + +# do search-request +def request(query, params): + time_range_dict = { + "day": "today", + "week": "week", + "month": "month", + "year": "year", + } + search_url = base_url + "api/v1/search?q={query}" + params["url"] = search_url.format( + query=quote_plus(query) + ) + "&page={pageno}".format(pageno=params["pageno"]) + + if params["time_range"] in time_range_dict: + params["url"] += "&date={timerange}".format( + timerange=time_range_dict[params["time_range"]] + ) + + if params["language"] != "all": + lang = params["language"].split("-") + if len(lang) == 2: + params["url"] += "&range={lrange}".format(lrange=lang[1]) + + return params + + +# get response from search-request +def response(resp): + results = [] + + search_results = resp.json() + embedded_url = ( + '' + ) + + base_invidious_url = base_url + "watch?v=" + + for result in search_results: + rtype = result.get("type", None) + if rtype == "video": + videoid = result.get("videoId", None) + if not videoid: + continue + + url = base_invidious_url + videoid + embedded = embedded_url.format(videoid=videoid) + thumbs = result.get("videoThumbnails", []) + thumb = next( + (th for th in thumbs if th["quality"] == "sddefault"), None + ) + if thumb: + thumbnail = thumb.get("url", "") + else: + thumbnail = "" + + publishedDate = parser.parse( + time.ctime(result.get("published", 0)) + ) + + results.append( + { + "url": url, + "title": result.get("title", ""), + "content": result.get("description", ""), + "template": "videos.html", + "publishedDate": publishedDate, + "embedded": embedded, + "thumbnail": thumbnail, + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 490b3af04..504a9fbe0 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -392,6 +392,12 @@ engines: timeout : 6.0 disabled : True + - name : invidious + engine : invidious + base_url : 'https://invidio.us/' + shortcut: iv + timeout : 5.0 + - name: kickass engine : kickass shortcut : kc diff --git a/searx/static/themes/oscar/img/icons/invidious.png b/searx/static/themes/oscar/img/icons/invidious.png new file mode 100644 index 0000000000000000000000000000000000000000..a94c969d8a43f4096eb2bc20e6028a8579b98380 GIT binary patch literal 3427 zcmV-p4V?0cP)oSdhpr?IiIxw*N&zrV!9 z#K*_S$;rvc$jHUT#lXP8y1Kfuva+eEsh*ymk&%&vgoJi>c4}&BU|?WcT3T&wZJC*w zu&}Vz)z#qO;OOY+?d|RF@9**P@$&NW>FMd=;o;ZU*R-^>ot>S9g@tf%a9CJaYinzU zhK8o5rrO%t@bK{6-QBCJtBZ?^Z*OmNb90rImDt$W>+9>=+uNI)n|OG5Zfq%+%D>W@cu6eSPZc>W7DiadC0veACm@jEszmii&r4cg@Ys!^6XJa&n-cpz-kV^YQTV@$j>=v*qRG+sO%@L9|75xVdKw(tSA@C&){LdNjB& zGQ#l9=kW6I@XpT8rQYxhxbS?`@ZaCxb<*%k$nfdz@WR5va?K=&gk%sjg9Z{@XE@{V`F2Jlao|bRK~`}x3{;JmX?W$iLbA(b#--mdU}I{gO`_= zwzjslwY6nsWu&B}pP!$hp`os>uH4+*Q&Urpj*h6PsH&=}Vq#*vyu7=+yR59NrKP2S zfPl^%*`@#h3aCj$K~#9!?cD`?+sGCM;5lQ6%gpE$Vx4hNg;PlDFc$4{>NaI&xXgE% znVA_}W@fnm;Qo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