Tags add for add songs and in api

This commit is contained in:
Kasper Rynning-Tønnesen
2019-02-24 23:39:36 +01:00
parent 46f0882a63
commit c66d6efa76
6 changed files with 25 additions and 12 deletions

View File

@@ -1247,6 +1247,8 @@ var List = {
var video_id = _song_info.id;
var video_title = _song_info.title;
var video_votes = _song_info.votes;
var tags = "";
if(_song_info.tags != undefined) _song_info.tags.toLowerCase();
var video_thumb_url = "//img.youtube.com/vi/"+video_id+"/mqdefault.jpg";
if(_song_info.source == "soundcloud") {
video_thumb_url = _song_info.thumbnail;
@@ -1316,6 +1318,7 @@ var List = {
song.querySelector(attr).setAttribute("data-video-title", video_title);
song.querySelector(attr).setAttribute("data-video-length", _song_info.length);
song.querySelector(attr).setAttribute("data-added-by", added_by);
song.querySelector(attr).setAttribute("data-tags", tags);
song.querySelector(attr).setAttribute("data-video-type", "suggested");
if(_song_info.source == "soundcloud") {
song.querySelector(attr).setAttribute("data-type-thumbnail", _song_info.thumbnail);

View File

@@ -1461,7 +1461,7 @@ function addDynamicListeners() {
if(substr != "<i c" && !html.classList.contains("waves-effect") && !html.classList.contains("result-start") && !html.classList.contains("result-end") && !html.classList.contains("result-get-more-info")){
var id = e.getAttribute("data-video-id");
var title = e.getAttribute("data-video-title");
var tags = e.getAttribute("data-video-tags").split(",");
var tags = e.getAttribute("data-tags").split(",");
var original_length = e.getAttribute("data-video-length");
var start = parseInt(e.querySelector(".result-start").value);
var end = parseInt(e.querySelector(".result-end").value);
@@ -1601,10 +1601,10 @@ function addDynamicListeners() {
this.stopPropagation();
var id = e.getAttribute("data-video-id");
var title = e.getAttribute("data-video-title");
var tags = e.getAttribute("data-video-tags");
var original_length = e.getAttribute("data-video-length");
var parent = e.parentElement.parentElement;
var tags = parent.parentElement.getAttribute("data-tags").split(",");
var start = parseInt(parent.querySelectorAll(".result-start")[0].value);
var end = parseInt(parent.querySelectorAll(".result-end")[0].value);
if(end > original_length) {
@@ -1654,13 +1654,14 @@ function addDynamicListeners() {
var title = e.getAttribute("data-video-title");
var length = e.getAttribute("data-video-length");
var added_by = e.getAttribute("data-added-by");
var tags = e.getAttribute("data-tags");
var source = "youtube";
var thumbnail;
if(e.getAttribute("data-video-source") != undefined) {
source = "soundcloud";
thumbnail = e.getAttribute("data-type-thumbnail");
}
Search.submit(id, title, parseInt(length), false, 0, 1, 0, parseInt(length), source, thumbnail);
Search.submit(id, title, parseInt(length), false, 0, 1, 0, parseInt(length), source, thumbnail, tags);
if(added_by == "user") {
number_suggested = number_suggested - 1;
if(number_suggested < 0) number_suggested = 0;

View File

@@ -108,7 +108,8 @@ var Search = {
var id=song.id;
duration = duration.replace("PT","").replace("H","h ").replace("M","m ").replace("S","s");
var thumb=song.snippet.thumbnails.medium.url;
var tags = "";
if(song.snippet.tags != undefined) tags = song.snippet.tags.join(",");
//$("#results").append(result_html);
var songs = pre_result.cloneNode(true);
songs.querySelector(".search-title").innerText = title;
@@ -120,7 +121,7 @@ var Search = {
songs.querySelector("#add-many").setAttribute("data-video-length", secs);
//$($(songs).querySelector("div")[0]).setAttribute("onclick", "submitAndClose('"+id+"','"+enc_title+"',"+secs+");");
songs.querySelector("#temp-results").setAttribute("data-video-id", id);
songs.querySelector("#temp-results").setAttribute("data-video-tags", song.snippet.tags.join(","));
songs.querySelector("#temp-results").setAttribute("data-tags", tags.toLowerCase());
songs.querySelector("#temp-results").setAttribute("data-video-title", enc_title);
songs.querySelector("#temp-results").setAttribute("data-video-length", secs);
songs.querySelector(".open-externally").setAttribute("href", "https://www.youtube.com/watch?v=" + id);
@@ -247,6 +248,7 @@ var Search = {
songs.querySelector("#add-many").setAttribute("data-video-title", enc_title);
songs.querySelector("#add-many").setAttribute("data-video-length", secs);
//$($(songs).querySelector("div")[0]).setAttribute("onclick", "submitAndClose('"+id+"','"+enc_title+"',"+secs+");");
songs.querySelector("#temp-results").setAttribute("data-tags", song.genre.toLowerCase());
songs.querySelector("#temp-results").setAttribute("data-video-id", id);
songs.querySelector("#temp-results").setAttribute("data-video-title", enc_title);
songs.querySelector("#temp-results").setAttribute("data-video-length", secs);

View File

@@ -63,7 +63,7 @@ var Suggestions = {
Helper.removeClass("#suggest-song-html", "hide");
}
var get_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&relatedToVideoId="+id+"&type=video&key="+api_key.youtube;
var video_urls = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,statistics&key="+api_key.youtube+"&id=";
var video_urls = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,statistics&fields=pageInfo,items(id,contentDetails,snippet(categoryId,channelTitle,publishedAt,title,description,tags,thumbnails))&key="+api_key.youtube+"&id=";
Helper.ajax({
type: "GET",
@@ -93,6 +93,7 @@ var Suggestions = {
duration = Helper.secondsToOther(Search.durationToSeconds(duration));
var video_id = song.id;
var video_title = song.snippet.title;
var tags = song.snippet.tags;
var viewCount = 0;
try {
viewCount = song.statistics.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
@@ -101,7 +102,7 @@ var Suggestions = {
}
try {
document.getElementById("suggest-song-html").insertAdjacentHTML("beforeend", List.generateSong({id: video_id, title: video_title, length: length, duration: duration, votes: viewCount, extra: "Views", source: "youtube"}, false, false, false));
document.getElementById("suggest-song-html").insertAdjacentHTML("beforeend", List.generateSong({id: video_id, title: video_title, length: length, duration: duration, votes: viewCount, extra: "Views", source: "youtube", tags:tags}, false, false, false));
} catch(e) {}
}
}