Recurbate download

Adds a download button for each video on recurbate.com/cc

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Recurbate download
// @version      1.1.4
// @description  Adds a download button for each video on recurbate.com/cc
// @author       razorwax
// @match        https://recu.me/*
// @license MIT
// @namespace https://greasyfork.org/users/724632
// ==/UserScript==
 
function ErrorPrint(errorReason)
{
    var error = "Recurbate Download Error! [reason = " + errorReason + "]";
    console.error(error);
    window.alert(error);
}
 
function DownloadVideo(url)
{
    if (!url)
    {
        ErrorPrint("find_video_src_failure");
        return;
    }
    window.open(url, '_blank');
}
 
function FindSourceFromUnstartedVideo(videoBtn)
{
    // Find token and id
    var token = videoBtn.attr("data-token");
    var id = videoBtn.attr("data-video-id");
    if (token && id)
    {
        // Send video request to server
        var url = "/api/get.php?video="+id+"&token="+token;
        $.get(url, function(data)
        {
            // Find src from video tag in the response
            if (data.includes("<video") && data.includes("src="))
            {
                var src = data.match(/src=".*"/m);
                if (src.length > 0)
                {
                    // Get the source and download it
                    src = src[0];
                    src = src.substring(5, src.length - 1);
                    DownloadVideo(src);
                }
            }
            else
            {
                window.alert("Server blocked request, reason = " + data);
            }
        });
    }
    else
    {
        ErrorPrint("token_and_id_failure");
    }
}
 
function FindSourceFromStartedVideo()
{
    var foundVideo;
    var searchVideos = $("video");
    if (searchVideos.length == 1)
    {
        // Guess this is the video we are looking for
        foundVideo = searchVideos[0];
    }
    else
    {
        // Multiple videos found, search for the correct one
        var videoIdRegex = /video_\d+/;
        for (var video of searchVideos)
        {
            if (video.id.match(videoIdRegex))
            {
                foundVideo = video;
                break;
            }
        }
    }
 
    if (foundVideo)
    {
        var source = foundVideo.src;
        if (!source)
        {
            // Try to find video source by source element
            var sourceElem = $(foundVideo).find("source");
            if (sourceElem && sourceElem.length > 0)
            {
                source = sourceElem[0].src;
            }
        }
        DownloadVideo(source);
    }
    else
    {
        ErrorPrint("find_video_failure");
    }
}
 
function AddDownloadButton(appendToElem)
{
    var downloadBtn = $("<button style=\"margin-left: 10px;\" class=\"btn btn-warning btn-sm\"><b style=\"color:#212528\">Download</b></button>").appendTo(appendToElem);
    downloadBtn.on("click", function()
    {
        // Download button press
        var videoBtns = $("#play_button");
        if (videoBtns.length > 0)
        {
            // Found the unstarted video player, find src from it
            FindSourceFromUnstartedVideo($(videoBtns[0]));
        }
        else
        {
            // Video must have been started
            FindSourceFromStartedVideo();
        }
    });
}
 
// Create download button
$(function ()
{
    var addTo = $("a.bookmark");
    if (addTo.length == 1)
    {
        addTo = addTo.parent();
    }
    else
    {
        addTo = $("div.video-info").children("div");
    }
 
    if (addTo.length > 0)
    {
        AddDownloadButton($(addTo[0]));
    }
    else
    {
        ErrorPrint("add_download_btn_failure");
    }
});