Youtube audio player generator script, found on web

Started on the old forum in January 2012 · view the original in the archive · old links redirect here

#audio #generator #player #script #youtube

3 replies · 1,671 views · started 14 years ago · 1 min read

4 participants
just_m3. Developer · 199 posts #1

Interesting script found on web, must share 🙂

<?php
    if(isset($_GET["source"])) { highlight_file(__FILE__);die(); }
    if(isset($_GET["q"])) { $q = $_GET["q"]; } else { $q = NULL; } // URI
    if(isset($_GET["a"])) { $a = true; } else { $a = false; } // Autoplay
    if(isset($_GET["loop"])) { $l = true; } else { $l = false; } // Loop
    if(isset($_GET["js"])) { $js = true; } else { $js = false; } // JavaScript API
    if(isset($_GET["fp"])) { $p = true; } else { $p = false; } // Progress Bar
    if(isset($_GET["sh"])) { $sh = true; } else { $sh = false; } // Shuffle
    if(isset($_GET["psize"])) { $ps = strtolower($_GET["psize"]); } // Progress Bar Size
    if(isset($_GET["invis"])) { $invisible = true; } else { $invisible = false; } // Invisible
    if(isset($_GET["html5"])) { $html5 = true; } else { $html5 = false; } // Use HTML5 Player
    if(isset($_GET["cookie"])) { $cookie = true; } else { $cookie = false; } // Allow Cookies
    if(!isset($_GET["psize"]) || ($ps != "s" && $ps != "m" && $ps != "l")) { $ps = "s"; } // Player Size
    if(isset($_GET["tiny"])) { $tiny = true; } else { $tiny = false; }
    if(isset($_GET["api"])) { $api = true; } else { $api = false; } // API Usage
    $w = 62;
    $h = 25;
    if(isset($_GET["s"]))
    {
        $s = true;
        if($ps == "s") { $w = 150; }
        if($ps == "m") { $w = 187; }
        if($ps == "l") { $w = 224; }
        if($ps == "i") { $w = 0;$h = 0; }
        if(isset($_GET["tc"])) // Time Code
        {
            $tc = true;
            if($ps == "s") { $w = 225; }
            if($ps == "m") { $w = 262; }
            if($ps == "l") { $w = 299; }
        }
    } else { $s = false; }
    if(isset($_GET["w"])) { $w = $_GET["w"]; } // Width
    if(isset($_GET["h"])) { $h = $_GET["h"]; } // Height
    if($tiny) { $w = 30; }
    if($invisible) { $w = 0; $h = 0; }
    
    if($q)
    {
        $q = urldecode($q);
        $uri = str_replace("?","&",$q);
        $base1 = explode("&v=",$uri);
        $base2 = explode("&",$base1[1]);
        $base3 = explode("&p=",$uri);
        $base4 = explode("&",$base3[1]);
        $plcode = $base4[0];
        $code = $base2[0];
        $type = "VIDEO";
        if(!$code || $p)
        {
            if(!$plcode) // First Try
            {
                $base3 = explode("&list=",$uri);
                $base4 = explode("&",$base3[1]);
                $plcode = substr($base4[0],2);
            }
            if(!$plcode)
                { $e = TRUE; $eMsg = "Not a YouTube Video or Playlist URL"; }
            else
            {
                $type = "PLAYLIST";
                $code = $plcode;
            }
        }
    }

$modifier = "?hl=en";
if($a) { $modifier .= "&autoplay=1"; }
if($l) { $modifier .= "&loop=1"; }
if($js){ $modifier .= "&enablejsapi=1"; }
if($sh){ $modifier .= "&shuffle=200"; }
if($type == "VIDEO")
{
    if(!$cookie) $embed_url = "http://www.youtube-nocookie.com/v/".$code.$modifier;
    if($cookie) $embed_url = "http://www.youtube.com/v/".$code.$modifier;
    $link_url = "http://www.youtube.com/watch?v=".$code.$modifier;
}
if($type == "PLAYLIST")
{
    $modifier .= "&version=2";
    if(!$cookie) $embed_url = "http://www.youtube-nocookie.com/p/".$code.$modifier;
    if($cookie) $embed_url = "http://www.youtube.com/p/".$code.$modifier;
    $link_url = "http://www.youtube.com/view_play_list?p=".$code.$modifier;
}
if(!$html5)
{
$html = '
            <object width="'.$w.'" height="'.$h.'">
                <param name="movie" value="'.$embed_url.'"></param>
                <param name="allowFullScreen" value="true"></param>
                <param name="allowscriptaccess" value="always"></param>
                <embed src="'.$embed_url.'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'.$w.'" height="'.$h.'">
                <noembed>
                    <a href="'.$link_url.'">
                        <img src="http://www.gtaero.net/ytmusic/play.png" alt="Play" style="border:0px;" />
                    </a>
                </noembed>
            </object>
';
} else {
    if($_GET["s"])
    {
        $h = $h+18;
    }
    if($type == "VIDEO")
    {
        $embed_url = "http://www.youtube-nocookie.com/embed/{$code}{$modifier}";
        $link_url = "http://www.youtube.com/watch?v={$code}{$modifier}";
    }
    $html = '
        <iframe src="'.$embed_url.'" frameborder="0" width="'.$w.'" height="'.$h.'">
            <a href="'.$link_url.'">
                <img src="http://www.gtaero.net/ytmusic/play.png" alt="Play" style="border:0px;" />
            </a>
        </iframe>
    ';
}
$html = str_replace(array("\n","\r\n","\t"),"",$html);

