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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"/>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="screen"/>
<title>YouTube Recutter</title>
<style type="text/css">
td, th { padding: 0.5em; }
input.timebox { width: 5em; }
button { margin: 0.25em; }
</style>
<script type="text/javascript">
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
// read a cutlist and turn it into a URL fragment string
// format: #ytid,ytid,ytid:i-e-s,i-e-s,i-e-s
// - ytid is a youtube video id
// - i is an index into the list of ytids
// - s is a start time in decimal seconds
// - e is an end time in decimal seconds
function frag_make(cutlist) {
var vid_list = cutlist.map(function(x) {return x.id}).filter(onlyUnique);
var cuts = cutlist.map(function(x) {
return {id: vid_list.indexOf(x.id),
start: x.start,
end: x.end}});
var frag = vid_list.join(",") + ":" +
cuts.map(function(x) { return [x.id, x.start, x.end].join("-") }).join(",");
return frag;
}
// read a URL fragment string and turn it into a cutlist
function frag_parse(frag) {
var vc
vc = frag.split(":");
var vids = vc[0].split(",");
var cuts = vc[1].split(",");
var cutlist = cuts.map(function(x) { ise = x.split("-");
return {id:vids[+ise[0]], start:+ise[1], end:+ise[2]}; })
return cutlist;
}
</script>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>YouTube Recutter</h1>
<p class="lead">Create and share an edit of a YouTube video</p>
</div>
<div class="col-md-9">
<div id="player">
<label>Paste link to video:
<input type="text" id="video-link"/>
</label>
<button id="load-button" disabled="true" onclick="load_video_button();">load</button>
</div>
</div>
<div class="col-md-3">
<div>
<button id="play-button" onclick="play_from_cutlist();">play this cut ></button><br/>
<hr/>
<button id="go-button" onclick="b_grab();">Cut here!</button>
<button id="add-button" onclick="cutlist_append_empty();">add a blank cut</button>
<button id="share-button" onclick="b_share();">save to url</button><br/>
</div>
<table class="table" id="cutlist">
<thead>
<tr><th>start</th><th>end</th></tr>
</thead>
<tbody></tbody>
</table>
<p>copyright by chronomex, 2015. all rights reserved.</p>
</div>
</div>
<script type="text/javascript">
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an iframe (and player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
$("#load-button")[0].disabled = false;
if (video_id) {
load_video();
}
}
var video_id;
function load_video_button() {
var video_url = $("#video-link")[0].value;
video_id = video_url.match(/(?:youtu\.be\/|[?&]v=)([-_A-Za-z0-9]*)/)[1];
load_video();
}
function load_video() {
player = new YT.Player('player', {
height: '390',
width: '640',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
player.loadVideoById(video_id);
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
}
function cutlist_cleanup() {
}
function cutlist_append_empty() {
var row = '<tr><td><input type="number" min="0" class="b-start timebox" name="start"/></td><td><input type="number" min="0" class="b-end timebox" name="end"/></td></tr>';
$("#cutlist tbody").append(row);
return $("#cutlist tbody tr").last()[0];
}
function add_start(time) {
var row = cutlist_append_empty()
row.className = "cut-active";
$(row).find(".b-start")[0].value = time;
}
function add_end(time) {
$(".cut-active .b-end")[0].value = time;
$(".cut-active")[0].className = "";
}
function b_grab() {
row = $(".cut-active").last();
time = Math.round(player.getCurrentTime()*100.)/100.
if (row.size() == 0) { // no cuts are active
add_start(time);
player.playVideo();
} else {
player.pauseVideo();
add_end(time);
}
return;
}
function b_share() {
var cutlist = $("#cutlist tr").get()
.filter(function(x) { return $(x).find("input").size() != 0 })
.map(function(x) {
return {
start: +($(x).find("td input.b-start")[0].value),
end: +($(x).find("td input.b-end")[0].value),
id: player.getVideoData().video_id
}
})
.filter(function(x) { return x.start != x.end; })
var frag = frag_make(cutlist);
history.pushState(null, "Video recut", "#" + frag);
}
function play_from_cutlist() {
}
function load_cutlist_from_url() {
if (window.location.hash.length == 0)
return;
var cutlist = frag_parse(window.location.hash .replace("#", ""));
cutlist.forEach(function(x) {
add_start(x.start);
add_end(x.end);
});
video_id = cutlist[0].id;
load_video();
}
load_cutlist_from_url();
</script>
</body>
</html>
|