MediaWiki:Common.js/DeadVideos.js

// DeadVideos script by Bobogoobo //IN PROGRESS! A few last bugs to get rid of. $(function {   var catList = [      '', 'Fanmade', 'Non-MLP', 'Other MLP', 'Promotional', 'Show', 'Quote', 'Scene', 'Song', 'International song',      'Equestria Girls international song', 'Season 1 international song', 'Season 2 international song',      'Season 3 international song', 'Season 4 international song'      ],      videoList = {}, noId = [], nonYT = [], pending = catList.length;

$('#mw-content-text p').html('UNDER CONSTRUCTION! This page will display any videos that no longer exist at the source. You must be logged in to a Google account for it to work properly. Also, this may not work on older versions of Internet Explorer. Note that the YouTube API which this script uses has a daily quota, though it is not likely to be reached. Please report any bugs or suggestions here. If results do not appear after a long time, it may have crashed; check your browser console for errors. ');

$.each(catList, function(index, value) {       function getList(cmcontinue) {            $.getJSON('/api.php?action=query&prop=imageinfo&iiprop=metadata&generator=categorymembers&gcmtitle=Category:' + value + (value ? ' ' : '') + 'videos' + '&gcmprop=title&gcmtype=file&gcmlimit=max&format=json&gcmcontinue=' + cmcontinue, function(data) { if (data.query) { $.each(data.query.pages, function(key, value) {                       $.each(value.imageinfo[0].metadata, function(mdindex, mdvalue) { if (mdvalue.name === 'videoId') { videoList[mdvalue.value] = value.title; return false; } else if (mdvalue.name === 'provider' && mdvalue.value !== 'youtube') { nonYT.push(value.title); return false; } else if (mdindex == value.imageinfo[0].metadata.length - 1) { noId.push(value.title); }                       });                    });                }

if (data['query-continue']) { getList(data['query-continue'].categorymembers.gcmcontinue); } else { pending -= 1; if (pending === 0) { stepTwo; }               }            });        }

getList(''); });

function stepTwo { var IDlists =, keys = Object.keys(videoList), counter = 0, pending = 0;

for (var i = 0; i < keys.length; i++) { IDlists[IDlists.length - 1].push(keys[i]); counter += 1; if (counter === 50) { IDlists.push([]); counter = 0; }       }

pending = IDlists.length; $.each(IDlists, function(index, value) {           $.getJSON('https://www.googleapis.com/youtube/v3/videos?part=id&id=' + value.join(',') + '&key=AIzaSyB9m40QxbD9iq9zM9_eXiBfmwJ3dZrvdgg', function(data) { $.each(data.items, function(index, value) {                   delete videoList[value.id];                }); pending -= 1;

if (pending === 0) { results; }           });        });    }

function results {

if (! $.isEmptyObject(videoList)) { $('#dv-results').append(' Dead videos '); $.each(videoList, function(key, value) {               $('#dv-results-1').append('' + value + ' (YTID: ' + key + ')');            }); }

if (noId.length) { $('#dv-results').append(' Videos with no ID '); $.each(noId, function(index, value) {               $('#dv-results-2').append('' + value + '');            }); }

if (nonYT.length) { $('#dv-results').append(' Non-YouTube videos (check manually) '); $.each(nonYT, function(index, value) {               $('#dv-results-3').append('<a href="/wiki/' + encodeURIComponent(value.replace(/ /g, '_')) +                  '" title="' + value + '">' + value + '</a></li>');            }); }   } });