Skip to content

Commit

Permalink
128 get most popular video (#156)
Browse files Browse the repository at this point in the history
* add most popular videos

* most popular video basic search done

* advanced most popular video done

* tooltip location

* changelog

* typo
  • Loading branch information
longshuicy authored Jun 3, 2024
1 parent 2e07af7 commit 75e8e98
Show file tree
Hide file tree
Showing 11 changed files with 666 additions and 461 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- YouTube most popular videos [#128](https://github.com/ncsa/standalone-smm-smile/issues/128)

### Fixed
- YouTube preview grid not aligned properly; and turn off geolocation filter for channel and playlist [#153](https://github.com/ncsa/standalone-smm-smile/issues/153)

Expand Down
3 changes: 3 additions & 0 deletions www/public/bootstrap/js/customized/history_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ $.getScript("bootstrap/js/customized/view_helperFunc.js", function(){
else if (key1 === 'youtube-Search-Playlist') {
var secondLevel = 'YouTube Playlists';
}
else if (key1 === 'youtube-Most-Popular') {
var secondLevel = 'YouTube Most Popular Videos';
}
else if (key1 === 'networkx') {
var secondLevel = 'Python NetworkX';
}
Expand Down
1 change: 1 addition & 0 deletions www/public/bootstrap/js/customized/query_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function authorize(platform){
$("#social-media option[value='queryYoutube']").removeAttr('disabled');
$("#social-media option[value='queryYoutubeChannel']").removeAttr('disabled');
$("#social-media option[value='queryYoutubePlaylist']").removeAttr('disabled');
$("#social-media option[value='youtubeMostPopular']").removeAttr('disabled');
}
}

Expand Down
25 changes: 13 additions & 12 deletions www/public/bootstrap/js/customized/query_formValid.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,19 @@ function formValid(searchID){
// https://developer.twitter.com/en/docs/tweets/search/guides/standard-operators
var regx = /^[\":?)(#@A-Za-z0-9_ _+-_&_|]+$/;
if ($("#social-media option:selected").val() === ''){

$("#modal-message").append(`<h4>Please select a platform!</h4>`);
$("#alert").modal('show');
$("#social-media").focus();
return false

}else if (!regx.test($("#searchbox").val()) || $("#searchbox").val()>=500){

return false;
} else if ($("#social-media option:selected").val() !== 'youtubeMostPopular' &&
(!regx.test($("#searchbox").val()) || $("#searchbox").val().length >= 500)) {
$("#modal-message").append(`<h4>Please type in search keyword in the form of <i>English words, number, operators,
and/or combinations</i> of them!<br><b>Length shouldn't exceed 500 characters!</b></h4>`);
and/or combinations</i> of them!<br><b>Length shouldn't exceed 500 characters!</b></h4>`);
$("#alert").modal('show');
$("#searchbox").focus();
return false

return false;
}

// extra search for advanced
if (searchID === '#input'){
if ($("#social-media option:selected").val() === 'queryTweet'){
Expand Down Expand Up @@ -177,9 +174,13 @@ function formValid(searchID){
$("#alert").modal('show');
return false
}
}else if ($("#social-media option:selected").val() === 'queryYoutube'){
// TODO implement form check for advanced search
return true;
}else if ($("#social-media option:selected").val() === 'queryYoutube' || $("#social-media option:selected").val() === 'queryYoutubePlaylist' || $("#social-media option:selected").val() === 'queryYoutubeChannel'){
if ($("#ytDateRange").is(':checked') &&
($("#publishedAfter").val() === '' || $("#publishedBefore").val() === '' || $("#publishedAfter").val()>$("#publishedBefore").val())){
$("#modal-message").append(`<h4>Please sepecify a date range, and the publishing after date cannot be later than the publishing before date!</h4>`);
$("#alert").modal('show');
return false
}
}
}

Expand Down
98 changes: 89 additions & 9 deletions www/public/bootstrap/js/customized/query_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function init(){
youtubeSearch:{},
youtubeSearchChannel:{},
youtubeSearchPlaylist:{},
youtubeMostPopular:{},
};

// initialization
Expand Down Expand Up @@ -66,7 +67,7 @@ function init(){

// customize advance dropdown
$('#dropdownButton').on('click',function(){
if ($("#searchbox").val() !== '' && $("#searchbox").val() !== undefined){
if (($("#searchbox").val() !== '' && $("#searchbox").val() !== undefined) || queryTerm === "youtubeMostPopular"){
if (queryTerm !== "queryTweetV2"){
$(this).parent().toggleClass('open');
if ($(this).parent().attr('class') === 'dropdown dropdown-lg open'){
Expand All @@ -79,7 +80,7 @@ function init(){
}

// initialize the advanced panel
// escape doule quotation mark
// escape double quotation mark
var keyword = $("#searchbox").val().replace(/[\"]+/g, `\\"`);

parameters['tweet']['q:'] = keyword;
Expand Down Expand Up @@ -147,9 +148,6 @@ function init(){
"\n\t\t\t\tstandard_thumbnails_url\n\t\t\t\tstandard_thumbnails_width\n\t\t\t\tstandard_thumbnails_height\n\t\t\t\tmaxres_thumbnails_url" +
"\n\t\t\t\tmaxres_thumbnails_width\n\t\t\t\thigh_thumbnails_height\n\t\t\t\tchannelTitle\n\t\t\t\tliveBroadcastContent\n\t\t\t}";

Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);

parameters['youtubeSearchChannel']['q:'] = keyword;
parameters['youtubeSearchChannel']['type:'] = "channel";
parameters['youtubeSearchChannel']['order:'] = "relevance";
Expand All @@ -161,9 +159,6 @@ function init(){
"\n\t\t\t\tstandard_thumbnails_url\n\t\t\t\tstandard_thumbnails_width\n\t\t\t\tstandard_thumbnails_height\n\t\t\t\tmaxres_thumbnails_url" +
"\n\t\t\t\tmaxres_thumbnails_width\n\t\t\t\thigh_thumbnails_height\n\t\t\t\tchannelTitle\n\t\t\t\tliveBroadcastContent\n\t\t\t}";

Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);

parameters['youtubeSearchPlaylist']['q:'] = keyword;
parameters['youtubeSearchPlaylist']['type:'] = "playlist";
parameters['youtubeSearchPlaylist']['order:'] = "relevance";
Expand All @@ -175,8 +170,34 @@ function init(){
"\n\t\t\t\tstandard_thumbnails_url\n\t\t\t\tstandard_thumbnails_width\n\t\t\t\tstandard_thumbnails_height\n\t\t\t\tmaxres_thumbnails_url" +
"\n\t\t\t\tmaxres_thumbnails_width\n\t\t\t\thigh_thumbnails_height\n\t\t\t\tchannelTitle\n\t\t\t\tliveBroadcastContent\n\t\t\t}";

parameters['youtubeMostPopular']['regionCode:'] = keyword;
parameters['youtubeMostPopular']['chart:'] = "mostPopular";
parameters['youtubeMostPopular']['fields'] = "\n\t\t\tkind\n\t\t\tetag\n\t\t\tid\n\t\t\tsnippet{\n\t\t\t\t" +
"publishedAt\n\t\t\t\tchannelId\n\t\t\t\ttitle\n\t\t\t\tdescription\n\t\t\t\tdefault_thumbnails_url" +
"\n\t\t\t\tdefault_thumbnails_width\n\t\t\t\tdefault_thumbnails_height\n\t\t\t\tmedium_thumbnails_url" +
"\n\t\t\t\tmedium_thumbnails_width\n\t\t\t\tmedium_thumbnails_height\n\t\t\t\thigh_thumbnails_url" +
"\n\t\t\t\thigh_thumbnails_width\n\t\t\t\thigh_thumbnails_height\n\t\t\t\tstandard_thumbnails_url" +
"\n\t\t\t\tstandard_thumbnails_width\n\t\t\t\tstandard_thumbnails_height\n\t\t\t\tmaxres_thumbnails_url" +
"\n\t\t\t\tmaxres_thumbnails_width\n\t\t\t\tmaxres_thumbnails_height\n\t\t\t\tchannelTitle\n\t\t\t\t" +
"tags\n\t\t\t\tcategoryId\n\t\t\t\tliveBroadcastContent\n\t\t\t\tdefaultLanguage\n\t\t\t\t" +
"localized_title\n\t\t\t\tlocalized_description\n\t\t\t\tlocalized_description\n\t\t\t\t" +
"defaultAudioLanguage\n\t\t\t}\n\t\t\tcontentDetails{\n\t\t\t\tduration\n\t\t\t\tdimension" +
"\n\t\t\t\tdefinition\n\t\t\t\tcaption\n\t\t\t\tlicensedContent\n\t\t\t\tregionRestriction_allowed" +
"\n\t\t\t\tregionRestriction_blocked\n\t\t\t\tprojection\n\t\t\t\thasCustomThumbnail\n\t\t\t}\n\t\t\t" +
"status{\n\t\t\t\tuploadStatus\n\t\t\t\tfailureReason\n\t\t\t\trejectionReason\n\t\t\t\tprivacyStatus" +
"\n\t\t\t\tpublishAt\n\t\t\t\tlicense\n\t\t\t\tembeddable\n\t\t\t\tpublicStatsViewable\n\t\t\t\t" +
"madeForKids\n\t\t\t\tselfDeclaredMadeForKids\n\t\t\t}\n\t\t\tstatistics{\n\t\t\t\tviewCount" +
"\n\t\t\t\tlikeCount\n\t\t\t\tdislikeCount\n\t\t\t\tfavoriteCount\n\t\t\t\tcommentCount\n\t\t\t}" +
"\n\t\t\tplayer{\n\t\t\t\tembedHtml\n\t\t\t\tembedHeight\n\t\t\t\tembedWidth\n\t\t\t}\n\t\t\t" +
"topicDetails{\n\t\t\t\ttopicIds\n\t\t\t\trelevantTopicIds\n\t\t\t\ttopicCategories\n\t\t\t}" +
"\n\t\t\trecordingDetails{\n\t\t\t\trecordingDate\n\t\t\t}\n\t\t\tliveStreamingDetails{\n\t\t\t\t" +
"actualStartTime\n\t\t\t\tactualEndTime\n\t\t\t\tscheduledStartTime\n\t\t\t\tscheduledEndTime" +
"\n\t\t\t\tconcurrentViewers\n\t\t\t\tactiveLiveChatId\n\t\t\t}"

Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);


}
else {
$("#modal-message").append(`<h4>We currently don't support advanced settings for this search function.</h4>`);
Expand Down Expand Up @@ -224,6 +245,7 @@ function init(){
$(".youtube-search").hide();
$(".youtube-search-playlist").hide();
$(".youtube-search-channel").hide();
$(".youtube-most-popular").hide();

$(".form-group.geocode").hide();
$(".form-group.dateRange").hide();
Expand Down Expand Up @@ -314,6 +336,18 @@ function init(){
.tooltip('fixTitle')
.tooltip('show');
}
else if (queryTerm === 'youtubeMostPopular'){
$(".youtube-most-popular").show();
$("#searchbox").attr("placeholder","Enter region code or leave blank for worldwide videos...");

// tooltip to show region code rules
$("boolean").attr('data-original-title',
"You can find the region code information in the ISO 3166-2 standard. For more details, please refer to the " +
"<a href='https://en.wikipedia.org/wiki/ISO_3166-2' target='_blank'>" +
"ISO 3166-2 Wikipedia page</a>.")
.tooltip('fixTitle')
.tooltip('show');
}

Query = updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);
Expand Down Expand Up @@ -403,6 +437,7 @@ function init(){
parameters['youtubeSearch']['q:'] = keyword;
parameters['youtubeSearchChannel']['q:'] = keyword;
parameters['youtubeSearchPlaylist']['q:'] = keyword;
parameters['youtubeMostPopular']['regionCode:'] = keyword;

Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);
Expand All @@ -412,6 +447,25 @@ function init(){
$(this).siblings(".prompt").show();
});

// Update keywords
$("#searchbox").change(function() {
var keyword = $("#searchbox").val().replace(/[\"]+/g, `\\"`);
parameters['tweet']['q:'] = keyword;
parameters['twtTimeline']['screen_name:'] = keyword;
parameters['tweetV2']['q:'] = keyword;
parameters['rdSearch']['query:'] = keyword;
parameters['rdPost']['subredditName:']= keyword;
parameters['rdComment']['subredditName:'] = keyword;
parameters['psPost']['q:'] = keyword;
parameters['psComment']['q:'] = keyword;
parameters['youtubeSearch']['q:'] = keyword;
parameters['youtubeSearchChannel']['q:'] = keyword;
parameters['youtubeSearchPlaylist']['q:'] = keyword;
parameters['youtubeMostPopular']['regionCode:'] = keyword;
Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);
})

/*---------------------------------------------query tweet ------------------------------------------------------------------------*/
// toggle date range checkbox
$("#dateRange").change(function(){
Expand Down Expand Up @@ -1018,6 +1072,27 @@ function init(){

});

/*---------------------------------------------- Youtube Most popular---------------------------------------*/
$("#youtube-most-popular-count").change(function(){
Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);
});

// localized language
$("#ytHl").change(function(){
parameters['youtubeMostPopular']['hl:'] = $(this).val();
Query =updateString(queryTerm,parameters);
$("#input").val(`{\n\n` + Query +`\n\n}`);
});

// video category
$("#ytVideoCategoryId").change(function () {
parameters['youtubeMostPopular']['videoCategoryId:'] = $(this).val();
Query = updateString(queryTerm, parameters);
$("#input").val(`{\n\n` + Query + `\n\n}`);
});


/*----------------------set intervals--------------------------------------------*/
$('input[name=histogram-interval]').change(function(){
setHitogramInterval($("input[name=histogram-interval]:checked").val());
Expand Down Expand Up @@ -1090,6 +1165,9 @@ function updateString(queryTerm, parameters){
else if (queryTerm === 'queryYoutubePlaylist'){
query = `\tyoutube{\n\t\tsearch(${constructQuery(parameters.youtubeSearchPlaylist)}\n\t\t}\n\t}`;
}
else if (queryTerm === 'youtubeMostPopular'){
query = `\tyoutube{\n\t\tvideos(${constructQuery(parameters.youtubeMostPopular)}\n\t\t}\n\t}`;
}

return query;
}
Expand Down Expand Up @@ -1162,7 +1240,9 @@ function setHitogramInterval(freq){
prefix = 'youtube-Search-Channel';
}else if (queryTerm === 'queryYoutubePlaylist'){
prefix = 'youtube-Search-Playlist';
}
}else if (queryTerm === 'youtubeMostPopular'){
prefix = 'youtube-Most-Popular';
}

if (prefix === undefined || filename === '' || filename === undefined){
$("#modal-message").append(`<h4>Incomplete information for histogram. Please make sure you have specified a data source, as well as retrieved data first.</h4>`);
Expand Down
Loading

0 comments on commit 75e8e98

Please sign in to comment.