mirror of
https://github.com/nikdoof/ohayodash.git
synced 2025-12-13 18:12:17 +00:00
Switch to search driven from providers.json
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import kubernetes
|
import kubernetes
|
||||||
|
import pkg_resources
|
||||||
import yaml
|
import yaml
|
||||||
from flask import Blueprint, jsonify, render_template
|
from flask import Blueprint, jsonify, render_template
|
||||||
|
|
||||||
@@ -112,21 +113,10 @@ def index(tag=None):
|
|||||||
@base.route('/providers.json')
|
@base.route('/providers.json')
|
||||||
@base.route('/<tag>/providers.json')
|
@base.route('/<tag>/providers.json')
|
||||||
def providers(tag=None):
|
def providers(tag=None):
|
||||||
return jsonify({
|
data_file = pkg_resources.resource_filename(__name__, 'data/providers.yaml')
|
||||||
'providers': [
|
with open(data_file, 'r') as fobj:
|
||||||
{'name': 'Allmusic', 'url': 'https://www.allmusic.com/search/all/', 'prefix': '/a'},
|
providers = yaml.safe_load(fobj)
|
||||||
{'name': 'Discogs', 'url': 'https://www.discogs.com/search/?q=', 'prefix': '/di'},
|
return jsonify({'providers': providers})
|
||||||
{'name': 'Duck Duck Go', 'url': 'https://duckduckgo.com/?q=', 'prefix': '/d'},
|
|
||||||
{'name': 'iMDB', 'url': 'https://www.imdb.com/find?q=', 'prefix': '/i'},
|
|
||||||
{'name': 'TheMovieDB', 'url': 'https://www.themoviedb.org/search?query=', 'prefix': '/m'},
|
|
||||||
{'name': 'Reddit', 'url': 'https://www.reddit.com/search?q=', 'prefix': '/r'},
|
|
||||||
{'name': 'Qwant', 'url': 'https://www.qwant.com/?q=', 'prefix': '/q'},
|
|
||||||
{'name': 'Soundcloud', 'url': 'https://soundcloud.com/search?q=', 'prefix': '/so'},
|
|
||||||
{'name': 'Spotify', 'url': 'https://open.spotify.com/search/results/', 'prefix': '/s'},
|
|
||||||
{'name': 'TheTVDB', 'url': 'https://www.thetvdb.com/search?query=', 'prefix': '/tv'},
|
|
||||||
{'name': 'Trakt', 'url': 'https://trakt.tv/search?query=', 'prefix': '/t'},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@base.route('/apps.json')
|
@base.route('/apps.json')
|
||||||
|
|||||||
45
ohayodash/data/providers.yaml
Normal file
45
ohayodash/data/providers.yaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
- name: Allmusic
|
||||||
|
url: https://www.allmusic.com/
|
||||||
|
search: search/all/
|
||||||
|
prefix: /a
|
||||||
|
- name: Discogs
|
||||||
|
url: https://www.discogs.com/
|
||||||
|
search: search/?q=
|
||||||
|
prefix: /di
|
||||||
|
- name: DuckDuckGo
|
||||||
|
url: https://duckduckgo.com/
|
||||||
|
search: "?q="
|
||||||
|
prefix: /d
|
||||||
|
- name: iMDB
|
||||||
|
url: https://imbdb.com/
|
||||||
|
search: find?q=
|
||||||
|
prefix: /i
|
||||||
|
- name: TheMovieDB
|
||||||
|
url: https://www.themoviedb.org/
|
||||||
|
search: search/?query=
|
||||||
|
prefix: /m
|
||||||
|
- name: Reddit
|
||||||
|
url: https://www.reddit.com/
|
||||||
|
search: search?q=
|
||||||
|
prefix: /r
|
||||||
|
- name: Qwant
|
||||||
|
url: https://www.qwant.com/
|
||||||
|
search: "?q="
|
||||||
|
prefix: /q
|
||||||
|
- name: Soundcloud
|
||||||
|
url: https://soundcloud.com/
|
||||||
|
search: search?q=
|
||||||
|
prefix: /so
|
||||||
|
- name: Spotify
|
||||||
|
url: https://open.spotify.com/
|
||||||
|
search: search/results/
|
||||||
|
prefix: /s
|
||||||
|
- name: TheTVDB
|
||||||
|
url: https://www.thetvdb.com/
|
||||||
|
search: search?query=
|
||||||
|
prefix: /tv
|
||||||
|
- name: Trakt
|
||||||
|
url: https://trakt.tv/
|
||||||
|
search: search?query=
|
||||||
|
prefix: /t
|
||||||
@@ -1,6 +1,15 @@
|
|||||||
var sindex = 0;
|
var sindex = 0;
|
||||||
var cycle = false;
|
var cycle = false;
|
||||||
var sengine = "https://www.google.com/search?q="; // Default search engine
|
var sengine = "https://www.google.com/search?q="; // Default search engine
|
||||||
|
var providers = [];
|
||||||
|
|
||||||
|
fetch('providers.json')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => storeProviders(data));
|
||||||
|
|
||||||
|
function storeProviders(data) {
|
||||||
|
providers = data['providers'];
|
||||||
|
}
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
var query = getParameterByName('q');
|
var query = getParameterByName('q');
|
||||||
@@ -16,35 +25,10 @@ function start() {
|
|||||||
function handleKeyPress(e) {
|
function handleKeyPress(e) {
|
||||||
var key = e.keyCode || e.which;
|
var key = e.keyCode || e.which;
|
||||||
var text = document.getElementById("keywords").value.replaceAll("+", "%2B");
|
var text = document.getElementById("keywords").value.replaceAll("+", "%2B");
|
||||||
var option = text.substr(1, text.indexOf(' ') - 1) || text.substr(1);
|
|
||||||
var subtext = text.substr(2 + option.length);
|
|
||||||
if (key == 13) { // Search functions
|
if (key == 13) { // Search functions
|
||||||
search(text);
|
search(text.trim());
|
||||||
}
|
}
|
||||||
if (key == 9) { // Tab Completion Functions
|
if (key == 32) { //Space to go to search
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
if (text[0] === ';') {
|
|
||||||
switch (option) {
|
|
||||||
case 't':
|
|
||||||
var streamers = ['admiralbahroo', 'moonmoon_ow', 'witwix'];
|
|
||||||
if (!subtext || cycle) {
|
|
||||||
cycle = true;
|
|
||||||
if (sindex > streamers.length - 1) sindex = 0;
|
|
||||||
document.getElementById("keywords").value = ';t ' + streamers[sindex++];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (var streamer of streamers) {
|
|
||||||
if (subtext === streamer.substr(0, subtext.length)) {
|
|
||||||
document.getElementById("keywords").value = ';t ' + streamer;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(key == 32){ //Space to go to search
|
|
||||||
document.getElementById("keywords").focus();
|
document.getElementById("keywords").focus();
|
||||||
}
|
}
|
||||||
sindex = 0;
|
sindex = 0;
|
||||||
@@ -55,65 +39,17 @@ function search(text) {
|
|||||||
var option = text.substr(1, text.indexOf(' ') - 1) || text.substr(1);
|
var option = text.substr(1, text.indexOf(' ') - 1) || text.substr(1);
|
||||||
var subtext = text.substr(2 + option.length);
|
var subtext = text.substr(2 + option.length);
|
||||||
if (text[0] === '/') {
|
if (text[0] === '/') {
|
||||||
if (text.indexOf(' ') > -1) {
|
providers.every(function (item) {
|
||||||
switch (option) {
|
if ('/' + option == item['prefix']) {
|
||||||
case "am":
|
if (text.indexOf(' ') > -1) {
|
||||||
window.location = "https://www.allmusic.com/search/all/" + subtext;
|
window.location = item['url'] + item['search'] + subtext;
|
||||||
break;
|
} else {
|
||||||
case "d":
|
window.location = item['url'] + subtext;
|
||||||
window.location = "https://duckduckgo.com/?q=" + subtext;
|
}
|
||||||
break;
|
return false;
|
||||||
case "di":
|
|
||||||
window.location = "https://www.discogs.com/search/?q=" + subtext;
|
|
||||||
break;
|
|
||||||
case "i":
|
|
||||||
window.location = "https://www.imdb.com/find?q=" + subtext;
|
|
||||||
break;
|
|
||||||
case "m":
|
|
||||||
window.location = "https://www.themoviedb.org/search?query=" + subtext;
|
|
||||||
break;
|
|
||||||
case "r":
|
|
||||||
window.location = "https://www.reddit.com/search?q=" + subtext;
|
|
||||||
break;
|
|
||||||
case "q":
|
|
||||||
window.location = "https://www.qwant.com/?q=" + subtext;
|
|
||||||
break;
|
|
||||||
case "so":
|
|
||||||
window.location = "https://soundcloud.com/search?q=" + subtext;
|
|
||||||
break;
|
|
||||||
case "s":
|
|
||||||
window.location = "https://open.spotify.com/search/results/" + subtext;
|
|
||||||
break;
|
|
||||||
case "t":
|
|
||||||
window.location = "https://trakt.tv/search?query=" + subtext;
|
|
||||||
break;
|
|
||||||
case "tv":
|
|
||||||
window.location = "https://www.thetvdb.com/search?query=" + subtext;
|
|
||||||
break;
|
|
||||||
case "y":
|
|
||||||
window.location = "https://www.youtube.com/results?search_query=" + subtext;
|
|
||||||
break;
|
|
||||||
case "g":
|
|
||||||
window.location = "https://www.google.com/?q=" + subtext;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
return true;
|
||||||
var option = text.substr(1);
|
});
|
||||||
switch (option) {
|
|
||||||
case "d":
|
|
||||||
window.location = "https://www.duckduckgo.com";
|
|
||||||
break;
|
|
||||||
case "y":
|
|
||||||
window.location = "https://www.youtube.com";
|
|
||||||
break;
|
|
||||||
case "r":
|
|
||||||
window.location = "https://reddit.com";
|
|
||||||
break;
|
|
||||||
case "s":
|
|
||||||
window.location = "https://open.spotify.com";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (validURL(text)) {
|
} else if (validURL(text)) {
|
||||||
if (containsProtocol(text))
|
if (containsProtocol(text))
|
||||||
window.location = text;
|
window.location = text;
|
||||||
@@ -140,7 +76,7 @@ function containsProtocol(str) {
|
|||||||
return !!pattern.test(str);
|
return !!pattern.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
String.prototype.replaceAll = function(search, replacement) {
|
String.prototype.replaceAll = function (search, replacement) {
|
||||||
var target = this;
|
var target = this;
|
||||||
return target.split(search).join(replacement);
|
return target.split(search).join(replacement);
|
||||||
};
|
};
|
||||||
@@ -13,6 +13,7 @@ classifiers =
|
|||||||
|
|
||||||
[options]
|
[options]
|
||||||
zip_safe = False
|
zip_safe = False
|
||||||
|
include_package_data = True
|
||||||
packages = ohayodash
|
packages = ohayodash
|
||||||
install_requires =
|
install_requires =
|
||||||
flask
|
flask
|
||||||
@@ -20,6 +21,9 @@ install_requires =
|
|||||||
pyyaml
|
pyyaml
|
||||||
gunicorn
|
gunicorn
|
||||||
|
|
||||||
|
[options.package_data]
|
||||||
|
ohayodash = data/*.yaml
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
format = wemake
|
format = wemake
|
||||||
ignore = E501,D,WPS226,WPS110, WPS210,WPS231
|
ignore = E501,D,WPS226,WPS110, WPS210,WPS231
|
||||||
|
|||||||
Reference in New Issue
Block a user