Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Not every youtube-link contains a video #215

Closed
goto opened this Issue Mar 1, 2013 · 2 comments

Comments

Projects
None yet
4 participants

goto commented Mar 1, 2013

A youtube-link does not have to be a video-url which contains a ?v=.
But subway doesn't consider this case.

e.g. http://www.youtube.com/results?search_query=do+the+harlem+shake

Stack trace

Uncaught TypeError: Cannot call method 'indexOf' of undefined utils.js:47
window.utils.linkify utils.js:47
Backbone.Model.extend.parse models.js:22
Backbone.View.extend.render message.js:29
Backbone.View.extend.initialize message.js:3
g.View backbone-min.js:36
o.extend.p.extend.v.extend.x.extend.j.extend.d backbone-min.js:41
Backbone.View.extend.addMessage chat.js:152
t backbone-min.js:8
g.Events.trigger backbone-min.js:10
e.extend._onModelEvent backbone-min.js:27
t backbone-min.js:8
g.Events.trigger backbone-min.js:10
e.extend.add backbone-min.js:21
(anonymous function) client.js:179
EventEmitter.emit socket.io.js:627
SocketNamespace.onPacket socket.io.js:2172
Socket.onPacket socket.io.js:1862
Transport.onPacket socket.io.js:1309
Transport.onData socket.io.js:1286
WS.open.websocket.onmessage

My 1 minute fix, which was only tested on the above case, for /assets/js/utils.js line 41ff.

//Look for embeddable media in all the links
      for (var i=0; i<links.length; i++){
        var href = links[i];
        //Add embedded youtube video
        if (href.search('http://www.youtube.com') > -1) {
          var video_id = href.split('v=')[1];
// my 'fix'
          if (video_id === undefined) {
              continue;
          }
Contributor

Fauntleroy commented Mar 4, 2013

While that works, it leaves out the (rare) case where someone uses a short youtube URL. Here's the method I use:

// Get Youtube ID out of a URL
testYoutube: function( url ){

    var id = url.match( /(?:youtube\.com.*[\?&]v=|youtu\.be\/)(.{11})/i );
    id = ( id )? id[1]: id;

    return id;

}
Contributor

Ibuprofen commented Mar 4, 2013

ae77502 should support short youtube urls (youtu.be). I tested http://youtu.be/WF34N4gJAKE locally and embed worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment