Skip to content

Commit bc24a50

Browse files
authored
Update and rename youtube titles data from URLs.html to youtube-info-extractor.html
1 parent ed9dc3a commit bc24a50

File tree

2 files changed

+92
-90
lines changed

2 files changed

+92
-90
lines changed

youtube titles data from URLs.html

-90
This file was deleted.

youtube-info-extractor.html

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

0 commit comments

Comments
 (0)