Cast API
This commit is contained in:
parent
441f45d6d7
commit
aab3933275
7 changed files with 112 additions and 8 deletions
16
api.php
16
api.php
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
||||||
*
|
*
|
||||||
* PHP Version 5.3.10
|
* PHP Version 5.3.10
|
||||||
*
|
*
|
||||||
* @category Youtube-dl
|
* @category Youtube-dl
|
||||||
* @package Youtubedl
|
* @package Youtubedl
|
||||||
* @author Pierre Rudloff <rudloff@strasweb.fr>
|
* @author Pierre Rudloff <rudloff@strasweb.fr>
|
||||||
|
@ -15,7 +15,7 @@ require_once 'download.php';
|
||||||
if (isset($_GET["url"])) {
|
if (isset($_GET["url"])) {
|
||||||
if (isset($_GET["format"]) || isset($_GET['audio'])) {
|
if (isset($_GET["format"]) || isset($_GET['audio'])) {
|
||||||
$video = VideoDownload::getJSON($_GET["url"], $_GET["format"]);
|
$video = VideoDownload::getJSON($_GET["url"], $_GET["format"]);
|
||||||
|
|
||||||
if (isset($video->url)) {
|
if (isset($video->url)) {
|
||||||
//Vimeo needs a correct user-agent
|
//Vimeo needs a correct user-agent
|
||||||
$UA = VideoDownload::getUA();
|
$UA = VideoDownload::getUA();
|
||||||
|
@ -57,7 +57,7 @@ if (isset($_GET["url"])) {
|
||||||
);
|
);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isset($_GET['audio'])) {
|
if (isset($_GET['audio'])) {
|
||||||
header(
|
header(
|
||||||
|
@ -135,12 +135,12 @@ if (isset($_GET["url"])) {
|
||||||
include 'logo.php';
|
include 'logo.php';
|
||||||
?>
|
?>
|
||||||
<p>You are going to download<i>
|
<p>You are going to download<i>
|
||||||
<a href="<?php echo $video->webpage_url; ?>">
|
<a id="video_link" data-ext="<?php echo $video->ext; ?>" data-video="<?php echo $video->url; ?>" href="<?php echo $video->webpage_url; ?>">
|
||||||
<?php
|
<?php
|
||||||
echo $video->title;
|
echo $video->title;
|
||||||
?></a></i>.</p>
|
?></a></i>. <img class="cast_icon" id="cast_disabled" src="img/ic_media_route_disabled_holo_light.png" alt="Google Cast™ is disabled" title="Google Cast is not supported on this browser." /><img class="cast_btn cast_hidden cast_icon" id="cast_btn_launch" src="img/ic_media_route_off_holo_light.png" title="Cast to ChromeCast" alt="Google Cast™" /><img src="img/ic_media_route_on_holo_light.png" alt="Casting to ChromeCast…" title="Stop casting" id="cast_btn_stop" class="cast_btn cast_hidden cast_icon" /></p>
|
||||||
<?php
|
<?php
|
||||||
echo '<img class="thumb" src="',
|
echo '<img class="thumb" src="',
|
||||||
$video->thumbnail, '" alt="" />';
|
$video->thumbnail, '" alt="" />';
|
||||||
?><br/>
|
?><br/>
|
||||||
<form action="api.php">
|
<form action="api.php">
|
||||||
|
@ -184,7 +184,7 @@ if (isset($_GET["url"])) {
|
||||||
$error=true;
|
$error=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($error)) {
|
if (isset($error)) {
|
||||||
include 'head.php';
|
include 'head.php';
|
||||||
?>
|
?>
|
||||||
|
|
90
cast.js
Normal file
90
cast.js
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*global chrome*/
|
||||||
|
/*jslint devel: true, browser: true */
|
||||||
|
var launchBtn, disabledBtn, stopBtn;
|
||||||
|
var session, currentMedia;
|
||||||
|
|
||||||
|
function receiverListener() {
|
||||||
|
'use strict';
|
||||||
|
console.log('receiverListener');
|
||||||
|
}
|
||||||
|
|
||||||
|
function sessionListener() {
|
||||||
|
'use strict';
|
||||||
|
console.log('sessionListener');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMediaDiscovered(how, media) {
|
||||||
|
'use strict';
|
||||||
|
currentMedia = media;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMediaError() {
|
||||||
|
'use strict';
|
||||||
|
console.log('onMediaError');
|
||||||
|
stopCast();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRequestSessionSuccess(e) {
|
||||||
|
'use strict';
|
||||||
|
session = e;
|
||||||
|
var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
|
||||||
|
stopBtn.classList.remove('cast_hidden');
|
||||||
|
launchBtn.classList.add('cast_hidden');
|
||||||
|
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onLaunchError() {
|
||||||
|
'use strict';
|
||||||
|
console.log('onLaunchError');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInitSuccess() {
|
||||||
|
'use strict';
|
||||||
|
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError() {
|
||||||
|
'use strict';
|
||||||
|
console.log('onError');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onStopCast() {
|
||||||
|
'use strict';
|
||||||
|
stopBtn.classList.add('cast_hidden');
|
||||||
|
launchBtn.classList.remove('cast_hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
function launchCast() {
|
||||||
|
'use strict';
|
||||||
|
var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.PAGE_SCOPED);
|
||||||
|
chrome.cast.initialize(apiConfig, onInitSuccess, onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopCast() {
|
||||||
|
'use strict';
|
||||||
|
session.stop(onStopCast);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeCastApi() {
|
||||||
|
'use strict';
|
||||||
|
launchBtn = document.getElementById('cast_btn_launch');
|
||||||
|
disabledBtn = document.getElementById('cast_disabled');
|
||||||
|
stopBtn = document.getElementById('cast_btn_stop');
|
||||||
|
if (launchBtn) {
|
||||||
|
disabledBtn.classList.add('cast_hidden');
|
||||||
|
launchBtn.classList.remove('cast_hidden');
|
||||||
|
launchBtn.addEventListener('click', launchCast, false);
|
||||||
|
stopBtn.addEventListener('click', stopCast, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadCastApi(loaded, errorInfo) {
|
||||||
|
'use strict';
|
||||||
|
if (loaded) {
|
||||||
|
initializeCastApi();
|
||||||
|
} else {
|
||||||
|
console.log(errorInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window['__onGCastApiAvailable'] = loadCastApi;
|
2
head.php
2
head.php
|
@ -21,6 +21,8 @@ href="https://fonts.googleapis.com/css?family=Open+Sans:400,300" />
|
||||||
<meta name="twitter:image" content="http://www.alltubedownload.net/img/logo.png" />
|
<meta name="twitter:image" content="http://www.alltubedownload.net/img/logo.png" />
|
||||||
<meta name="twitter:creator" content="@Tael67" />
|
<meta name="twitter:creator" content="@Tael67" />
|
||||||
<meta name="twitter:description" content="Easily download videos from Youtube, Dailymotion, Vimeo and other websites." />
|
<meta name="twitter:description" content="Easily download videos from Youtube, Dailymotion, Vimeo and other websites." />
|
||||||
|
<script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
|
||||||
|
<script src="cast.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
img/ic_media_route_disabled_holo_light.png
Normal file
BIN
img/ic_media_route_disabled_holo_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 380 B |
BIN
img/ic_media_route_off_holo_light.png
Normal file
BIN
img/ic_media_route_off_holo_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 401 B |
BIN
img/ic_media_route_on_holo_light.png
Normal file
BIN
img/ic_media_route_on_holo_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 439 B |
12
style.css
12
style.css
|
@ -526,6 +526,18 @@ h1 {
|
||||||
max-width:700px;
|
max-width:700px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cast_btn {
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cast_hidden {
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cast_icon {
|
||||||
|
vertical-align:middle;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.thumb {
|
.thumb {
|
||||||
width:90%;
|
width:90%;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue