Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Add download all button #110

Open
wilyarti opened this issue Jun 3, 2019 · 5 comments
Open

Add download all button #110

wilyarti opened this issue Jun 3, 2019 · 5 comments

Comments

@wilyarti
Copy link

wilyarti commented Jun 3, 2019

I just used jQuery and a regex function to download all videos. I'm too lazy to click on each video.

It's probably a horrible idea but here goes:

// regex function for jQuery - https://j11y.io/javascript/regex-selector-for-jquery/
jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ? 
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}
// find all low quality links and click on them.
$(':regex(title, Audio file.*)').next().each( function(index, element) {
    element.click();
});

There is probably a better way than this and it relies on jQuery. But it seems to work fine.

@HeavyMavi
Copy link

would you please tell me how to get this to run, I'm still noob

@wilyarti
Copy link
Author

Yeah sure.

First open up the console on your browser (Ctrl + Shift + C).
Paste these lines until they do not show an error (this loads jQuery and creates the regex function):

var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();

jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ? 
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}

Then the rest of the code should run:

// find all low quality links and click on them.
$(':regex(title, Audio file.*)').next().each( function(index, element) {
    element.click();
});

There is a much better way I'm sure. But I was too lazy to go through the code to see how it works.

@mhewedy
Copy link
Owner

mhewedy commented Jun 16, 2019

I just used jQuery and a regex function to download all videos. I'm too lazy to click on each video.

It's probably a horrible idea but here goes:

// regex function for jQuery - https://j11y.io/javascript/regex-selector-for-jquery/
jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ? 
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}
// find all low quality links and click on them.
$(':regex(title, Audio file.*)').next().each( function(index, element) {
    element.click();
});

There is probably a better way than this and it relies on jQuery. But it seems to work fine.

Thanks for sharing this information

@Porkechebure
Copy link

Porkechebure commented Oct 20, 2019

I've tried to make it easier to read and added a delay (as sometimes I found a lot of videos and it started downloading like 300 videos one after the other at full speed and chrome was crashing under the huge amount of total downloads.

Now to the code

First add jquery as shown above:
var jq = document.createElement('script'); jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";

wait for it to load and
document.getElementsByTagName('head')[0].appendChild(jq); jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";

then
jQuery.noConflict();

This works and is tested:

add this method in console:

function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
then add this function (modify title as you need and 10000 with the sleep milliseconds you need)

async function downloadvideos() { var links = jQuery("a[title*='Video file with width']:last-child"); var i; for (i = 0; i < links.length; i++) { await sleep(10000); links[i].click(); } }

then launch

downloadvideos();

If you want to download a particular quality try

`jQuery("a[title*='Video file with width:']:nth-child(6)")

where at the place of 6 you put the desired quality (1 audio, 6 is the highest)

I also tried to do a one liner with jquery but it seems that setTimeout has big troubles with .each of jquery.....

I give you code, someone might want to fix it or to play with it with the aforementioned sleep function and maybe it works (replace 1000 and the selector with what you need);

function download(index, element) {setTimeout( function() {console.log(1000*index)}, (1000*index))};
and
jQuery("a[title*='Video file with width: 960'").each(function(index, element) { download(index, element);});

@Fllorent0D
Copy link

If you want a jQuery less version that downloads the highest quality.

document.querySelectorAll('a[title^="Audio file"]').forEach(node => {
    let sibling = node;
    while (sibling.nextSibling) sibling = sibling.nextSibling;
    sibling.click()
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants