muri 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -12,6 +12,8 @@ MURI Currently supports:
12
12
  * Imageshack
13
13
  * Photobucket
14
14
  ** "API documentation":http://photobucket.com/developer/documentation
15
+ * Twitpic
16
+ ** "API documentation":http://twitpic.com/api.do
15
17
  * Facebook
16
18
  ** "API documentation":http://wiki.developers.facebook.com/index.php/API
17
19
 
@@ -56,11 +58,11 @@ Assuming the URI was successfully parsed (thus @a.valid? == true@), all media ty
56
58
  </code>
57
59
  </pre>
58
60
 
59
- *NOTE: Facebook photos return a hash for @media_api_id@, keyed with @pid@ (the ID for the photo) and @user_id@ (the ID for the user)*
61
+ *NOTE: Facebook photos return a @media_api_id@ which can be used to search for photo information in a Facebook photos.get API call as the pid. This pid is NOT the same as the pid found in the query string (the @media_id@)*
60
62
 
61
63
  * Services with a @media_api_id@ also have a @media_api_type@, which indicates what sort of API call should be made (be it 'photo', 'video', 'media', 'set', 'album', or 'playlist', depending on URI type)
62
64
 
63
- * A direct media url for Youtube, Photobucket, and Imageshack (@http://img#{num}.imageshack.us/img#{num}/#{NUMBER}/#{IMAGENAME}@ format)
65
+ * A direct media url for Youtube, Photobucket, Twitpic, and Imageshack (@http://img#{num}.imageshack.us/img#{num}/#{NUMBER}/#{IMAGENAME}@ format)
64
66
 
65
67
  <pre>
66
68
  <code>
@@ -68,7 +70,7 @@ Assuming the URI was successfully parsed (thus @a.valid? == true@), all media ty
68
70
  </code>
69
71
  </pre>
70
72
 
71
- * A media landing website url for Youtube, Photobucket, Imageshack, Vimeo, and Flickr (flickr media_url's provide the @http://flic.kr/p/#{ID}@ short url)
73
+ * A media landing website url for Youtube, Photobucket, Imageshack, Vimeo, Twitpic, and Flickr (flickr media_url's provide the @http://flic.kr/p/#{ID}@ short url)
72
74
 
73
75
  <pre>
74
76
  <code>
@@ -84,7 +86,7 @@ Assuming the URI was successfully parsed (thus @a.valid? == true@), all media ty
84
86
  </code>
85
87
  </pre>
86
88
 
87
- * Thumbnails URL for Youtube Photobucket, and Flickr (flickr in the @http://farm#{num}.static.flickr.com/@ format)
89
+ * Thumbnails URL for Youtube Photobucket, Twitpic, and Flickr (flickr in the @http://farm#{num}.static.flickr.com/@ format)
88
90
 
89
91
  <pre>
90
92
  <code>
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 5
4
+ :patch: 6
data/lib/muri/base.rb CHANGED
@@ -16,6 +16,7 @@ class Muri
16
16
  include Filter::Imageshack
17
17
  include Filter::Photobucket
18
18
  include Filter::Facebook
19
+ include Filter::Twitpic
19
20
 
20
21
  def self.parse(url)
21
22
  self.new(url)
@@ -1,10 +1,4 @@
1
1
  require 'cgi'
2
- ## Best way I have been able to find to use the facebook API to fetch photo information is as follows:
3
- ## First, get a list of all user photos (using media_id). Parse each resulting <photo> element until you
4
- ## find one where <link> equals
5
- ## 'http://www.facebook.com/photo.php?pid=#{media_api_id[:pid]}&amp;id=#{media_api_id[:user_id]}'
6
- ##
7
- ## Sucks a whole lot, but facebook seems to no longer allow API calls using the PID from the query string.
8
2
  class Muri
9
3
  module Filter
10
4
  module Facebook
@@ -38,7 +32,9 @@ class Muri
38
32
  share_key = params["l"].first
39
33
 
40
34
  @info[:website] = "#{url_common}/photo.php?pid=#{@info[:media_id]}&l=#{share_key}&id=#{media_creator}"
41
- @info[:media_api_id] = { :pid => @info[:media_id], :user_id => media_creator }
35
+
36
+ # The media_api_id is the PID which can be searched for in the facebook photos table
37
+ @info[:media_api_id] = (media_creator << 32) + @info[:media_id]
42
38
  end
43
39
  end
44
40
 
@@ -59,8 +55,8 @@ class Muri
59
55
  end
60
56
  end
61
57
  end
62
-
63
58
  # http://www.facebook.com/photo.php?pid=34929102&l=a1abf8cd37&id=15201063 (preview)
59
+ # database_pid = (USER_ID << 32) + PID
64
60
  # pid = photo id
65
61
  # id = user id
66
62
  # l = photo share key
@@ -45,7 +45,7 @@ class Muri
45
45
  if @info[:media_api_type] == FLICKR_PHOTO
46
46
  @info[:website] = "http://flic.kr/p/" + self.class.encode58(@info[:media_id].to_i)
47
47
  elsif @info[:media_api_type] == FLICKR_SET
48
- @info[:website] = "http://www.flickr.com/photos/#{media_creator}/sets/#{@info[:media_id]}"
48
+ @info[:website] = "http://www.flickr.com/photos/#{media_creator}/sets/#{@info[:media_id]}"#/show takes direct
49
49
  end
50
50
  else
51
51
  raise UnsupportedURI
@@ -15,10 +15,10 @@ class Muri
15
15
  server_id = $1
16
16
  url_common = "http://img#{server_id}.imageshack.us"
17
17
 
18
- if @url.path =~ /^\/i\/([a-z0-9]*?)\.([a-z0-9]*?)\//i
18
+ if @url.path =~ /^\/i\/([a-z0-9]+?)\.([a-z0-9]+?)\//i
19
19
  @info[:media_id] = $1
20
20
  @info[:content_type] = $2
21
- elsif @url.path =~ /^\/img([0-9]*?)\/([0-9]*?)\/([a-z0-9]*?)\.([a-z0-9]*?)/i
21
+ elsif @url.path =~ /^\/img([0-9]*?)\/([0-9]+?)\/([a-z0-9]+?)\.([a-z0-9]+?)/i
22
22
  content_path_id = $2
23
23
  @info[:media_id] = $3
24
24
  @info[:content_type] = $4
@@ -48,4 +48,4 @@ end
48
48
 
49
49
  # http://img30.imageshack.us/img30/4184/rush02.mp4
50
50
  # http://img30.imageshack.us/i/rush02.mp4/
51
- # http://yfrog.us/0urush02z
51
+ # http://yfrog.us/0urush02z => http://code.google.com/p/imageshackapi/wiki/YFROGurls
@@ -0,0 +1,46 @@
1
+ class Muri
2
+ module Filter
3
+ module Twitpic
4
+
5
+ TWITPIC_PHOTO = 'photo'
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ self::PARSERS[Muri::Filter::Twitpic] = "twitpic_parse"
10
+ end
11
+ end
12
+
13
+ def twitpic_parse
14
+ @info[:service] = 'Twitpic'
15
+ url_common = "http://twitpic.com"
16
+
17
+ if @url.path =~ /^([a-z0-9]+)/i
18
+ @info[:media_id] = $1
19
+ @info[:website] = "#{url_common}/#{@info[:media_id]}"
20
+ @info[:media_url] = "#{url_common}/show/large/#{@info[:media_id]}"
21
+ @info[:media_thumbnail] = "#{url_common}/show/thumb/#{@info[:media_id]}"
22
+ @info[:media_api_type] = TWITPIC_PHOTO
23
+ end
24
+
25
+ # Twitpic does not have an API to pull photo info. Media ID is best guess
26
+ if self.valid?
27
+ @info[:media_api_id] = @info[:media_id]
28
+ else
29
+ raise UnsupportedURI
30
+ end
31
+
32
+ self
33
+ end
34
+
35
+ def self.parsable?(uri)
36
+ uri.host =~ /^twitpic\.com$/i
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ # http://twitpic.com/17d7th
43
+ # http://twitpic.com/show/large/17d7th
44
+ # http://twitpic.com/show/thumb/17d7th
45
+
46
+ # http://twitpic.com/api.do
@@ -19,8 +19,11 @@ class Muri
19
19
  if @url.path =~ /^\/(album\/)?([0-9]+)(\/)?$/i
20
20
  @info[:media_id] = $2
21
21
  @info[:media_api_type] = $1.nil? ? VIMEO_VIDEO : VIMEO_ALBUM
22
+ elsif @url.path =~ /^\/groups\/([0-9a-z\@\-\_]+)\/videos\/([0-9]+)(\/)?$/i
23
+ @info[:media_id] = $2
24
+ @info[:media_api_type] = VIMEO_VIDEO
22
25
  elsif ((@url.path =~ /^\/moogaloop\.swf/i) && (params.include?("clip_id")))
23
- @info[:media_id] = params["clip_id"].first if (params["clip_id"].first =~ /([0-9]*)/)
26
+ @info[:media_id] = params["clip_id"].first if (params["clip_id"].first =~ /([0-9]+)/)
24
27
  @info[:media_api_type] = VIMEO_VIDEO
25
28
  end
26
29
 
@@ -42,6 +45,7 @@ class Muri
42
45
  end
43
46
  end
44
47
  end
48
+ # http://www.vimeo.com/groups/beyondthestill/videos/9394829
45
49
  # http://vimeo.com/moogaloop.swf?clip_id=7312128&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1"
46
50
  # http://vimeo.com/7312128
47
51
  # http://vimeo.com/album/89702
@@ -20,10 +20,10 @@ class Muri
20
20
  if (@url.path =~ /\/watch$/i) && params.include?("v")
21
21
  @info[:media_id] = params["v"].first
22
22
  @info[:media_api_type] = YOUTUBE_VIDEO
23
- elsif (@url.path =~ /\/v\/([a-z0-9\-\_]*)/i)
23
+ elsif (@url.path =~ /\/v\/([a-z0-9\-\_]+)/i)
24
24
  @info[:media_id] = $1
25
25
  @info[:media_api_type] = YOUTUBE_VIDEO
26
- elsif (@url.path =~ /\/p\/([a-z0-9\-\_]*)/i)
26
+ elsif (@url.path =~ /\/p\/([a-z0-9\-\_]+)/i)
27
27
  @info[:media_id] = $1
28
28
  @info[:media_api_type] = YOUTUBE_PLAYLIST
29
29
  elsif (@url.path =~ /^\/view\_play\_list/i) && (params.include?('p'))
data/muri.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muri}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["William Schneider"]
12
- s.date = %q{2010-03-05}
12
+ s.date = %q{2010-03-09}
13
13
  s.description = %q{Automatically get media information from the URL.}
14
14
  s.email = %q{bananastalktome@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/muri/filters/flickr.rb",
28
28
  "lib/muri/filters/imageshack.rb",
29
29
  "lib/muri/filters/photobucket.rb",
30
+ "lib/muri/filters/twitpic.rb",
30
31
  "lib/muri/filters/vimeo.rb",
31
32
  "lib/muri/filters/youtube.rb",
32
33
  "muri.gemspec",
@@ -35,6 +36,7 @@ Gem::Specification.new do |s|
35
36
  "test/flickr_test.rb",
36
37
  "test/imageshack_test.rb",
37
38
  "test/photobucket_test.rb",
39
+ "test/twitpic_test.rb",
38
40
  "test/vimeo_test.rb",
39
41
  "test/youtube_test.rb"
40
42
  ]
@@ -49,6 +51,7 @@ Gem::Specification.new do |s|
49
51
  "test/flickr_test.rb",
50
52
  "test/imageshack_test.rb",
51
53
  "test/photobucket_test.rb",
54
+ "test/twitpic_test.rb",
52
55
  "test/vimeo_test.rb",
53
56
  "test/youtube_test.rb"
54
57
  ]
@@ -57,6 +57,6 @@ describe "Facebook parse second" do
57
57
  end
58
58
 
59
59
  it "should have media api id" do
60
- @a.media_api_id == { :pid => '34929102', :user_id => '15201063' }
60
+ @a.media_api_id == 65288068484364750
61
61
  end
62
62
  end
@@ -0,0 +1,42 @@
1
+ require 'lib/muri.rb'
2
+ shared_examples_for "Twitpic parse" do
3
+ it "should be Twitpic service" do
4
+ @a.service == 'Twitpic'
5
+ end
6
+ it "should be valid" do
7
+ @a.valid? == true
8
+ end
9
+ end
10
+
11
+ shared_examples_for "Twitpic parse photo" do
12
+ it_should_behave_like "Twitpic parse"
13
+ it "should have media api type = TWITPIC_PHOTO" do
14
+ @a.media_api_type == Muri::TWITPIC_PHOTO
15
+ end
16
+ end
17
+
18
+ describe "Twitpic parse first" do
19
+ before(:all) do
20
+ @a = Muri.parse 'http://twitpic.com/17d7th'
21
+ end
22
+ it_should_behave_like "Twitpic parse photo"
23
+ it "should have media id" do
24
+ @a.media_id == '17d7th'
25
+ end
26
+
27
+ it "should have a website" do
28
+ @a.website == "http://twitpic.com/17d7th"
29
+ end
30
+
31
+ it "should have media api id" do
32
+ @a.media_api_id == '17d7th'
33
+ end
34
+
35
+ it "should have media url" do
36
+ @a.media_url == "http://twitpic.com/show/large/17d7th"
37
+ end
38
+
39
+ it "should have a media thumbnail" do
40
+ @a.media_thumbnail == "http://twitpic.com/show/thumb/17d7th"
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Schneider
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-05 00:00:00 -05:00
12
+ date: 2010-03-09 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -33,6 +33,7 @@ files:
33
33
  - lib/muri/filters/flickr.rb
34
34
  - lib/muri/filters/imageshack.rb
35
35
  - lib/muri/filters/photobucket.rb
36
+ - lib/muri/filters/twitpic.rb
36
37
  - lib/muri/filters/vimeo.rb
37
38
  - lib/muri/filters/youtube.rb
38
39
  - muri.gemspec
@@ -41,6 +42,7 @@ files:
41
42
  - test/flickr_test.rb
42
43
  - test/imageshack_test.rb
43
44
  - test/photobucket_test.rb
45
+ - test/twitpic_test.rb
44
46
  - test/vimeo_test.rb
45
47
  - test/youtube_test.rb
46
48
  has_rdoc: true
@@ -77,5 +79,6 @@ test_files:
77
79
  - test/flickr_test.rb
78
80
  - test/imageshack_test.rb
79
81
  - test/photobucket_test.rb
82
+ - test/twitpic_test.rb
80
83
  - test/vimeo_test.rb
81
84
  - test/youtube_test.rb