Skip to content

Commit

Permalink
added audio option in userscript and adjustments on client
Browse files Browse the repository at this point in the history
  • Loading branch information
Venipa committed Jul 3, 2019
1 parent b60e25d commit d0b9885
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 67 deletions.
154 changes: 87 additions & 67 deletions CoubDownload-Bridge-Userscript/coub-bridge.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Coub-Bridge
// @namespace https://venipa.net
// @version 0.1.2
// @version 0.1.3
// @description try to take over the world!
// @author Venipa
// @match https://*.coub.com/*
Expand All @@ -10,73 +10,93 @@
// ==/UserScript==

(function() {
// 'use strict';
const downloadButton = function() {
const btn = document.createElement('a');
btn.innerText = "Download Coub";
btn.style.padding = "8px 12px";
btn.style.color = "#fff";
btn.style.background = "#000";
btn.style.lineHeight = 1;
btn.style.fontSize = "0.875rem";
btn.style.alignSelf = 'center';
btn.style.borderRadius = '4px';
btn.style.marginRight = '8px';
return btn;
// 'use strict';
const downloadButton = function() {
const btn = document.createElement('a');
btn.innerText = 'Download';
btn.style.padding = '8px 12px';
btn.style.color = '#fff';
btn.style.background = '#000';
btn.style.lineHeight = 1;
btn.style.fontSize = '0.875rem';
btn.style.alignSelf = 'center';
btn.style.borderRadius = '4px';
btn.style.marginRight = '8px';
return btn;
};
var log = {
debug: function(msg, ...params) {
console.log('[coub-bridge|debug] ', msg, params);
},
tag: function(tag, msg, ...params) {
console.log('[coub-bridge|' + tag + '] ', msg, params);
}
var log = {
debug: function(msg, ...params) {
console.log('[coub-bridge|debug] ', msg, params);
},
tag: function(tag, msg, ...params) {
console.log('[coub-bridge|' + tag + '] ', msg, params);
}
};
log.debug('boot');
const buttonId = 'coubdl-download';
var checkCoubs = function() {
var coubs = document.querySelectorAll('#coubchat .coub[coub-block]:not(.timeline-banner), .coubs-list .coub[coub-block]:not(.timeline-banner), .coub-page > .coub-block-col .coub[coub-block]');
var coubRelated = document.querySelectorAll('.suggests-block-col .suggest__list > .suggest__item');
};
log.debug('boot');
const buttonId = 'coubdl-download';
const buttonAudioId = 'coubdl-audio-download';
var checkCoubs = function() {
var coubs = document.querySelectorAll(
'#coubchat .coub[coub-block]:not(.timeline-banner), .coubs-list .coub[coub-block]:not(.timeline-banner), .coub-page > .coub-block-col .coub[coub-block]'
);
var coubRelated = document.querySelectorAll(
'.suggests-block-col .suggest__list > .suggest__item'
);

if (coubs) {
coubs.forEach(function(x) {
if (!x || !x.querySelector) {
return;
}
var controls = x.querySelector('.description__controls');
if (controls && controls.querySelectorAll && controls.querySelectorAll('#' + buttonId).length === 0) {
var coubId = x.getAttribute('data-permalink');
var downloadBtn = downloadButton();
downloadBtn.id = buttonId;
downloadBtn.href = "coubdl-bridge://" + coubId;
controls.prepend(downloadBtn);
}
});
if (coubs) {
coubs.forEach(function(x) {
if (!x || !x.querySelector) {
return;
}
var controls = x.querySelector('.description__controls');
if (controls && controls.querySelectorAll) {
if (controls.querySelectorAll('#' + buttonId).length === 0) {
let coubId = x.getAttribute('data-permalink');
let downloadBtn = downloadButton();
downloadBtn.id = buttonId;
downloadBtn.href = 'coubdl-bridge://' + coubId;
downloadBtn.innerText = "Video";
controls.prepend(downloadBtn);
}
if (controls.querySelectorAll('#' + buttonAudioId).length === 0) {
let coubId = x.getAttribute('data-permalink');
let downloadBtn = downloadButton();
downloadBtn.id = buttonAudioId;
downloadBtn.innerText = "Audio";
downloadBtn.href = 'coubdl-bridge://' + coubId + '/audio';
controls.prepend(downloadBtn);
}
}
if (coubRelated) {
coubRelated.forEach(function(x) {
if (x && x.querySelectorAll && x.querySelectorAll('#' + buttonId).length === 0) {
var coubId = x.getAttribute('data-permalink');
var downloadBtn = downloadButton();
downloadBtn.id = buttonId;
downloadBtn.href = "coubdl-bridge://" + coubId;
downloadBtn.style.padding = '4px 6px';
downloadBtn.style.position = 'absolute';
downloadBtn.style.top = 0;
downloadBtn.style.right = 0;
downloadBtn.style.marginTop = '8px';
downloadBtn.style.marginRight = '8px';
downloadBtn.style.zIndex = 9999;
x.prepend(downloadBtn);
}
});
});
}
if (coubRelated) {
coubRelated.forEach(function(x) {
if (
x &&
x.querySelectorAll &&
x.querySelectorAll('#' + buttonId).length === 0
) {
var coubId = x.getAttribute('data-permalink');
var downloadBtn = downloadButton();
downloadBtn.id = buttonId;
downloadBtn.href = 'coubdl-bridge://' + coubId;
downloadBtn.style.padding = '4px 6px';
downloadBtn.style.position = 'absolute';
downloadBtn.style.top = 0;
downloadBtn.style.right = 0;
downloadBtn.style.marginTop = '8px';
downloadBtn.style.marginRight = '8px';
downloadBtn.style.zIndex = 9999;
x.prepend(downloadBtn);
}
};
var worker;
var workerFunc = function() {
clearInterval(worker);
checkCoubs();
worker = setInterval(workerFunc, 2500);
};
workerFunc();
})();
});
}
};
var worker;
var workerFunc = function() {
clearInterval(worker);
checkCoubs();
worker = setInterval(workerFunc, 2500);
};
workerFunc();
})();
10 changes: 10 additions & 0 deletions CoubDownload-Bridge/Commands/DownloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand All @@ -30,6 +31,15 @@ public string Execute(DownloadArgs args)
if (CoubId.ToLower().StartsWith("coubdl-bridge"))
{
CoubId = CoubId.Substring("coubdl-bridge://".Length);
var csId = CoubId.Split('/');
if (csId.Length > 1)
{
CoubId = csId.FirstOrDefault();
if (csId.LastOrDefault() == "audio")
{
args.audio = true;
}
}
}
if (CoubId.EndsWith("/"))
{
Expand Down

0 comments on commit d0b9885

Please sign in to comment.