Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding simple support for youtube playlists #34

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var ytworkers = [];
//Launch configuration manager
function launchConfigTab() {
tabs.open({
url: data.url('preferences.html')
url: data.url('./preferences.html')
});
}
//Save the new configuration
Expand Down Expand Up @@ -191,16 +191,24 @@ function displayMessage(m_title, message, type) {
}
//Parse an url to send
function parseUrlPlay(url, pathname, playhost) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*?((&list=)([^#\&\?]*))?.*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
sendYouTube(match[2], playhost);
if(match[5]) {
sendYouTubeList(match[5], playhost);
} else {
sendYouTubeVideo(match[2], playhost);
}
return;
}
var regExp2 = /^.*(youtube.com\/watch.*[\?\&]v=)([^#\&\?]*).*/;
var regExp2 = /^.*(youtube.com\/watch.*[\?\&]v=)([^#\&\?]*).*?((&list=)([^#\&\?]*))?.*/;
var match2 = url.match(regExp2);
if (match2 && match2[2].length == 11) {
sendYouTube(match2[2], playhost);
if(match[5]) {
sendYouTubeList(match[5], playhost);
} else {
sendYouTubeVideo(match[2], playhost);
}
return;
}
if(pathname === ''){
Expand All @@ -221,8 +229,13 @@ function parseUrlQueue(url, pathname, playhost) {
return;
}
//Send a YouTube video
function sendYouTube(ytid, playhost) {
var url = 'plugin://plugin.video.youtube/?action=play_video&videoid=' + ytid;
function sendYouTubeVideo(ytid, playhost) {
var url = 'plugin://plugin.video.youtube/play/?video_id=' + ytid;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also address #29 👍

prepareSend(url, playhost);
}
//Send a YouTube playlist
function sendYouTubeList(listid, playhost) {
var url = 'plugin://plugin.video.youtube/play/?playlist_id=' + listid + '&order=default&play=1';
prepareSend(url, playhost);
}
//Get password for server
Expand Down Expand Up @@ -365,8 +378,8 @@ exports.main = function () {
},
});
pageMod.PageMod({
include: data.url('preferences.html'),
contentScriptFile: [data.url("jquery-2.1.1.min.js"), data.url('preferences.js')],
include: data.url('./preferences.html'),
contentScriptFile: [data.url("jquery-2.1.1.min.js"), data.url('./preferences.js')],
onAttach: function(worker) {
worker.port.on("updateservers", function (servers) {
//Update the server configuration
Expand Down