diff --git a/app/models/comment.rb b/app/models/comment.rb
index 16edcf412..2b67f7921 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -4,8 +4,6 @@
class Comment < ActiveRecord::Base
require File.join(Rails.root, 'lib/diaspora/web_socket')
- require File.join(Rails.root, 'lib/youtube_titles')
- include YoutubeTitles
include ROXML
include Diaspora::Webhooks
@@ -30,7 +28,6 @@ class Comment < ActiveRecord::Base
validates :text, :presence => true, :length => { :maximum => 2500 }
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
- serialize :youtube_titles, Hash
scope :including_author, includes(:author => :profile)
diff --git a/app/models/status_message.rb b/app/models/status_message.rb
index abcb91dac..af7250069 100644
--- a/app/models/status_message.rb
+++ b/app/models/status_message.rb
@@ -6,8 +6,6 @@ class StatusMessage < Post
include Diaspora::Socketable
include Diaspora::Taggable
- include YoutubeTitles
- require File.join(Rails.root, 'lib/youtube_titles')
include ActionView::Helpers::TextHelper
include PeopleHelper
@@ -26,7 +24,6 @@ class StatusMessage < Post
attr_accessible :text, :provider_display_name
attr_accessor :oembed_url
- serialize :youtube_titles, Hash
after_create :create_mentions
diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml
index 78dcc265f..312ca48ae 100644
--- a/app/views/comments/_comment.html.haml
+++ b/app/views/comments/_comment.html.haml
@@ -12,7 +12,7 @@
= person_link(comment.author, :class => "hovercardable")
%span{:class => [direction_for(comment.text), 'collapsible']}
- = markdownify(comment, :oembed => true, :youtube_maps => comment.youtube_titles)
+ = markdownify(comment, :oembed => true)
.comment_info
%time.timeago{:datetime => comment.created_at}
diff --git a/app/views/comments/_comment.mobile.haml b/app/views/comments/_comment.mobile.haml
index 5b622dfa6..3a6bdd586 100644
--- a/app/views/comments/_comment.mobile.haml
+++ b/app/views/comments/_comment.mobile.haml
@@ -12,5 +12,5 @@
= comment.created_at ? time_ago_in_words(comment.created_at) : time_ago_in_words(Time.now)
%div{:class => direction_for(comment.text)}
- = markdownify(comment, :youtube_maps => comment[:youtube_titles])
+ = markdownify(comment)
diff --git a/app/views/status_messages/_status_message.haml b/app/views/status_messages/_status_message.haml
index 6048f085a..9cfd533f0 100644
--- a/app/views/status_messages/_status_message.haml
+++ b/app/views/status_messages/_status_message.haml
@@ -16,4 +16,4 @@
= link_to (image_tag photo.url(:thumb_small), :class => 'stream-photo thumb_small', 'data-small-photo' => photo.url(:thumb_medium), 'data-full-photo' => photo.url), photo_path(photo), :class => 'stream-photo-link'
%div{:class => direction_for(post.text)}
- != markdownify(post, :youtube_maps => post[:youtube_titles])
+ != markdownify(post)
diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml
index f86d4c783..a250b1f5a 100644
--- a/app/views/status_messages/_status_message.html.haml
+++ b/app/views/status_messages/_status_message.html.haml
@@ -16,6 +16,6 @@
= link_to (image_tag photo.url(:thumb_small), :class => 'stream-photo thumb_small', 'data-small-photo' => photo.url(:thumb_medium), 'data-full-photo' => photo.url), photo_path(photo), :class => 'stream-photo-link'
%div{:class => [direction_for(post.text), 'collapsible']}
- != markdownify(post, :youtube_maps => post[:youtube_titles])
+ != markdownify(post)
- if post.o_embed_cache_id.present?
= o_embed_html(post.o_embed_cache)
diff --git a/app/views/status_messages/_status_message.mobile.haml b/app/views/status_messages/_status_message.mobile.haml
index 8a34f126f..00d743ed2 100644
--- a/app/views/status_messages/_status_message.mobile.haml
+++ b/app/views/status_messages/_status_message.mobile.haml
@@ -15,4 +15,4 @@
= image_tag post.image_url
%div{:class => direction_for(post.text)}
- != markdownify(post, :youtube_maps => post[:youtube_titles])
+ != markdownify(post)
diff --git a/lib/youtube_titles.rb b/lib/youtube_titles.rb
deleted file mode 100644
index fcd177d50..000000000
--- a/lib/youtube_titles.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-module YoutubeTitles
- def self.included(model)
- model.class_eval do
- before_save do
- get_youtube_title text
- end
- end if model.respond_to?(:before_save)
- end
-
- def youtube_title_for video_id
- http = Net::HTTP.new('gdata.youtube.com', 80)
- path = "/feeds/api/videos/#{video_id}?v=2"
- resp, data = http.get(path)
- title = data.match(/
(.*)<\/title>/)
- unless title.nil?
- title = title.to_s[7..-9]
- end
- title || I18n.t('application.helper.video_title.unknown')
- end
-
- def get_youtube_title text
- self.youtube_titles = {}
- youtube_match = text.enum_for(:scan, YOUTUBE_ID_REGEX).map { Regexp.last_match }
- return if youtube_match.empty?
-
- matches = {}
- youtube_match.each do |match_data|
- matches[match_data[1]] = CGI::escape(youtube_title_for(match_data[1]))
- end
-
- self.youtube_titles = matches unless matches.empty?
- end
-
- def unserialize_attribute attr_name
- if attr_name == "youtube_titles"
- begin
- super
- rescue ActiveRecord::SerializationTypeMismatch
- {}
- end
- else
- super
- end
- end
- YOUTUBE_ID_REGEX = /(?:https?:\/\/)(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})(?:\S*(#[^ ]+)|\S+)?/im unless defined? YOUTUBE_ID_REGEX
-end
diff --git a/spec/lib/youtube_titles_spec.rb b/spec/lib/youtube_titles_spec.rb
deleted file mode 100644
index 20e527b31..000000000
--- a/spec/lib/youtube_titles_spec.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-require 'spec_helper'
-require 'youtube_titles'
-
-describe YoutubeTitles do
- include YoutubeTitles
-
- before do
- @video_id = "ABYnqp-bxvg"
- @url="http://www.youtube.com/watch?v=#{@video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
- @api_path = "/feeds/api/videos/#{@video_id}?v=2"
- end
-
- describe '#youtube_title_for' do
- before do
- @expected_title = "UP & down & UP & down &"
- @mock_http = mock("http")
- Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(@mock_http)
- end
-
- it 'gets a youtube title corresponding to an id' do
- @mock_http.should_receive(:get).with(@api_path).and_return(
- [nil, "Foobar #{@expected_title} hallo welt dsd"])
- youtube_title_for(@video_id).should == @expected_title
- end
-
- it 'returns a fallback for videos with no title' do
- @mock_http.should_receive(:get).with(@api_path).and_return(
- [nil, "Foobar #{@expected_title} hallo welt dsd"])
- youtube_title_for(@video_id).should == I18n.t('application.helper.video_title.unknown')
- end
- end
-
- describe 'serialization and marshalling' do
- before do
- @expected_title = '""Procrastination"" Tales Of Mere Existence'
- mock_http = mock("http")
- Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
- mock_http.should_receive(:get).with(@api_path).and_return(
- [nil, "Foobar #{@expected_title} hallo welt dsd"])
- @post = Factory.create(:status_message, :text => @url)
- end
-
- it 'can be re-marshalled' do
- lambda {
- StatusMessage.find(@post.id).youtube_titles
- }.should_not raise_error
- end
- it 'can be re-marshalled if it is serializaed incorrectly' do
- StatusMessage.where(:id => @post.id).update_all(:youtube_titles => "this is not yaml")
- lambda {
- StatusMessage.find(@post.id).youtube_titles
- }.should_not raise_error
- end
- end
-
- describe "YOUTUBE_ID_REGEX" do
- specify "normal url" do
- url = "http://www.youtube.com/watch?v=dQw4w9WgXcQ"
- matched_data = url.match(YoutubeTitles::YOUTUBE_ID_REGEX)
- matched_data[0].should == url
- matched_data[1].should == "dQw4w9WgXcQ"
- end
-
- specify "https url" do
- url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
- matched_data = url.match(YoutubeTitles::YOUTUBE_ID_REGEX)
- matched_data[0].should == url
- matched_data[1].should == "dQw4w9WgXcQ"
- end
-
- specify "url with extra query params" do
- url = "http://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=related"
- matched_data = url.match(YoutubeTitles::YOUTUBE_ID_REGEX)
- matched_data[0].should == url
- matched_data[1].should == "dQw4w9WgXcQ"
- end
- end
-end
diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb
index be158ca61..778a5ca8c 100644
--- a/spec/models/comment_spec.rb
+++ b/spec/models/comment_spec.rb
@@ -99,29 +99,6 @@ describe Comment do
end
end
- # NOTE(move this to the youtube module spec)
- describe 'youtube' do
- before do
- @message = alice.post :status_message, :text => "hi", :to => @alices_aspect.id
- end
-
- it 'should process youtube titles on the way in' do
- first_video_id = "ABYnqp-1111"
- second_video_id = "ABYnqp-2222"
- url = "http://www.youtube.com/watch?v=#{first_video_id} http://www.youtube.com/watch?v=#{second_video_id}"
- expected_title = "UP & down & UP & down &"
-
- mock_http = mock("http")
- Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).twice.and_return(mock_http)
- mock_http.should_receive(:get).with(/\/feeds\/api\/videos/).twice.and_return(
- [nil, 'Foobar '+expected_title+' hallo welt dsd'])
-
- comment = alice.build_comment :text => url, :post => @message
- comment.save!
-
- Comment.find(comment.id).youtube_titles.should == { first_video_id => CGI::escape(expected_title), second_video_id => CGI::escape(expected_title) }
- end
- end
describe 'it is relayable' do
before do
diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb
index 5cbb587d6..9c3450249 100644
--- a/spec/models/status_message_spec.rb
+++ b/spec/models/status_message_spec.rb
@@ -275,23 +275,6 @@ STR
end
end
- describe 'youtube' do
- it 'should process youtube titles on the way in' do
- video_id = "ABYnqp-bxvg"
- url="http://www.youtube.com/watch?v=#{video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
- expected_title = "UP & down & UP & down &"
-
- mock_http = mock("http")
- Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
- mock_http.should_receive(:get).with('/feeds/api/videos/'+video_id+'?v=2').and_return(
- [nil, 'Foobar '+expected_title+' hallo welt dsd'])
-
- post = @user.build_post :status_message, :text => url, :to => @aspect.id
-
- post.save!
- Post.find(post.id).youtube_titles.should == {video_id => CGI::escape(expected_title)}
- end
- end
describe '#after_dispatch' do
before do
@photos = [alice.build_post(:photo, :pending => true, :user_file=> File.open(photo_fixture_name)),