Skip to content

Instantly share code, notes, and snippets.

@ciencia
Created December 13, 2023 19:13
Show Gist options
  • Save ciencia/2ac39db0cd940dfa512484502e764a77 to your computer and use it in GitHub Desktop.
Save ciencia/2ac39db0cd940dfa512484502e764a77 to your computer and use it in GitHub Desktop.
Extract youtube videos from wikia
/*
Execute in the browser's console
Extracts all videos from youtube in a json. The object is printed in the console, where you can "copy as object".
You may need to modify the category title
*/
(function() {
var _videoCollection = {},
_init = function() {
_fetchVideos();
},
_fetchVideos = function(contParams) {
var params = {
action: 'query',
format: 'json',
prop: 'imageinfo',
generator: 'categorymembers',
iiprop: 'metadata',
gcmtitle: 'Category:Videos',
formatversion: 2,
};
if (contParams) {
$.extend(params, contParams);
}
$.getJSON(mw.config.get('wgScriptPath') + '/api.php', params, _getResult);
},
_getResult = function(data) {
_parseResults(data);
if (data['continue']) {
_fetchVideos(data['continue']);
} else {
_finish();
}
},
_parseResults = function(data) {
var videoId;
for (var pp of data.query.pages) {
if (pp.imageinfo && pp.imageinfo[0]) {
videoId = null;
for (var mm of pp.imageinfo[0].metadata) {
if (mm.name == 'videoId') {
videoId = mm.value;
}
if (mm.name == 'provider' && mm.value != 'youtube') {
// Si no es youtube, skip
videoId = null;
break;
}
}
if (videoId) {
_videoCollection[pp.title] = videoId;
}
}
}
},
_finish = function() {
console.log(_videoCollection);
};
_init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment