Skip to content

Commit ed9dc3a

Browse files
authored
Add files via upload
1 parent 10bb6a6 commit ed9dc3a

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

youtube titles data from URLs.html

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!DOCTYPE html>
2+
<!-- from https://github.com/salmanarshad2000/demos/blob/v1.0.0/youtube/retrieve-title-description-and-thumbnail.html -->
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<title>YouTube: Retrieve Title and info for list of videos</title>
7+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
8+
<style>
9+
</style>
10+
</head>
11+
<body>
12+
<h3>Enter YouTube Video ID or URLs in the text box below, one URL per line</h3>
13+
14+
<table width="100%">
15+
<tr width="100%">
16+
<td width="50%">
17+
18+
<textarea id="search-txt" type="text" value="https://www.youtube.com/watch?v=_w1De4KqshI" rows="20" cols="60"></textarea>
19+
<br><br>
20+
<input id="search-btn" type="button" value="Fetch Video Information">
21+
</td><td>
22+
<br><br><br>
23+
<textarea id="output" rows="30" cols="60"></textarea>
24+
<script>
25+
/*
26+
* YouTube: Retrieve Title, and other info
27+
* Original: http://salman-w.blogspot.com/2010/01/retrieve-youtube-video-title.html,
28+
* https://github.com/salmanarshad2000/demos/blob/v1.0.0/youtube/retrieve-title-description-and-thumbnail.html
29+
*/
30+
31+
$(function() {
32+
33+
$("#search-btn").on("click", function() {
34+
$("#video-data-1, #video-data-2").empty();
35+
document.getElementById("output").value = "";
36+
37+
var array1 = document.getElementById('search-txt').value.split('\n');
38+
for (i=0; i< array1.length; i++) {
39+
40+
//var videoid = $("#search-txt").val();
41+
var videoid = array1[i];
42+
var matches = videoid.match(/^https:\/\/www\.youtube\.com\/.*[?&]v=([^&]+)/i) || videoid.match(/^https:\/\/youtu\.be\/([^?]+)/i);
43+
if (matches) {
44+
videoid = matches[1];
45+
console.log(matches[0]);
46+
console.log(matches[1]);
47+
}
48+
if (videoid.match(/^[a-z0-9_-]{11}$/i) === null) {
49+
document.getElementById("output").value += videoid + " : Unable to parse Video ID/URL.\n\n";
50+
continue;
51+
}
52+
$.getJSON("https://www.googleapis.com/youtube/v3/videos", {
53+
key: "AIzaSyB67EeMDNvqQqPqwVM-Jtqt8Pdpq-R9q4I",
54+
part: "snippet,statistics",
55+
id: videoid
56+
}, function(data) {
57+
if (data.items.length === 0) {
58+
document.getElementById("output").value += videoid + " : Video not found.\n\n";
59+
60+
} else {
61+
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" ;
62+
}
63+
64+
/*
65+
other infos, from original script:
66+
$("<img>", {
67+
src: data.items[0].snippet.thumbnails.medium.url,
68+
width: data.items[0].snippet.thumbnails.medium.width,
69+
height: data.items[0].snippet.thumbnails.medium.height
70+
}).appendTo("#video-data-1");
71+
$("<p></p>").text(data.items[0].snippet.description).appendTo("#video-data-1");
72+
$("<li></li>").text("Published at: " + data.items[0].snippet.publishedAt).appendTo("#video-data-2");
73+
$("<li></li>").text("View count: " + data.items[0].statistics.viewCount).appendTo("#video-data-2");
74+
$("<li></li>").text("Favorite count: " + data.items[0].statistics.favoriteCount).appendTo("#video-data-2");
75+
$("<li></li>").text("Like count: " + data.items[0].statistics.likeCount).appendTo("#video-data-2");
76+
$("<li></li>").text("Dislike count: " + data.items[0].statistics.dislikeCount).appendTo("#video-data-2");
77+
*/
78+
}).fail(function(jqXHR, textStatus, errorThrown) {
79+
document.getElementById("output").value += "Error for id " + videoid + ": " + ( jqXHR.responseText || errorThrown ) + "\n\n";
80+
});
81+
}
82+
});
83+
});
84+
</script>
85+
</td></tr></table>
86+
<br>
87+
Note: URLs should have https:// and not http:// .<br>
88+
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.
89+
</body>
90+
</html>

0 commit comments

Comments
 (0)