iwara download

Download videos from iwara.tv. NOTE: may need grant download privilege to browser extension like tampermonkey.

11.05.2021 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey 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 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         iwara download
// @name:zh-CN   iwara 下载
// @description          Download videos from iwara.tv. NOTE: may need grant download privilege to browser extension like tampermonkey.
// @description:zh-CN    下载 iwara 视频。 注意:可能需要给 tampermonkey 等插件设置下载权限。
// @namespace    https://sleazyfork.org/zh-CN/scripts/425903-iwara-download
// @version      0.1.1
// @author       oajsdfk
// @match        https://*.iwara.tv/*
//
// @grant        GM_download
// ==/UserScript==

(function() {
  'use strict';

  if (!jQuery) { return; }

  var $ = jQuery.noConflict();

  var view_page = window.location.pathname.startsWith('/videos/')

  function fname(str) {
    return str.replace(/\\/g,'¥')
      .replace(/\//g,'/')
      .replace(/:/g,':')
      .replace(/\*/g,'*')
      .replace(/\?/g,'?')
      .replace(/"/g,'”')
      .replace(/</g,'<')
      .replace(/>/g,'>')
      .replace(/\|/g,'|')
      .replace(/\t/g, ' ')
      .replace(/~/g,'~');
  };

  var download_clicked;
  $('#user-links').append('<input id="download" type="button" value="download">');
  $('#download').on('click', function() {
    let dl = $(this);

    if (view_page) {
      $(dl).val('downloading');
      download();
      return;
    }

    if (!download_clicked) {
      $('.node-video').append('<input type="checkbox" class="dl_chk" checked/>');

      $(dl).val('download selected');

      $('#user-links').append('<span>'+
                              '<input id="sel_dl_all" type="button" value="all">'+
                              '<input id="sel_dl_invert" type="button" value="invert">'+
                              '<input id="sel_dl_none" type="button" value="none">'+
                              '</span>');

      $('#sel_dl_all').on('click', function(e) {
        $('.dl_chk:enabled').each(function() {
          this.checked = true;
        });
      });
      $('#sel_dl_invert').on('click', function(e) {
        $('.dl_chk:enabled').each(function() {
          this.checked = !this.checked;
        });
      });
      $('#sel_dl_none').on('click', function(e) {
        $('.dl_chk:enabled').each(function() {
          this.checked = false;
        });
      });

      download_clicked = 1;
    } else {
      let checked = $('.node-video').has('.dl_chk:checked:enabled');

      if (checked.length === 0) { return; }

      $(dl).val('downloading');

      checked.each((idx, v) => download($(v)));
    }
  });

  function download(video) {
    let like;
    let view;
    let vid;
    let title;
    let user;
    if (!view_page) {
      let t = video.find('.title > a');
      vid = t.attr('href').replace('/videos/', '');
      title = t.text();
      like = video.find('.likes-icon').has('.glyphicon-heart').text().trim();
      view = video.find('.likes-icon').has('.glyphicon-eye-open').text().trim();
      user = video.find('.username').text();
    } else {
      vid = window.location.pathname.replace('/videos/', '');
      title = $('.node-info').find('.title').text();
      let t = $('.node-views').has('.glyphicon-heart').has('.glyphicon-eye-open').text().trim().split(/\s+/);
      like = t[0];
      view = t[1];
      user = $('.node-info').find('.username').text();
    }



    console.log('download:', '♥' + like + ' 👁' + view + ' ' + user + '/' + title + ' [' + vid + ']');

    let filename = fname(user) + '/' + fname(title) + ' [' + vid + ']';

    $.get('/api/video/' + vid, function(res) {
      if (res[0]) {
        console.log(vid, "urls: ", res[0]);
        let t = res[0].mime.split('/');
        let f = filename +'.' + t[t.length-1];

        let url = 'https:'+res[0].uri;
        console.log('downloading file:', f, 'url:', url);

        GM_download({
          url: url,
          name: 'iwara/' + f,
          onload: () => {
            console.log('download suc:', f);

            if (!view_page) {
              let i = video.find('.dl_chk');
              i.attr('disabled', true);
              i.removeClass('dl_chk');
            } else {
              $('#download').enable(false);
            }
          },
          onprogress: (e) => {
            let v = e.loaded/e.total*100;
            console.log('downloading:', f, e, v+'%');
          },
          onerror : (e) => console.error('download failed:', f, e),
          ontimeout  : (e) => console.error('download timeout:', f, e),
          saveAs: false
        });

      } else {
        console.error("no video:", vid);
      }
    }, 'JSON').fail(function(err) {
      console.error("get_url_failed", vid, err);
    });
  }

})();