Note that there are some explanatory texts on larger screens.

plurals
  1. POTubeMP3 jQuery/JavaScript
    text
    copied!<p>I recently came across "TubeMP3" - a script that converts YouTube videos to MP3's in one button.</p> <p>What I want to do is have the iframe convert the video in the background (not show the iframe because it has ads), then when the conversion process is complete, append a download button to the body. Can anyone point me in the right direction? I'm stuck.</p> <p>Here's my BASIC html:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;script src="URL for the miniplayer"&gt;&lt;/script&gt; &lt;script src="URL to jquery 1.9.1"&gt;&lt;/script&gt; &lt;!-- start document ready function --&gt; &lt;script&gt; $(document).ready(function() { applyplayer(); applysearch(); applysearchBox(); applybutton() }); &lt;/script&gt; &lt;!-- start input --&gt; &lt;input type="text" placeholder="Paste YouTube URL..." size="80" id="textURL"&gt;&lt;/input&gt; &lt;br&gt; &lt;!-- start result --&gt; &lt;div class="tubemp3result" id="Searchtarget" &gt;&lt;/div&gt; &lt;!-- start button --&gt; &lt;button onclick="convertByform()"&gt;Convert!&lt;/button&gt; &lt;!-- start bottom result --&gt; &lt;div class="tubemp3" data-type="small" data-play="auto"&gt; &lt;/div&gt; </code></pre> <p>Now this is the source of the "miniplayer.js" file (containing the convertByform() function):</p> <pre><code>function applyplayer(){ var TubeElement = $('.tubemp3'); if(typeof TubeElement != 'undefined'){ var hitAr = 0; while(hitAr &lt; 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' &amp;&amp; typeof TubeID[1] !='undefined')? TubeID[1]:''; if( typeof tubes != 'undefined' &amp;&amp; typeof tubUrl != 'undefined' &amp;&amp; typeof type != 'undefined' &amp;&amp; typeof play != 'undefined' &amp;&amp; typeof TubeID != 'undefined' &amp;&amp; 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 = '&lt;div style="width:'+widhtElem+'px;margin:0px auto;"&gt;&lt;iframe frameborder="0"'+ 'scrolling="no" width="'+width+'" height="'+height+'" '+ 'src="http://tubemp3script.com/player/playerembed.html#'+tubUrl+'|'+type+'|'+play+'"&gt;&lt;/iframe&gt;'+ '&lt;a onclick="getConvert(\''+TubeID+'\')" href="#"&gt;&lt;img src="http://tubemp3script.com/player/download.png" /&gt;&lt;/div&gt;'; $(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 = '&lt;p&gt;&lt;span class="tubeh2"&gt;'+title+'&lt;span&gt;&lt;/p&gt;'+ '&lt;div class="tubemp3" data-type="small" data-width="400" data-autoplay="none"&gt;'+ ''+url+''+ '&lt;/div&gt;'; $($('.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)+'&amp;max-results=4&amp;alt=jsonc&amp;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 = '&lt;div align="center" id="frameconvert" style="background:#ccc;z-index:1000;position:fixed;top:0px;width:500px;height: 190px"&gt;' + '&lt;iframe src="http://tubemp3script.com/work.php?v='+tubeid+'" width="100%" height="190" style="overflow:hidden;" frameborder="0"&gt;&lt;/iframe&gt;'+ '&lt;button style="position:absolute; bottom:0px; right:0px; height:25px;font-size:10px;" onclick="closeFrame()"&gt;close&lt;/button&gt;&lt;/div&gt;'; $('body').append(myhtml); } function applybutton(){ $('.DlTubescript').each(function(){ var checktube = $(this).attr('href'); var getID = /v=(.*)/; var tUbid = getID.exec(checktube); if(tUbid != null &amp;&amp; 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]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload