Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/youtube-api-migration'
Browse files Browse the repository at this point in the history
  • Loading branch information
khloke committed Jul 11, 2015
2 parents 47ff87c + b5347fb commit a3194f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
Binary file modified images/bitcoin_qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 17 additions & 22 deletions js/content_scripts/youtube-content-scripts.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

initYouTubeList();

chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action == "getPlaylistUrls") {
initYouTubeList();
sendResponse({urlList: JSON.stringify(urlList)});
} else if (request.action == "onPlayback") {
$("video")[0].pause();
Expand All @@ -18,46 +18,41 @@ chrome.extension.onMessage.addListener(
function initYouTubeList(){
var tabUrl = window.location.href;
var youTubeListId = getURLParameter(tabUrl, 'list');
if (youTubeListId){
if (youTubeListId && youTubeListId != playlistId){
playlistId = youTubeListId;
extractVideosFromYouTubePlaylist(youTubeListId);
}
}

function extractVideosFromYouTubePlaylist(playListID, index) {
var currentIndex;
if (!index) {
urlList = [];
currentIndex = 1;
} else {
currentIndex = index;
}
var playListURL = '//gdata.youtube.com/feeds/api/playlists/' + playListID + '?v=2&alt=json&start-index=' + currentIndex;
function extractVideosFromYouTubePlaylist(playListID, token) {
var videoURL = 'https://www.youtube.com/watch?v=';
$.getJSON(playListURL, function (data) {
//GLOBAL
var playListURL = '//www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults=50&playlistId=' + playListID + '&key=AIzaSyA3INgfTLddMbrJm8f68xpvfPZDAzDqk10';
if (token) {
playListURL = playListURL + '&pageToken=' + token;
}

var totalVideoCount = data.feed.openSearch$totalResults.$t;
var itemsPerPage = data.feed.openSearch$itemsPerPage.$t;
var startIndex = data.feed.openSearch$startIndex.$t;
$.getJSON(playListURL, function (data) {
var nextPageToken;
if (data.nextPageToken) {
nextPageToken = data.nextPageToken;
}

$.each(data.feed.entry, function (i, item) {
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
$.each(data.items, function (i, item) {
var videoID = item.contentDetails.videoId;
var url = videoURL + videoID;

urlList.push(url);
});

if (totalVideoCount > itemsPerPage && startIndex < (totalVideoCount - totalVideoCount%itemsPerPage + 1)) {
if (nextPageToken) {
extractVideosFromYouTubePlaylist(playListID, startIndex + itemsPerPage);
}
});
}

var playlistId;
var urlList = [];


function getURLParameter(tabUrl, sParam) {
var sPageURL = tabUrl.substring(tabUrl.indexOf('?') + 1 );
var sURLVariables = sPageURL.split('&');
Expand Down

0 comments on commit a3194f6

Please sign in to comment.