Skip to content

Instantly share code, notes, and snippets.

@rndD
Created September 21, 2012 10:05
Show Gist options
  • Save rndD/3760734 to your computer and use it in GitHub Desktop.
Save rndD/3760734 to your computer and use it in GitHub Desktop.
Userscript для собирание информации о видео в vk.com
// ==UserScript==
// @name VK video Data miner(bagulnik)
// @author boyo
// @description Жутко баджу и беру информацию о видео вконтакте, тестировался только в хроме
// @match http://vk.com/*
// ==/UserScript==
// Usage: добавь в браузер, зайди в видеозаписи на vk.com, набери в поиске запрос и смело нажимай "багульник вперед".
function addJQuery(callback) {
//выходим если это айфрейм
if (window.top != window.top) return;
var script = document.createElement("script");
script.setAttribute("src", "//code.jquery.com/jquery-latest.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
var allVideosLoaded = false;
var goButton = $("<button type = 'button' style = 'position:fixed; top:0px; right:0px;'>Багульник вперед!!!</button>")
.appendTo("body")
.on("mouseup", searchVideo);
var videoArray;
var currentVideo = 0;
var isPused = false;
function searchVideo(){
window.videoview.showVideo = function(title, html, js, desc, info, controlsLine, opt) {
var interval = setInterval(function(){
if (mvcur.mvControlsLine){
clearInterval(interval);
extend(cur.lang, opt.lang);
mvcur.mvData = opt.mvData;
mvcur.videoRaw = opt.mvData.videoRaw;
if (!mvcur.mvContent) {
mvcur.mvContent = ge('mv_content');
}
mvcur.mvContent.innerHTML = html;
if (mvcur.mvWide) {
mvcur.mvWide.innerHTML = desc;
}
if (mvcur.mvNarrow) {
mvcur.mvNarrow.innerHTML = info;
}
mvcur.mvControlsLine.innerHTML = controlsLine;
mvcur.finished = false;
hide(mvcur.mvLoader);
if (js) {
eval('(function(){' + js + '})()');
}
if (opt['taggedInfo']) {
var tagInfo = ge('mv_approve');
tagInfo.innerHTML = opt['taggedInfo'];
show(tagInfo);
}
videoview.updateSize();
mvcur.changeCanvasSize = function() {
videoview.updateSize();
window.checkRBoxes && checkRBoxes();
};
if (mvcur.minimized) {
videoview.minimizePlayer();
}
var titleWidth = (mvcur.minimized) ? mvcur.minSize.wrap.w : false;
videoview.setTitle(titleWidth);
if (mvcur.statusVideo) {
var statusCont = ge('like_count' + mvcur.mvData.videoRaw);
if (statusCont) {
var tt = statusCont.parentNode.tt;
if (tt && tt.container) {
re(tt.container)
//re(tt.el);
}
if (statusCont.parentNode.tt) {
delete statusCont.parentNode.tt;
}
}
}
if (opt.showInfo && !mvcur.minimized) {
addClass(mvcur.mvControlsLine, 'mv_controls_shown');
show(ge('mv_controls'));
}
show('mv_content');
window.updateWndVScroll && updateWndVScroll();
}
}, 100);
}
$(document).keydown(function(event){
if(event.which == 113){
isPused = !isPused;
if (!isPused){
collectionOfInformation();
}
}
});
var videosCount = $('a.video_name').length;
var repeatedValue = 0;
var interval = setInterval(function(){
if (videosCount == $('a.video_name').length)
repeatedValue++;
else
repeatedValue = 0;
videosCount = $('a.video_name').length;
// console.log("Было найдено: " + videosCount);
$("html, body").scrollTop($(document).height());
if (repeatedValue == 30){
clearInterval(interval);
console.log("Всего найдено " + videosCount + " видео");
videoArray = $('a.video_name');
console.log(videoArray);
collectionOfInformation();
}
}, 100);
}
function collectionOfInformation(){
if(isPused)
return;
if(videoArray[currentVideo]){
$(videoArray[currentVideo]).click();
var expectationCounter = 0;
var interval = setInterval(function(){
expectationCounter++;
if ($("div.mv_min_title").text() != ""){
if($("#mv_comments_header").text() != ""){
var commentsNumber = Number($("#mv_comments_header").text().match(/\d+/g)[0])
+ $("div.mv_comment").length
}
else
commentsNumber = $("div.mv_comment").length;
var likesNumber = $("#mv_like_count").text();
if (likesNumber == "")
likesNumber = 0;
else
likesNumber = Number(likesNumber);
var obj = {
name: $("div.mv_min_title").text(),
link: window.location.href,
viewsNumber: Number($("div.mv_num_views").text().split(" ")[0]),
likesNumber: likesNumber,
commentsNumber: commentsNumber,
date: $("#mv_date_wrap").text().replace("Добавлена ", ""),
length: $(videoArray[currentVideo]).parent().find(".video_duration").text()
};
console.log(currentVideo + " / " + videoArray.length);
console.log(videoArray[currentVideo]);
console.log(obj);
// if (videoArray[currentVideo - 1]){
// if (obj.date == videoArray[currentVideo - 1].date){
// isPused = true;
// }
// else{
// $("div.mv_top_close").click();
// var timeout = setTimeout(function(){
// clearTimeout(timeout);
// collectionOfInformation();
// }, 50);
// }
// }
// else{
$("div.mv_top_close").click();
var timeout = setInterval(function(){
if ($("#mv_layer_wrap").css("display") == "none"){
clearTimeout(timeout);
collectionOfInformation();
}
}, 50);
// }
videoArray[currentVideo] = obj;
currentVideo++;
clearInterval(interval);
}
if($("#system_msg").text().indexOf("Ошибка доступа") != -1){
$("#system_msg").text("");
var obj = {
name: "Ошибка доступа",
link: window.location.href,
viewsNumber: "-",
likesNumber: "-",
commentsNumber: "-",
date: "-",
length: "-"
};
console.log(currentVideo + " / " + videoArray.length + " Ошибка доступа, пропускаю");
console.log(videoArray[currentVideo]);
console.log(obj);
videoArray[currentVideo] = obj;
currentVideo++;
clearInterval(interval);
$("div.mv_top_close").click();
var timeout = setTimeout(function(){
clearTimeout(timeout);
collectionOfInformation();
}, 50);
}
if (expectationCounter == 50){
expectationCounter = 0;
$("#system_msg").text("");
var obj = {
name: "Видео грузиться слишком долго",
link: window.location.href,
viewsNumber: "-",
likesNumber: "-",
commentsNumber: "-",
date: "-",
length: "-"
};
console.log(currentVideo + " / " + videoArray.length + " Видео грузиться слишком долго, пропускаю");
console.log(videoArray[currentVideo]);
console.log(obj);
videoArray[currentVideo] = obj;
currentVideo++;
clearInterval(interval);
$("div.mv_top_close").click();
var timeout = setTimeout(function(){
clearTimeout(timeout);
collectionOfInformation();
}, 50);
}
}, 50);
}
else{
console.log("Все видео обработанно");
// console.log(videoArray);
currentVideo = 0;
createTable(videoArray);
}
}
function createTable(videoArray){
var container = $("<div></div>")
.appendTo("body")
.css("position", "fixed")
.css("overflow", "scroll")
.css("z-index", "99")
.css("background", "white")
.css("border", "3px solid black")
.css("width", "100%")
.css("height", "100%")
.css("top", "0px")
.css("left", "0px");
var buttonClose = $("<button type = 'button'>Close</button>")
.appendTo(container)
.on("mousedown", function(){
container.remove();
});
var table = $("<table><tr><td>Имя</td><td>Ссылка</td><td>Просмотры</td><td>Лайки</td><td>Комменты</td><td>Дата</td><td>Длительность</td></tr></table>")
.appendTo(container);
for (var i = 0; i < videoArray.length; i++) {
var tr = $("<tr></tr>")
.appendTo(table);
for (var j in videoArray[i]) {
var td = $("<td></td>")
.text(videoArray[i][j])
.appendTo(tr);
}
}
}
//console.log(1);
//alert("There are " + $('a').length + " links on this page.");
}
// load jQuery and execute the main function
addJQuery(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment