Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved Searching Licensed Bug #259

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 116 additions & 214 deletions src/assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,220 +45,122 @@ document.addEventListener("DOMContentLoaded", function (e) {
}

// construct license params by engine convention
function getLicenseParams(form) {
let rights;

// engine licenses logic alphabetically
// does nothing for now, will revisit later

if (form.commercial || form.modify) {
switch (form.searchEngine) {
case "ccmixter":
rights = "";
if (form.commercial && form.modify) {
rights += "&lic=by,sa,s,splus,pd,zero";
} else if (form.commercial) {
rights += "&lic=open";
} else if (form.modify) {
rights += "&lic=by,nc,sa,ncsa,s,splus,pd,zero";
}
break;

case "europeana":
rights = "+AND+RIGHTS%3A*creative*+";
if (form.commercial && form.modify) {
rights += "AND+NOT+RIGHTS%3A*nc*+AND+NOT+RIGHTS%3A*nd*";
} else if (form.commercial) {
rights += "AND+NOT+RIGHTS%3A*nc*";
} else if (form.modify) {
rights += "AND+NOT+RIGHTS%3A*nd*";
}
break;

case "flickr":
rights = "&license=";
if (form.commercial && form.modify) {
rights += "4%2C5%2C9%2C10";
} else if (form.commercial) {
rights += "4%2C5%2C6%2C9%2C10";
} else if (form.modify) {
rights += "1%2C2%2C9%2C10";
}
break;

case "google":
rights = "&as_rights=(cc_publicdomain|cc_attribute|cc_sharealike).-";
if (form.commercial && form.modify) {
rights += "(cc_noncommercial|cc_nonderived)";
} else if (form.commercial) {
rights += "(cc_noncommercial)";
} else if (form.modify) {
rights += "(cc_nonderived)";
}
break;

case "googleimages":
rights = "&as_rights=(cc_publicdomain|cc_attribute|cc_sharealike).-";
if (form.commercial && form.modify) {
rights += "(cc_noncommercial|cc_nonderived)";
} else if (form.commercial) {
rights += "(cc_noncommercial)";
} else if (form.modify) {
rights += "(cc_nonderived)";
}
break;

case "jamendo":
rights = "";
if (form.commercial && form.modify) {
rights += "-nc%20AND%20-nd";
} else if (form.commercial) {
rights += "-nc";
} else if (form.modify) {
rights += "-nd";
}
break;

case "nappy":
rights = "";
if (form.commercial && form.modify) {
rights += "";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "openclipart":
rights = "";
if (form.commercial && form.modify) {
rights += "";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "opengameart":
rights = "&sort_by=count&sort_order=DESC"; // Just standard OGA search filters
if (form.commercial && form.modify) {
rights +=
"&field_art_licenses_tid[]=2&field_art_licenses_tid[]=17981" + // Include CC BY (3.0 and 4.0) licenses
"&field_art_licenses_tid[]=17982&field_art_licenses_tid[]=3" + // Include CC BY-SA (3.0 and 4.0) licenses
"&field_art_licenses_tid[]=4"; // Include CC0 license

// I don't sure about permissiveness of OGA BY (3.0 and 4.0) licenses,
// so I decided to comment this line
//+ '&field_art_licenses_tid[]=10310&field_art_licenses_tid[]=31772'
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "openverse":
rights = "&license_type=";
if (form.commercial && form.modify) {
rights += "commercial,modification";
} else if (form.commercial) {
rights += "commercial";
} else if (form.modify) {
rights += "modification";
}
break;

case "sketchfab":
rights = "";
if (form.commercial && form.modify) {
rights +=
"&features=downloadable" +
"&licenses=322a749bcfa841b29dff1e8a1bb74b0b" + // Include CC BY license
"&licenses=b9ddc40b93e34cdca1fc152f39b9f375" + // Include CC BY-SA license
"&licenses=7c23a1ba438d4306920229c12afcb5f9"; // Include CC0
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "soundcloud":
rights = "";
if (form.commercial && form.modify) {
rights += "&filter.license=to_modify_commercially";
} else if (form.commercial) {
rights += "&filter.license=to_use_commercially";
} else if (form.modify) {
rights += "&filter.license=to_share";
}
break;

case "thingiverse":
// currently defering to openverse since
// thingiverse filtering is broken
rights = "&license_type=";
if (form.commercial && form.modify) {
rights += "commercial,modification";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "vimeo":
rights = "&license=";
if (form.commercial && form.modify) {
rights += "by";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "wikipedia-commons":
rights = "";
if (form.commercial && form.modify) {
rights += "";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "youtube":
rights = "&sp=EgIwAQ%253D%253D";
if (form.commercial && form.modify) {
rights += "";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

// if you want to add a new engine logic,
// you can work from this:

// case "default":
// rights = '';
// if (form.commercial && form.modify) {
// rights += '';
// } else if (form.commercial) {
// rights += '';
// } else if (form.modify) {
// rights += '';
// }
// break;
}
} else {
rights = "";
function getLicenseParams(form) {
let rights = "";

// Check if commercial or modify options are selected
if (form.commercial || form.modify) {
switch (form.searchEngine) {
case "ccmixter":
rights = "&f=license:";
if (form.commercial && form.modify) {
rights += "cc-by,cc-by-sa";
} else if (form.commercial) {
rights += "cc-by,cc-by-nc";
} else if (form.modify) {
rights += "cc-by,cc-by-nd";
}
break;

case "europeana":
rights = "+AND+RIGHTS%3A*creative*+";
if (form.commercial && form.modify) {
rights += "AND+NOT+RIGHTS%3A*nc*+AND+NOT+RIGHTS%3A*nd*";
} else if (form.commercial) {
rights += "AND+NOT+RIGHTS%3A*nc*";
} else if (form.modify) {
rights += "AND+NOT+RIGHTS%3A*nd*";
}
break;

case "flickr":
rights = "&license=";
if (form.commercial && form.modify) {
rights += "4%2C5%2C9%2C10";
} else if (form.commercial) {
rights += "4%2C5%2C6%2C9%2C10";
} else if (form.modify) {
rights += "1%2C2%2C9%2C10";
}
break;

case "google":
case "googleimages":
rights = "&as_rights=(cc_publicdomain|cc_attribute|cc_sharealike).-";
if (form.commercial && form.modify) {
rights += "(cc_noncommercial|cc_nonderived)";
} else if (form.commercial) {
rights += "(cc_noncommercial)";
} else if (form.modify) {
rights += "(cc_nonderived)";
}
break;

case "jamendo":
rights = "";
if (form.commercial && form.modify) {
rights += "";
} else if (form.commercial) {
rights += "";
} else if (form.modify) {
rights += "";
}
break;

case "openverse":
rights = "&license_type=";
if (form.commercial && form.modify) {
rights += "commercial,modification";
} else if (form.commercial) {
rights += "commercial";
} else if (form.modify) {
rights += "modification";
}
break;

case "soundcloud":
rights = "&filter.license=";
if (form.commercial && form.modify) {
rights += "to_modify_commercially";
} else if (form.commercial) {
rights += "to_use_commercially";
} else if (form.modify) {
rights += "to_share";
}
break;

case "thingiverse":
rights = "&license_type=";
if (form.commercial && form.modify) {
rights += "commercial,modification";
} else if (form.commercial) {
rights += "commercial";
} else if (form.modify) {
rights += "modification";
}
break;

case "vimeo":
rights = "&license=";
if (form.commercial && form.modify) {
rights += "by";
}
break;

case "youtube":
rights = "&sp=EgIwAQ%253D%253D";
if (form.commercial && form.modify) {
rights += ""; // Add appropriate filters for YouTube as per your requirement
}
break;

default:
rights = ""; // Default case if the search engine doesn't require any rights parameters
break;
}
return rights;
}

return rights;
}

});
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ <h3>Find content you can share, use, and remix.</h3>
id="ccmixter"
name="search-engine"
value="ccmixter"
class="search-engines"
data-object="engine"
data-engine="ccmixter"
data-url="http://ccmixter.org/search?search_type=any&search_in=all&search_text=" />
data-url="https://ccmixter.org/search?search_type=any&search_in=all&search_text=" />
<label
for="ccmixter"
class="engines"
Expand Down