1

我最近遇到了“TubeMP3”——一个一键将 YouTube 视频转换为 MP3 的脚本。

我想要做的是让 iframe 在后台转换视频(不显示 iframe,因为它有广告),然后在转换过程完成后,将下载按钮附加到正文。谁能指出我正确的方向?我被困住了。

这是我的基本 html:

<!DOCTYPE html>
<html>
<body>

<script src="URL for the miniplayer"></script>
<script src="URL to jquery 1.9.1"></script>

<!-- start document ready function -->
<script> 
$(document).ready(function() { 
applyplayer(); applysearch(); applysearchBox(); applybutton() });
</script>

<!-- start input -->
<input type="text" placeholder="Paste YouTube URL..." size="80" id="textURL"></input>

<br>

<!-- start result -->
<div class="tubemp3result" id="Searchtarget" ></div>

<!-- start button -->
<button onclick="convertByform()">Convert!</button>

<!-- start bottom result -->
<div class="tubemp3" data-type="small" data-play="auto">
</div>

现在这是“miniplayer.js”文件的来源(包含 convertByform() 函数):

function applyplayer(){

var TubeElement = $('.tubemp3');

if(typeof TubeElement != 'undefined'){

    var hitAr = 0;

    while(hitAr < TubeElement.length){

        var tubes = $(TubeElement[hitAr]);

        var tubUrl = $(TubeElement[hitAr]).html();

        var type = tubes.attr('data-type');

        var play = tubes.attr('data-autoplay');

        var width = tubes.attr('data-width');

            var tubIdmatch = /watch\?v=(.*)/;

        var TubeID = tubIdmatch.exec(tubUrl);   

        TubeID = (typeof TubeID != 'undefined' && typeof TubeID[1] !='undefined')? TubeID[1]:'';

        if(

        typeof tubes != 'undefined' &&

        typeof tubUrl != 'undefined' &&

        typeof type != 'undefined' &&

        typeof play != 'undefined' &&

        typeof TubeID != 'undefined' &&

        typeof width != 'undefined' 

        )

        {

            tubes.removeAttr('data-type');

            tubes.removeAttr('data-autoplay');

            tubes.removeAttr('data-width');

            if(type =='small'){

                var height = 40;

                }else{

                var height = type.split('x');

                height = height[1];

            }

            widhtElem = Number(width) + 40;



            var player = '<div style="width:'+widhtElem+'px;margin:0px auto;"><iframe frameborder="0"'+

                        'scrolling="no" width="'+width+'" height="'+height+'" '+

                        'src="http://tubemp3script.com/player/playerembed.html#'+tubUrl+'|'+type+'|'+play+'"></iframe>'+

                        '<a onclick="getConvert(\''+TubeID+'\')" href="#"><img src="http://tubemp3script.com/player/download.png" /></div>';

            $(tubes).html(player);

        }



            hitAr++;

    }

}

}

function jstubeCallback(Djson,key){

var result =  Djson['data']['items'];

if(typeof result=='object'){

    $(result).each(function(){

    var title = this['title'];

    var url =  'http://www.youtube.com/watch?v='+this['id'];

    var html = '<p><span class="tubeh2">'+title+'<span></p>'+

        '<div class="tubemp3" data-type="small" data-width="400" data-autoplay="none">'+

        ''+url+''+

        '</div>';

    $($('.tubemp3result')[key]).append(html);

    });

}



applyplayer();
}

function searchSTUB(title,key){

var max = 4;

var url = 'http://gdata.youtube.com/feeds/api/videos';

var datareq = 'q='+escape(title)+'&max-results=4&alt=jsonc&v=2';

$.ajax({

    url : url,

    data : datareq,

    type : 'GET',

     dataType: 'json',

    success    : function(data){

                jstubeCallback(data,key);

            }

});

}

function applysearch(){

var mytubeelement = $('.tubemp3result');

if(typeof mytubeelement != 'undefined'){

mytubeelement.each(function(key,value){

var keyword = $(this).attr('data-keyword');

    if(typeof keyword != 'undefined'){

    $(this).removeAttr('data-keyword');

        searchSTUB(keyword, key);

    }   

});

}



}

function applysearchBox(){

$('#TubeSearchBox').submit(function(){

var keyword = $('#TubeSearchBox').find('input[name=s]').val();

var target = $('#TubeSearchBox').attr('action');

$(''+target+'').html('');

$(''+target+'').attr('data-keyword',keyword);

applysearch();

return false;

});

}

function closeFrame(){

$('#frameconvert').remove();

}

function getConvert(tubeid){

$('#frameconvert').remove();

var myhtml = '<div align="center" id="frameconvert" style="background:#ccc;z-index:1000;position:fixed;top:0px;width:500px;height: 190px">' +

        '<iframe src="http://tubemp3script.com/work.php?v='+tubeid+'" width="100%" height="190" style="overflow:hidden;" frameborder="0"></iframe>'+

        '<button style="position:absolute; bottom:0px; right:0px; height:25px;font-size:10px;" onclick="closeFrame()">close</button></div>';

        $('body').append(myhtml);

}

function applybutton(){

$('.DlTubescript').each(function(){

var checktube = $(this).attr('href');

    var getID = /v=(.*)/;

    var tUbid = getID.exec(checktube);

    if(tUbid != null && typeof  tUbid[1] != 'undefined' ){

        $(this).attr('href','#');

        $(this).attr('target','_self');

        $(this).click(function(){

            getConvert(tUbid[1]);

        });

    }

});

}

function convertByform(){

hit = 0;

var anuanu = $('#textURL').val();

var getID = /v=(.*)/;

var tUbid = getID.exec(anuanu);

if(typeof  tUbid[1] != 'undefined'){

getConvert(tUbid[1]);

}

}
4

0 回答 0