aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-05-21 22:31:18 -0500
committerJesús <heckyel@hyperbola.info>2019-05-21 22:31:18 -0500
commit403def35b11d2dba5e596662ebdd0c9dd2438772 (patch)
treeef1fbae8d7968e120aa30c3c947d267cb1ee3ffb
parent0c10774cd262d3b038691567684861e191100733 (diff)
downloadytlibre-403def35b11d2dba5e596662ebdd0c9dd2438772.tar.lz
ytlibre-403def35b11d2dba5e596662ebdd0c9dd2438772.tar.xz
ytlibre-403def35b11d2dba5e596662ebdd0c9dd2438772.zip
Extract data from invidio
This migration allows users to extract videos with DRM and without DRM. All this without non-free JS
-rw-r--r--embed/index.php3
-rw-r--r--index.php7
-rw-r--r--templates/embed.tpl6
-rw-r--r--templates/video.tpl31
-rw-r--r--tools/init.php73
-rw-r--r--tools/processor.php71
6 files changed, 68 insertions, 123 deletions
diff --git a/embed/index.php b/embed/index.php
index 0136083..8d85408 100644
--- a/embed/index.php
+++ b/embed/index.php
@@ -24,7 +24,8 @@ if (empty($_GET['link'])){
$video_decode->assign("videoTitle", $videoTitle);
$video_decode->assign("librethumb", $librethumb);
- $video_decode->assign("videosStream", $videosStream);
+ $video_decode->assign("streamFormats", $streamFormats);
+ $video_decode->assign("breaklink", $breaklink);
/* ---- ---- CSS ---- ---- */
$video_decode->assign('styles', array('frond' => '../templates/css/frond.min.css',
diff --git a/index.php b/index.php
index 8000daa..ff1be94 100644
--- a/index.php
+++ b/index.php
@@ -30,9 +30,12 @@ if (empty($_GET['link'])){
$video_decode->assign("videoViews", $videoViews);
$video_decode->assign("librethumb", $librethumb);
- $video_decode->assign("cStreams", $cStreams);
+ $video_decode->assign("downloads", $downloads);
+ $video_decode->assign("breakdownload", $breakdownload);
+ $video_decode->assign("streamFormats", $streamFormats);
+
+ $video_decode->assign("breaklink", $breaklink);
$video_decode->assign("baselink", $baselink);
- $video_decode->assign("videosStream", $videosStream);
/* ---- ---- CSS ---- ---- */
$video_decode->assign('styles', array('frond' => 'templates/css/frond.min.css',
diff --git a/templates/embed.tpl b/templates/embed.tpl
index 53939d6..6934726 100644
--- a/templates/embed.tpl
+++ b/templates/embed.tpl
@@ -36,9 +36,9 @@
</head>
<body>
<video class="player-ply" controls poster="{$librethumb}" data-setup="{}">
- {foreach $videosStream as $stream}
- {$stream = json_decode(json_encode($stream))}
- <source data-res="{$stream->quality}" src="{$stream->url}" type="{$stream->libretype}"/>
+ {$breaklink}
+ {foreach $streamFormats as $stream}
+ <source data-res="{trim($stream->resolution, 'p')}" src="{$stream->url}" type='{$stream->type}'/>
{/foreach}
<p>Lo siento, este navegador no soporta vídeo en HTML5. Por favor, cambia o actualiza tu navegador web</p>
</video>
diff --git a/templates/video.tpl b/templates/video.tpl
index 8a8eafc..94b7cde 100644
--- a/templates/video.tpl
+++ b/templates/video.tpl
@@ -73,26 +73,25 @@
<hr>
<div class="contenedor">
<h4>Formatos de vídeo</h4>
- {foreach $cStreams as $stream}
- {$stream = json_decode(json_encode($stream))}
+ {foreach $downloads as $download}
<div class="row">
- <div class="col">{$stream->type}</div>
- <div class="col">{$stream->quality}</div>
- <div class="col">{$stream->size}</div>
+ <div class="col">{$download->container}</div>
+ <div class="col">{$download->resolution}</div>
<div class="col">
- <a class="boton-descarga" href="{$stream->url}" download>Descarga</a>
+ <a class="boton-descarga" href="{$download->url}" download>Descarga</a>
</div>
</div>
- {/foreach}
- <div class="librevideojs">
- <video class="player-ply" controls poster="{$librethumb}" data-setup="{}">
- {foreach $videosStream as $stream}
- {$stream = json_decode(json_encode($stream))}
- <source data-res="{$stream->quality}" src="{$stream->url}" type="{$stream->libretype}"/>
- {/foreach}
- <p>Lo siento, este navegador no soporta vídeo en HTML5. Por favor, cambia o actualiza tu navegador web</p>
- </video>
- </div>
+ {/foreach}
+ {$breakdownload}
+ <div class="librevideojs">
+ <video class="player-ply" controls poster="{$librethumb}" data-setup="{}">
+ {$breaklink}
+ {foreach $streamFormats as $stream}
+ <source data-res="{trim($stream->resolution, 'p')}" src="{$stream->url}" type='{$stream->type}'/>
+ {/foreach}
+ <p>Lo siento, este navegador no soporta vídeo en HTML5. Por favor, cambia o actualiza tu navegador web</p>
+ </video>
+ </div>
<!--Plyr-->
<script>
document.addEventListener('DOMContentLoaded', () => {
diff --git a/tools/init.php b/tools/init.php
index d822c1e..2627811 100644
--- a/tools/init.php
+++ b/tools/init.php
@@ -14,76 +14,3 @@ function secToDuration($seconds){
$seconds = ($seconds - ($minutes * 60));
return $minutes . ' minutes ' . $seconds . ' seconds';
}
-
-function parseStream($stream){
- $available_formats = [];
- foreach ($stream as $format) {
- parse_str($format, $format_info);
- if (isset($format_info['bitrate'])) $quality = isset($format_info['quality_label'])?$format_info['quality_label']:round($format_info['bitrate']/1000). 'k';
- else $quality = isset($format_info['quality'])?$format_info['quality']:'';
-
- switch ($quality){
- case 'hd720':
- $quality = "720";
- break;
- case 'medium':
- $quality = "360";
- break;
- case 'small':
- $quality = "240"; // May Less
- break;
- }
- $type = explode(";", $format_info['type']);
- $type= $type[0];
- switch ($type) {
- case 'video/3gpp':
- $type = "3GP";
- break;
- case 'video/mp4':
- $type = "MP4";
- break;
- case 'video/webm':
- $type = "WEBM";
- break;
- }
-
- $libretype = explode(";", $format_info['type']);
- $libretype= $libretype[0];
- switch ($libretype) {
- case 'video/webm':
- $libretype = "video/webm";
- break;
- }
-
- $available_formats[] = [
- 'itag' => $format_info['itag'],
- 'quality' => $quality,
- 'type' => $type,
- 'libretype' => $libretype,
- 'url' => $format_info['url'],
- 'size' => getSize($format_info['url']),
-
- ];
- }
-
- return $available_formats;
-}
-
-function getSize($url)
-{
-
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_NOBODY, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- $r = curl_exec($ch);
-
- foreach (explode("\n", $r) as $header) {
- if (strpos($header, 'Content-Length:') === 0) {
- return intval(intval(trim(substr($header, 16)))/ (1024*1024)) . " MB";
- }
- }
-}
diff --git a/tools/processor.php b/tools/processor.php
index f4e6d2b..89a37f6 100644
--- a/tools/processor.php
+++ b/tools/processor.php
@@ -18,23 +18,18 @@ if (strpos($baselink,$yturl) !== false){
parse_str($link, $urlData);
$video_id = array_values($urlData)[0];
-$videoFetchURL = file_get_contents("https://www.youtube.com/get_video_info?html5=1&video_id={$video_id}");
-parse_str($videoFetchURL, $video_info);
+$video_string = file_get_contents("https://invidio.us/api/v1/videos/{$video_id}");
+
+$video_info = json_decode($video_string);
-$video_info = json_decode(json_encode($video_info));
-if (!$video_info->status === "ok") {
- die("error in fetching youtube video data");
-}
$videoTitle = $video_info->title;
$videoAuthor = $video_info->author;
-$videoDurationSecs = $video_info->length_seconds;
+$videoDurationSecs = $video_info->lengthSeconds;
$videoDuration = secToDuration($videoDurationSecs);
-$videoChannel = $video_info->ucid;
+$videoChannel = $video_info->author;
// Begin_ViewCount
-$api_key = 'AIzaSyB9TLn5HvT614SjzBv8ZOj3wL2tc7PM3M4'; // API KEY only view_count
-$data_all = json_decode(file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id={$video_id}&key={$api_key}"));
-$video_view = $data_all->items[0]->statistics->viewCount;
+$extract_video_view = $video_info->viewCount;
function bytes($a) {
$unim = array("","K","M","G","T","P");
@@ -46,25 +41,45 @@ function bytes($a) {
return number_format($a,($c ? 2 : 0),",",".")." ".$unim[$c];
}
-$videoViews = bytes($video_view);
+$videoViews = bytes($extract_video_view);
// End_ViewCount
-//change hqdefault.jpg to default.jpg for downgrading the thumbnail quality
+// change hqdefault.jpg to default.jpg for downgrading the thumbnail quality
$videoThumbURL = "https://i1.ytimg.com/vi/{$video_id}/hqdefault.jpg";
-$librethumb = "https://i1.ytimg.com/vi/{$video_id}/maxresdefault.jpg";
-
-if (!isset($video_info->url_encoded_fmt_stream_map)) {
- die('No data found');
-}
-
-$streamFormats = explode(",", $video_info->url_encoded_fmt_stream_map);
-
-if (isset($video_info->adaptive_fmts)) {
- $streamSFormats = explode(",", $video_info->adaptive_fmts);
- $pStreams = parseStream($streamSFormats);
+$librethumb = $video_info->videoThumbnails[0]->url;
+
+// Extract videos from JSON
+$streamFormats = $video_info->formatStreams;
+
+// Downloads
+$downloads = $video_info->formatStreams;
+
+// Breaking DRM!!!
+$url_drm = $streamFormats[0]->url;
+@$headers = get_headers($url_drm);
+if (preg_match('/^HTTP\/\d\.\d\s+(403)/', $headers[0])){
+ // Liberty data
+ $breakquality = trim($streamFormats[0]->resolution, 'p');
+ $breakurl = "https://invidio.us/latest_version?id={$video_id}&itag=18&local=true";
+ $breaklink = <<<EOT
+ <source data-res="{$breakquality}" src="{$breakurl}" type='{$streamFormats[0]->type}'/>
+EOT;
+ $downloadFormat = $downloads[0]->container;
+ $downloadQuality = $streamFormats[0]->resolution;
+ $breakdownload = <<<EOT
+<div class="row">
+ <div class="col">{$downloadFormat}</div>
+ <div class="col">{$downloadQuality}</div>
+ <div class="col">
+ <a class="boton-descarga" href="{$breakurl}" download>Descarga Habilitada</a>
+ </div>
+</div>
+EOT;
+} else {
+ $breaklink = '';
+ $breakdownload = '';
}
+// End Breaking DRM!!!
-$cStreams = parseStream($streamFormats);
-
-// Aquí selecciona solo 2 vídeos principales.
-$videosStream = array_slice($cStreams, 0, 2);
+// // Captions
+// $streamCaptions = $video_info->captions;