fb_video_url_converter 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ = Version 0.2.5
2
+ * Removed errors login. Reraising different errors than FacebookBot::LoginFailed so will log automatically. Inserted all cookie_jar operations into begin-rescue blocks because it sometimes raises "undefined method expired? 4 nil class"
1
3
  = Version 0.2.4
2
4
  * Experimental Rails errors loggin
3
5
  = Version 0.2.3
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('fb_video_url_converter', '0.2.4') do |p|
5
+ Echoe.new('fb_video_url_converter', '0.2.5') do |p|
6
6
  p.description = "Facebook Video URL Converter is intended as an easy alternative to changing video hosting from Facebook to a different one."
7
7
  p.url = "https://github.com/mensfeld/FB-Video-URL-Converter"
8
8
  p.author = "Maciej Mensfeld"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fb_video_url_converter}
5
- s.version = "0.2.4"
5
+ s.version = "0.2.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Maciej Mensfeld"]
data/lib/facebook_bot.rb CHANGED
@@ -38,10 +38,7 @@ class FacebookBot
38
38
 
39
39
  begin
40
40
  @@root = File.join(Rails.root, 'tmp')
41
- @@rails = true
42
- rescue Exception => e
43
- @@rails = false
44
- log e
41
+ rescue
45
42
  raise CookiePathNotInitialized, 'Specify cookie_path' if self.class.cookie_path.nil?
46
43
  @@root = self.class.cookie_path
47
44
  end
@@ -50,9 +47,7 @@ class FacebookBot
50
47
 
51
48
  begin
52
49
  @agent.cookie_jar.load(@cookies)
53
- rescue Exception => e
54
- log e
55
- @agent.cookie_jar.clear!
50
+ rescue
56
51
  end if (File.file?(@cookies) && File.size(@cookies) > 10)
57
52
 
58
53
  self.login
@@ -69,24 +64,18 @@ class FacebookBot
69
64
  page = @agent.get(FB_URL) if page.root.to_html.include?('<title>Redirecting')
70
65
  end
71
66
 
72
- @agent.cookie_jar.save_as(@cookies)
73
- body = page.root.to_html
74
-
67
+ # Donno why but sometimes cookiejar gets crazy - so better be prepared ;)
75
68
  begin
76
- # This is a UID given to each Facebook user.
77
- @uid = %r{\\"user\\":(\d+),\\"hide\\"}.match(body)[1]
78
- rescue Exception => e
79
- log e
80
- @uid = nil
69
+ @agent.cookie_jar.save_as(@cookies)
70
+ rescue
81
71
  end
72
+
73
+ body = page.root.to_html
82
74
 
83
75
  # This is a token we need to submit forms.
84
76
  begin
85
77
  @post_form_id = %r{<input type="hidden" .* name="post_form_id" value="([^"]+)}.match(body)[1]
86
- rescue Exception => e
87
- log e
88
- File.open(@cookies, 'w') {|f| f.write('') }
89
- @agent.cookie_jar.clear!
78
+ rescue
90
79
  raise self.class::LoginFailed, 'Incorrect login or password'
91
80
  end
92
81
  end
@@ -95,8 +84,7 @@ class FacebookBot
95
84
  begin
96
85
  load_video_page(id)
97
86
  get_url(@video_page)
98
- rescue Exception => e
99
- log e
87
+ rescue
100
88
  VIDEO_ERROR
101
89
  end
102
90
  end
@@ -108,11 +96,6 @@ class FacebookBot
108
96
 
109
97
  private
110
98
 
111
- # We log stuff only when using rails (to lazy to write diff logger not for rails)
112
- def log(e)
113
- Rails.logger.error "[FB_Video_Url_Converter] #{e}" if @@rails
114
- end
115
-
116
99
  def load_video_page(id)
117
100
  if @video_page.nil?
118
101
  pa = @agent.get("#{FB_URL}video/video.php?v=#{id}")
@@ -54,8 +54,8 @@ class FacebookVideo < ActiveRecord::Base
54
54
  def self.get(v_id)
55
55
  v = self.video_data(v_id)
56
56
  case v
57
- when 'video_error' then NotWorkingVideo.new(VIDEO_ERROR_MSG)
58
- when 'fb_error' then NotWorkingVideo.new(FB_ERROR_MSG)
57
+ when :video_error then NotWorkingVideo.new(VIDEO_ERROR_MSG)
58
+ when :fb_error then NotWorkingVideo.new(FB_ERROR_MSG)
59
59
  else v
60
60
  end
61
61
  end
@@ -100,14 +100,14 @@ class FacebookVideo < ActiveRecord::Base
100
100
  v_id = v_id.scan(/[0-9]+/).first
101
101
  end
102
102
 
103
- return 'video_error' if v_id.nil? || v_id.length < 12
103
+ return :video_error if v_id.nil? || v_id.length < 12
104
104
 
105
105
  video = self.find_by_video_id(v_id)
106
106
  unless video && video.valid?
107
107
  begin
108
108
  fb = FacebookBot.new
109
109
  rescue FacebookBot::LoginFailed
110
- return 'fb_error'
110
+ return :fb_error
111
111
  end
112
112
  url = fb.video_url(v_id)
113
113
  name = fb.video_name(v_id)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fb_video_url_converter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 0.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Maciej Mensfeld
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- ��������L�K��x8�s����ĩ�
1
+ cp6�AK�7�|#O�<a�~:l�P�d�g�b���`�g��S�r�R�K���*8�8fsu�4r�w,�w�f�3<�!��Z��m՘�(1p ��~=a�.�F@��<�_��6��2������#�n;�S�G\9p�c��˽Ҭt� ����u�ogm;�g-�l� A��K�Ҝ�D�J�Uzu�Ұ��⼻B<Ԅ��e�� �lCBQ�8��sWl'�b��6���#�[��T-�����m�t}�lH