0

how do i get my latest video id as variable to use like this:

<script>//fetch newest video id and make it a variable</script>
<button onclick="window.open('https://www.youtube.com/embed/'+videoId+'', 'newwindow', 'width=853, height=480'); return false;">My latest youtube video</button>

like this but JS/JQUERY

and is there any way for doing this for twitch past broadcasts?

<button onclick="window.open('http://www.twitch.tv/User/popout?videoId='+streamId+'', 'newwindow', 'width=853, height=480'); return false;">My latest broadcast</button>
Community
  • 1
  • 1
ziizaa
  • 3
  • 1
  • 5
  • Why are you messing with the question every two minutes. I'm working on answering your question. If you keep changing the question how do you expect people to give you a serious answer? – NewToJS Feb 09 '15 at 15:53

2 Answers2

1

I would recommend using Youtube API

YouTube Data API - Working with Channel IDs

This will not only give you all the video IDs but you will have more control over how you display the video data on your website. If you want more control over the Youtube video player.

YouTube JavaScript Player API Reference

Get Latest video from channel You must use the channel ID for example

https://www.youtube.com/channel/UC5yi93rwcQxIjr0s6Ak8mdw

Channel ID: UC5yi93rwcQxIjr0s6Ak8mdw

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
var i;
function FolderData(ChanID){
    var ChanID=document.getElementById('YTCI').value;
  $.ajax({
    url: 'http://gdata.youtube.com/feeds/base/users/'+ChanID+'/uploads?alt=json-in-script&v=2&orderby=published&max-results=1',
    dataType: 'jsonp',
    success: function(data){
        var vidID=data.feed.entry[0].id.$t.split("video:");
        document.getElementById('Results').innerHTML="Video ID: "+vidID[1];
        var YTbutton= document.getElementById("YTbtn");
        YTbutton.setAttribute("onclick","OpenWindow(\'https://www.youtube.com/embed/"+vidID[1]+"\');");
    },
        error: function () {console.log("Error");}
    });
}
function OpenWindow(Winpath){
window.open(Winpath, 'newwindow', 'width=853, height=480');
}
</script>
</head>
<body>
<input type="text" id="YTCI" placeholder="Channel ID"/><button onclick="FolderData()">Check Console</button>
<div id="Results"></div>
    <button id="YTbtn">My latest youtube video</button>
</body>
</html>
Community
  • 1
  • 1
NewToJS
  • 2,762
  • 3
  • 14
  • 22
0

i made playlist of all my youtube videos and took the embed url of that playlist

<button onclick="window.open('https://www.youtube.com/embed/videoseries?list=PlaylistId', 'newwindow', 'width=853, height=480'); return false;">My latest youtube videos</button>
ziizaa
  • 3
  • 1
  • 5