aboutsummaryrefslogtreecommitdiffstats
path: root/tools/processor.php
blob: 6b18f7453f987ac55d054a8ffc35ab42db75e3a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
require_once "init.php";

if ( empty( $_GET['link'] ) ){
    header( 'Location: index.php' );
}

$baselink = htmlspecialchars( $_GET['link'] );

$urlexists = url_exists( $baselink );
if ( $urlexists === TRUE ) {
    // Regex - filter URL id is match[5]
    $rx = '/^((?:https?:)?\/\/)?                # Optional protocol
             ((?:www|m)[.])?                    # Optional sub-domain
             ((?:youtube[.]com|
                 youtu[.]be|
                 invidio[.]us|
                 invidiou[.]sh|
                 invidious[.]kabi[.]tk|
                 invidious[.]snopyta[.]org))    # URL supports
             (\/(?:[\w\-]+\?v=|embed\/|v\/)?)   # Parameters (embed, v)
             ([\w\-]+)                          # Video id of 11
             (\S+)?$/mx';
    preg_match( $rx, $baselink, $match );

    // Testing if id → 11 characters
    if ( strlen( $match[5] ) == 11 ) {
        $video_id = $match[5];
    } else {
        header( 'Location: index.php' );
    }
} else {
    header( 'Location: index.php' );
}

// servers JSON
$invidio0 = "https://invidio.us/api/v1/videos/{$video_id}";
$invidio1 = "https://invidious.snopyta.org/api/v1/videos/{$video_id}";

$invidio0on = url_exists( $invidio0 );
$invidio1on = url_exists( $invidio1 );

// check servers
if ( $invidio0on === TRUE ) {
    $video_string = file_get_contents( $invidio0 );
} elseif ( $invidio1on === TRUE ) {
    $video_string = file_get_contents( $invidio1 );
} else {
    header( 'Location: index.php' );
}

$video_info = json_decode( $video_string );

$videoTitle = $video_info->title;
$videoAuthor = $video_info->author;
$videoDurationSecs = $video_info->lengthSeconds;
$videoDuration = secToDuration( $videoDurationSecs );
$videoChannel = $video_info->author;

// Begin_ViewCount
$extract_video_view = $video_info->viewCount;
$videoViews = bytes( $extract_video_view );
// End_ViewCount

// change hqdefault.jpg to default.jpg for downgrading the thumbnail quality
$videoThumbURL = "https://i1.ytimg.com/vi/{$video_id}/hqdefault.jpg";
$librethumb = $video_info->videoThumbnails[0]->url;

// Extract videos from JSON
$streamFormats = $video_info->formatStreams;

// Downloads
$downloads = $video_info->formatStreams;

///// Beaking DRM!!!
// Check standar video into URL
$url_standar = video_exists( $streamFormats[0]->url );
// format video DRM
$formatdrm = $streamFormats[0]->type;

// nodes
$node0 = "https://invidio.us/latest_version?id={$video_id}&itag=18&local=true";
$node1 = "https://invidious.snopyta.org/latest_version?id={$video_id}&itag=18&local=true";
// explain DRM
$drmv  = "https://archive.org/download/libreweb/rms-drm.webm";

$node0on = video_exists( $node0 );
$node1on = video_exists( $node1 );

// check nodes
if ( $node0on === TRUE ) {
    $breakurl = $node0;
} elseif ( $node1on === TRUE ) {
    $breakurl = $node1;
} else {
    $breakurl = $drmv;
    $formatdrm = 'video/webm';
}

if ( $url_standar === FALSE ) {
    // Liberty data
    $breakquality = trim( $streamFormats[0]->resolution, 'p' );
    $breaklink = <<<EOT
<source data-res="{$breakquality}" src="{$breakurl}" type='{$formatdrm}'/>
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}" title="{$videoTitle}.{$downloadFormat}" download="{$videoTitle}.{$downloadFormat}">Descarga Habilitada</a>
  </div>
</div>
EOT;
} else {
    $breaklink = '';
    $breakdownload = '';
}
///// End Beaking DRM!!!

// // Captions
// $streamCaptions = $video_info->captions;