if($api)
{
    header("Content-type: text/plain;charset=utf-8");
    die($html);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
    <head>
        <title>YouTube Audio Player</title>
        <style type="text/css">
            .i1 { padding-left:20px; }
            div { margin-top:0px;padding-top:0px; }
        </style>
        <script type="text/javascript">
            function toggle(e)
            {
                if(e.style.display == "none") { e.style.display = "block"; }
                else { e.style.display = "none"; }
            }
        </script>
    </head>
    <body>
        <h1>YouTube Audio Player</h1>
<?php if($e) { ?>
        <h2>Error</h2>
        <p><?= $eMsg ?></p>
<?php } ?>
        <h2>Form</h2>
        <form method="get" action="./">
            <label for="yturl">URL To Video:</label> <input id="yturl" type="text" name="q" value="<?=$q?>" /> [ <a href="<?=$q?>" target="_blank">test</a> ]
            <br />
            <label><input type="checkbox" id="tiny" name="tiny" <?php if($tiny) { print("checked=\"checked\" "); } ?> /> Tiny (Not Compatible with Progress Bar)</label><br />
            <input type="checkbox" id="progress" name="s" <?php if($s) { print("checked=\"checked\" "); } ?>onclick="toggle(document.getElementById('needProgress')); "/> <label for="progress">Progress Bar</label>
            <div id="needProgress"<?php if(!$s) { print(" style=\"display:none\""); } ?> class="i1">
                <input type="checkbox" id="timecode" name="tc" <?php if($tc) { print("checked=\"checked\" "); } ?>/> <label for="timecode">Time Code</label>
                <br />
                <label for="progress_size">Size:</label>
                <select name="psize" id="progress_size">
                    <option value="s"<?php if($ps == "s") { print("selected=\"selected\""); } ?>>Small</option>
                    <option value="m"<?php if($ps == "m") { print("selected=\"selected\""); } ?>>Medium</option>
                    <option value="l"<?php if($ps == "l") { print("selected=\"selected\""); } ?>>Large</option>
                </select>
            </div>
            <br />
            <input type="checkbox" id="autoplay" name="a" <?php if($a) { print("checked=\"checked\" "); } ?>/> <label for="autoplay">Autoplay</label>
            <br />
            <input type="checkbox" id="loop" name="loop" <?php if($l) { print("checked=\"checked\" "); } ?>/> <label for="loop">Loop</label>
            <br />
            <input type="checkbox" id="invis" name="invis" <?php if($invisible) { print("checked=\"checked\" "); } ?>/> <label for="invis">Invisible</label>
            <br />
            <?php if($plcode && ($type != "PLAYLIST" || $p)) { ?>
            <input type="checkbox" id="playlist" name="fp" <?php if($p) { print("checked=\"checked\" "); } ?>/> <label for="playlist">Entire Playlist</label> [ <a href="http://youtube.com/view_play_list?p=<?=$plcode?>" target="_blank">test</a> ]
            <br />
            <?php } ?>
            <input type="checkbox" id="js" name="js" <?php if($js) { print("checked=\"checked\" "); } ?>/> <label for="js">JavaScript API</label>
            <br />
            <input type="checkbox" id="html5" name="html5" <?php if($html5) { echo 'checked="checked" '; } ?> /> <label for="html5">New Player</label> (Testing Only)
            <br />
            <input type="checkbox" id="cookie" name="cookie" <?php if($cookie) { echo 'checked="checked" '; } ?> /> <label for="cookie"> Allow YouTube to collect cookies</label>
            <br />
            <input type="submit" value="Make!" />
        </form>
        <h2>Preview</h2>
        <?= $html ?>
        <h2>Embeddable Code</h2>
        <textarea rows="5" cols="50" editable="false"><?= $html ?></textarea>
        <hr />
        <p>
            <a href="http://tech.gtaero.net/code/youtube-audio-player">About</a> |
            <a href="./?source">View Source</a> |
            <a href="javascript:document.location='http://gtaero.net/ytmusic/?q=' + encodeURIComponent(document.location);">Generate Audio Player</a> (Bookmarklet)
        </p>
    </body>
</html><?php
    if(isset($_GET["source"])) { highlight_file(__FILE__);die(); }
    if(isset($_GET["q"])) { $q = $_GET["q"]; } else { $q = NULL; } // URI
    if(isset($_GET["a"])) { $a = true; } else { $a = false; } // Autoplay
    if(isset($_GET["loop"])) { $l = true; } else { $l = false; } // Loop
    if(isset($_GET["js"])) { $js = true; } else { $js = false; } // JavaScript API
    if(isset($_GET["fp"])) { $p = true; } else { $p = false; } // Progress Bar
    if(isset($_GET["sh"])) { $sh = true; } else { $sh = false; } // Shuffle
    if(isset($_GET["psize"])) { $ps = strtolower($_GET["psize"]); } // Progress Bar Size
    if(isset($_GET["invis"])) { $invisible = true; } else { $invisible = false; } // Invisible
    if(isset($_GET["html5"])) { $html5 = true; } else { $html5 = false; } // Use HTML5 Player
    if(isset($_GET["cookie"])) { $cookie = true; } else { $cookie = false; } // Allow Cookies
    if(!isset($_GET["psize"]) || ($ps != "s" && $ps != "m" && $ps != "l")) { $ps = "s"; } // Player Size
    if(isset($_GET["tiny"])) { $tiny = true; } else { $tiny = false; }
    if(isset($_GET["api"])) { $api = true; } else { $api = false; } // API Usage
    $w = 62;
    $h = 25;
    if(isset($_GET["s"]))
    {
        $s = true;
        if($ps == "s") { $w = 150; }
        if($ps == "m") { $w = 187; }
        if($ps == "l") { $w = 224; }
        if($ps == "i") { $w = 0;$h = 0; }
        if(isset($_GET["tc"])) // Time Code
        {
            $tc = true;
            if($ps == "s") { $w = 225; }
            if($ps == "m") { $w = 262; }
            if($ps == "l") { $w = 299; }
        }
    } else { $s = false; }
    if(isset($_GET["w"])) { $w = $_GET["w"]; } // Width
    if(isset($_GET["h"])) { $h = $_GET["h"]; } // Height
    if($tiny) { $w = 30; }
    if($invisible) { $w = 0; $h = 0; }
    
    if($q)
    {
        $q = urldecode($q);
        $uri = str_replace("?","&",$q);
        $base1 = explode("&v=",$uri);
        $base2 = explode("&",$base1[1]);
        $base3 = explode("&p=",$uri);
        $base4 = explode("&",$base3[1]);
        $plcode = $base4[0];
        $code = $base2[0];
        $type = "VIDEO";
        if(!$code || $p)
        {
            if(!$plcode) // First Try
            {
                $base3 = explode("&list=",$uri);
                $base4 = explode("&",$base3[1]);
                $plcode = substr($base4[0],2);
            }
            if(!$plcode)
                { $e = TRUE; $eMsg = "Not a YouTube Video or Playlist URL"; }
            else
            {
                $type = "PLAYLIST";
                $code = $plcode;
            }
        }
    }

$modifier = "?hl=en";
if($a) { $modifier .= "&autoplay=1"; }
if($l) { $modifier .= "&loop=1"; }
if($js){ $modifier .= "&enablejsapi=1"; }
if($sh){ $modifier .= "&shuffle=200"; }
if($type == "VIDEO")
{
    if(!$cookie) $embed_url = "http://www.youtube-nocookie.com/v/".$code.$modifier;
    if($cookie) $embed_url = "http://www.youtube.com/v/".$code.$modifier;
    $link_url = "http://www.youtube.com/watch?v=".$code.$modifier;
}
if($type == "PLAYLIST")
{
    $modifier .= "&version=2";
    if(!$cookie) $embed_url = "http://www.youtube-nocookie.com/p/".$code.$modifier;
    if($cookie) $embed_url = "http://www.youtube.com/p/".$code.$modifier;
    $link_url = "http://www.youtube.com/view_play_list?p=".$code.$modifier;
}
if(!$html5)
{
$html = '
            <object width="'.$w.'" height="'.$h.'">
                <param name="movie" value="'.$embed_url.'"></param>
                <param name="allowFullScreen" value="true"></param>
                <param name="allowscriptaccess" value="always"></param>
                <embed src="'.$embed_url.'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'.$w.'" height="'.$h.'">
                <noembed>
                    <a href="'.$link_url.'">
                        <img src="http://www.gtaero.net/ytmusic/play.png" alt="Play" style="border:0px;" />
                    </a>
                </noembed>
            </object>
';
} else {
    if($_GET["s"])
    {
        $h = $h+18;
    }
    if($type == "VIDEO")
    {
        $embed_url = "http://www.youtube-nocookie.com/embed/{$code}{$modifier}";
        $link_url = "http://www.youtube.com/watch?v={$code}{$modifier}";
    }
    $html = '
        <iframe src="'.$embed_url.'" frameborder="0" width="'.$w.'" height="'.$h.'">
            <a href="'.$link_url.'">
                <img src="http://www.gtaero.net/ytmusic/play.png" alt="Play" style="border:0px;" />
            </a>
        </iframe>
    ';
}
$html = str_replace(array("\n","\r\n","\t"),"",$html);

if($api)
{
    header("Content-type: text/plain;charset=utf-8");
    die($html);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
    <head>
        <title>YouTube Audio Player</title>
        <style type="text/css">
            .i1 { padding-left:20px; }
            div { margin-top:0px;padding-top:0px; }
        </style>
        <script type="text/javascript">
            function toggle(e)
            {
                if(e.style.display == "none") { e.style.display = "block"; }
                else { e.style.display = "none"; }
            }
        </script>
    </head>
    <body>
        <h1>YouTube Audio Player</h1>
<?php if($e) { ?>
        <h2>Error</h2>
        <p><?= $eMsg ?></p>
<?php } ?>
        <h2>Form</h2>
        <form method="get" action="./">
            <label for="yturl">URL To Video:</label> <input id="yturl" type="text" name="q" value="<?=$q?>" /> [ <a href="<?=$q?>" target="_blank">test</a> ]
            <br />
            <label><input type="checkbox" id="tiny" name="tiny" <?php if($tiny) { print("checked=\"checked\" "); } ?> /> Tiny (Not Compatible with Progress Bar)</label><br />
            <input type="checkbox" id="progress" name="s" <?php if($s) { print("checked=\"checked\" "); } ?>onclick="toggle(document.getElementById('needProgress')); "/> <label for="progress">Progress Bar</label>
            <div id="needProgress"<?php if(!$s) { print(" style=\"display:none\""); } ?> class="i1">
                <input type="checkbox" id="timecode" name="tc" <?php if($tc) { print("checked=\"checked\" "); } ?>/> <label for="timecode">Time Code</label>
                <br />
                <label for="progress_size">Size:</label>
                <select name="psize" id="progress_size">
                    <option value="s"<?php if($ps == "s") { print("selected=\"selected\""); } ?>>Small</option>
                    <option value="m"<?php if($ps == "m") { print("selected=\"selected\""); } ?>>Medium</option>
                    <option value="l"<?php if($ps == "l") { print("selected=\"selected\""); } ?>>Large</option>
                </select>
            </div>
            <br />
            <input type="checkbox" id="autoplay" name="a" <?php if($a) { print("checked=\"checked\" "); } ?>/> <label for="autoplay">Autoplay</label>
            <br />
            <input type="checkbox" id="loop" name="loop" <?php if($l) { print("checked=\"checked\" "); } ?>/> <label for="loop">Loop</label>
            <br />
            <input type="checkbox" id="invis" name="invis" <?php if($invisible) { print("checked=\"checked\" "); } ?>/> <label for="invis">Invisible</label>
            <br />
            <?php if($plcode && ($type != "PLAYLIST" || $p)) { ?>
            <input type="checkbox" id="playlist" name="fp" <?php if($p) { print("checked=\"checked\" "); } ?>/> <label for="playlist">Entire Playlist</label> [ <a href="http://youtube.com/view_play_list?p=<?=$plcode?>" target="_blank">test</a> ]
            <br />
            <?php } ?>
            <input type="checkbox" id="js" name="js" <?php if($js) { print("checked=\"checked\" "); } ?>/> <label for="js">JavaScript API</label>
            <br />
            <input type="checkbox" id="html5" name="html5" <?php if($html5) { echo 'checked="checked" '; } ?> /> <label for="html5">New Player</label> (Testing Only)
            <br />
            <input type="checkbox" id="cookie" name="cookie" <?php if($cookie) { echo 'checked="checked" '; } ?> /> <label for="cookie"> Allow YouTube to collect cookies</label>
            <br />
            <input type="submit" value="Make!" />
        </form>
        <h2>Preview</h2>
        <?= $html ?>
        <h2>Embeddable Code</h2>
        <textarea rows="5" cols="50" editable="false"><?= $html ?></textarea>
        <hr />
        <p>
            <a href="http://tech.gtaero.net/code/youtube-audio-player">About</a> |
            <a href="./?source">View Source</a> |
            <a href="javascript:document.location='http://gtaero.net/ytmusic/?q=' + encodeURIComponent(document.location);">Generate Audio Player</a> (Bookmarklet)
        </p>
    </body>
</html>

Demo : YouTube Audio Player Source : http://www.gtaero.net/ytmusic/?source

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

Attachments: test.zip
gogreen Junior · 18 posts #2

Thanx Dude !

Make A Thought Go Green !

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close