-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathyoutube-info-extractor.html
97 lines (92 loc) · 4.54 KB
/
youtube-info-extractor.html
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
<!DOCTYPE html>
<!-- from https://github.com/salmanarshad2000/demos/blob/v1.0.0/youtube/retrieve-title-description-and-thumbnail.html -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Youtube video info extractor</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
body, textarea {
font-family: "Open Sans","Arial";
}
textarea {
font-size: 10pt;
}
</style>
</head>
<body>
<h2>Youtube video info extractor</h2>
<table width="100%">
<tr width="100%">
<td width="40%">
Your Youtube API Access Key: <input id="accesskey" type="text" size="50"> | <small><a target="_blank" href="https://developers.google.com/youtube/v3/getting-started" title="What, you thought I'll let you use mine? :)">Click here to get your Access Key</a></small><br>
<h4>Enter YouTube Video URLs in the text box below,<br>one URL per line</h3>
<textarea id="search-txt" type="text" rows="20" cols="50">
https://www.youtube.com/watch?v=_w1De4KqshI
</textarea>
<br><br>
<input id="search-btn" type="button" value="Fetch Video Information"> <small>give it a few secs</small>
</td><td>
Output: <br>
<textarea id="output" rows="20" cols="80"></textarea>
<br> For youtube-dl:<br><input id="youtubedl" size="80" value="ytmp4"></>
<script>
/*
* YouTube: Retrieve Title, and other info
* Original: http://salman-w.blogspot.com/2010/01/retrieve-youtube-video-title.html,
* https://github.com/salmanarshad2000/demos/blob/v1.0.0/youtube/retrieve-title-description-and-thumbnail.html
*/
//$(function() {
$("#search-btn").on("click", function() {
document.getElementById('output').value = '';
document.getElementById('youtubedl').value = '';
var array1 = document.getElementById('search-txt').value.split('\n');
for (i=0; i< array1.length; i++) { // for loop cyling through each line of input text
var line = array1[i];
var videoid = "";
var matches = line.match(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/i); // from https://stackoverflow.com/a/37704433/4355695
if (matches) {
videoid = matches[5];
//console.log(array1[i] + " : " + matches[5]);
}
if (videoid.match(/^[a-z0-9_-]{11}$/i) === null) {
document.getElementById("output").value += line + " : Unable to parse Video ID/URL.\n\n";
continue;
}
$.getJSON("https://www.googleapis.com/youtube/v3/videos", {
key: $('#accesskey').val(),
part: "snippet,statistics",
id: videoid
}, function(data) {
if (data.items.length === 0) {
document.getElementById("output").value += line + " : Video not found.\n\n";
} else {
document.getElementById("output").value += "https://www.youtube.com/watch?v=" + data.items[0].id + "\n" + data.items[0].snippet.title + " -" + data.items[0].snippet.channelTitle + ", " + data.items[0].snippet.publishedAt.substr(0,10) + "\n\n" ;
}
document.getElementById("youtubedl").value += " " + 'http://youtu.be/' + data.items[0].id;
/*
other infos, from original script:
$("<img>", {
src: data.items[0].snippet.thumbnails.medium.url,
width: data.items[0].snippet.thumbnails.medium.width,
height: data.items[0].snippet.thumbnails.medium.height
}).appendTo("#video-data-1");
$("<p></p>").text(data.items[0].snippet.description).appendTo("#video-data-1");
$("<li></li>").text("Published at: " + data.items[0].snippet.publishedAt).appendTo("#video-data-2");
$("<li></li>").text("View count: " + data.items[0].statistics.viewCount).appendTo("#video-data-2");
$("<li></li>").text("Favorite count: " + data.items[0].statistics.favoriteCount).appendTo("#video-data-2");
$("<li></li>").text("Like count: " + data.items[0].statistics.likeCount).appendTo("#video-data-2");
$("<li></li>").text("Dislike count: " + data.items[0].statistics.dislikeCount).appendTo("#video-data-2");
*/
}).fail(function(jqXHR, textStatus, errorThrown) {
document.getElementById("output").value += "Error for id " + videoid + ": " + ( jqXHR.responseText || errorThrown ) + "\n\n";
});
} //end of for loop cycling through each line
});
//});
</script>
</td></tr></table>
<br>
By <a href="http://nikhilvj.cu.cc">Nikhil VJ</a>. Adapted from <a href="http://salman-w.blogspot.com/2010/01/retrieve-youtube-video-title.html">this script by Salman Arshad</a>, to be able to process multiple URLs. Also, got a neat expression-matching regexp from <a href="https://stackoverflow.com/a/37704433/4355695">this Stackoverflow answer</a> that can catch any kind of youtube URL thrown at it :).
</body>
</html>