muri 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile ADDED
@@ -0,0 +1,103 @@
1
+ h2. Media URI Parser - MURI
2
+
3
+ A simple to use media URI Parser. Pass a URI in, get helpful information out.
4
+
5
+ MURI Currently supports:
6
+ * Youtube (Single videos and Playlists)
7
+ ** "API documentation":http://code.google.com/apis/youtube/2.0/developers_guide_protocol_audience.html
8
+ * Vimeo (single videos and albums)
9
+ ** "API documentation":http://vimeo.com/api/docs/simple-api
10
+ * Flickr (single images and sets)
11
+ ** "API documentation":http://www.flickr.com/services/api/
12
+ * Imageshack
13
+ * Photobucket
14
+ ** "API documentation":http://photobucket.com/developer/documentation
15
+ * Facebook
16
+ ** "API documentation":http://wiki.developers.facebook.com/index.php/API
17
+
18
+ h3. Installation & basic usage
19
+
20
+ Install muri as a ruby gem (you might need to run this command as root by prepending @sudo@ to it):
21
+
22
+ <pre>
23
+ <code>
24
+ $ gem install muri
25
+ </code>
26
+ </pre>
27
+
28
+ Using muri is just as easy!
29
+
30
+ <pre>
31
+ <code>
32
+ a = Muri.parse('http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM')
33
+ </code>
34
+ </pre>
35
+
36
+ If @a.valid?@ you are good to go. If not, either the URI host was not recognized, or the path/parameters provided along with a known URI host were not recognized. When these two types of errors are encountered, an exception is caught and returned in @a.errors@ as either "Muri::NoParser" or "Muri::UnrecognizedURI". If you don't care about the type of error, just that the URI was not parsed, @a.valid?@ will give you a boolean answer.
37
+
38
+ Assuming the URI was successfully parsed (thus @a.valid? == true@), all media types share several common attributes:
39
+
40
+ <pre>
41
+ <code>
42
+ a.service # 'Youtube'
43
+ a.media_id # 'blahblahblah'
44
+ a.original_url # 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
45
+ a.uri # URI object for 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
46
+ </code>
47
+ </pre>
48
+
49
+ *Due to variations in information which can be gathered from a uri, some services provide more information than others. For example:*
50
+
51
+ * All but Imageshack have a @media_api_id@, which is the ID which can be used in API calls to the related services. Typically the same as @media_id@.
52
+
53
+ <pre>
54
+ <code>
55
+ a.media_api_id # 'blahblahblah'
56
+ </code>
57
+ </pre>
58
+
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)*
60
+
61
+ * 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
+
63
+ * A direct media url for Youtube, Photobucket, and Imageshack (@http://img#{num}.imageshack.us/img#{num}/#{NUMBER}/#{IMAGENAME}@ format)
64
+
65
+ <pre>
66
+ <code>
67
+ a.media_url # 'http://www.youtube.com/v/blahblahblah'
68
+ </code>
69
+ </pre>
70
+
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)
72
+
73
+ <pre>
74
+ <code>
75
+ a.website # 'http://www.youtube.com/watch?v=blahblahblah'
76
+ </code>
77
+ </pre>
78
+
79
+ * Content type for Imageshack, Photobucket and Flickr URI's (flickr in the @http://farm#{num}.static.flickr.com/@ format)
80
+
81
+ <pre>
82
+ <code>
83
+ a.content_type # 'jpg' (Content Type also for Imageshack and Photobucket)
84
+ </code>
85
+ </pre>
86
+
87
+ * Thumbnails URL for Youtube Photobucket, and Flickr (flickr in the @http://farm#{num}.static.flickr.com/@ format)
88
+
89
+ <pre>
90
+ <code>
91
+ a.media_thumbnail # 'http://i.ytimg.com/vi/4CYDFoEz8rg/default.jpg'
92
+ </code>
93
+ </pre>
94
+
95
+ *Some additional information may be provided, which can be determined by looking through each filters code.*
96
+
97
+
98
+ If an attribute is not present, muri returns @nil@.
99
+
100
+
101
+ h3. Contact
102
+
103
+ If you would like to get in contact with me, my email is bananastalktome@gmail.com. I appreciate any information or assistance reverse-engineering media website URI's. I plan on including more services _and_ more parse information with updates. That being said, MURI is currently not production quality. Please use with caution and in development only. Thank you.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 4
4
+ :patch: 5
data/lib/muri/base.rb CHANGED
@@ -15,6 +15,7 @@ class Muri
15
15
  include Filter::Vimeo
16
16
  include Filter::Imageshack
17
17
  include Filter::Photobucket
18
+ include Filter::Facebook
18
19
 
19
20
  def self.parse(url)
20
21
  self.new(url)
@@ -33,7 +34,7 @@ class Muri
33
34
  @info.to_s
34
35
  end
35
36
 
36
- def parsed?
37
+ def valid?
37
38
  @info[:media_id].nil? ? false : true
38
39
  end
39
40
 
@@ -50,21 +51,22 @@ class Muri
50
51
  private
51
52
 
52
53
  def _parse(raw_url)
53
- @url = URI.parse(raw_url)
54
- if @url.scheme.nil?
55
- raw_url = "http://#{raw_url}"
54
+ begin
56
55
  @url = URI.parse(raw_url)
56
+ if @url.scheme.nil?
57
+ raw_url = "http://#{raw_url}"
58
+ @url = URI.parse(raw_url)
59
+ end
60
+ if parser = determine_feed_parser
61
+ @info[:uri] = @url
62
+ @info[:original_url] = raw_url
63
+ send(PARSERS[parser])
64
+ else
65
+ raise NoParser
66
+ end
67
+ rescue NoParser, UnsupportedURI => e
68
+ @info[:errors] = "#{e}"
57
69
  end
58
- if parser = determine_feed_parser
59
- @info[:uri] = @url
60
- @info[:original_url] = raw_url
61
- send(PARSERS[parser])
62
- else
63
- raise NoParser.new("No Transformer found for URL")
64
- end
65
-
66
- #rescue => e
67
- #raise "failed #{e}"
68
70
  end
69
71
 
70
72
  def determine_feed_parser
@@ -72,11 +74,7 @@ class Muri
72
74
  end
73
75
 
74
76
  def method_missing(func, args = nil)
75
- #if @info[func.to_sym] != nil
76
- @info[func.to_sym].nil? ? nil : @info[func.to_sym]
77
- #else
78
- # nil #super(func,args)
79
- #end
77
+ @info[func.to_sym].nil? ? nil : @info[func.to_sym]
80
78
  end
81
79
 
82
80
  protected
@@ -0,0 +1,68 @@
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
+ class Muri
9
+ module Filter
10
+ module Facebook
11
+
12
+ FACEBOOK_PHOTO = "photo"
13
+ FACEBOOK_VIDEO = "video"
14
+
15
+ def self.included(base)
16
+ base.class_eval do
17
+ self::PARSERS[Muri::Filter::Facebook] = "facebook_parse"
18
+ end
19
+ end
20
+
21
+ def facebook_parse
22
+ @info[:service] = 'Facebook'
23
+ params = @url.query.nil? ? {} : CGI::parse(@url.query)
24
+ url_common = "http://www.facebook.com"
25
+
26
+ if @url.path =~ /^\/v\/([0-9]+)/
27
+ @info[:media_id] = $1
28
+ @info[:media_url] = "#{url_common}/v/#{@info[:media_id]}"
29
+
30
+ # Currently no API for video, but media_id is best guess value for such content
31
+ @info[:media_api_id] = @info[:media_id]
32
+ @info[:media_api_type] = FACEBOOK_VIDEO
33
+ elsif (@url.path =~ /^\/photo\.php/i)
34
+ if params.include?("pid") && params.include?("id") && params.include?("l")
35
+ @info[:media_api_type] = FACEBOOK_PHOTO
36
+ @info[:media_id] = params["pid"].first if (params["pid"].first =~ /([0-9]*)/)
37
+ media_creator = params["id"].first if (params["id"].first =~ /([0-9]*)/)
38
+ share_key = params["l"].first
39
+
40
+ @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 }
42
+ end
43
+ end
44
+
45
+ #if self.valid?
46
+ #@info[:media_api_id] = @info[:media_id]
47
+ #else
48
+ if !self.valid?
49
+ raise UnsupportedURI
50
+ end
51
+
52
+ self
53
+ end
54
+
55
+ def self.parsable?(uri)
56
+ uri.host =~ /^(www\.)?facebook\.com$/i
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+
63
+ # http://www.facebook.com/photo.php?pid=34929102&l=a1abf8cd37&id=15201063 (preview)
64
+ # pid = photo id
65
+ # id = user id
66
+ # l = photo share key
67
+ # http://www.facebook.com/v/614695029223 (full)
68
+ # http://www.facebook.com/album.php?aid=2149275&id=15201063&l=99900807c3
@@ -1,7 +1,10 @@
1
1
  class Muri
2
2
  module Filter
3
3
  module Flickr
4
-
4
+
5
+ FLICKR_PHOTO = "photo"
6
+ FLICKR_SET = "set"
7
+
5
8
  def self.included(base)
6
9
  base.class_eval do
7
10
  self::PARSERS[Muri::Filter::Flickr] = "flickr_parse"
@@ -11,13 +14,15 @@ class Muri
11
14
  def flickr_parse
12
15
  @info[:service] = 'Flickr'
13
16
 
14
- if @url.path =~ /^\/photos\/([a-z0-9\@]*?)\/([^(?:sets)][0-9]*)/i
15
- #@info[:media_creator] = $1
16
- @info[:media_id] = $2
17
+ if @url.path =~ /^\/photos\/([a-z0-9\-\_\@]*?)\/(sets\/)?([0-9]*)/i
18
+ media_creator = $1
19
+ @info[:media_id] = $3
20
+ @info[:media_api_type] = $2.nil? ? FLICKR_PHOTO : FLICKR_SET
17
21
  elsif (@url.host + @url.path) =~ /^farm([1-3])\.static.flickr.com\/([0-9]*?)\/([0-9]*?)\_([a-z0-9]*?)(\_[a-z]){0,1}\.([a-z]*)/i
18
22
  farm = $1
19
23
  server_id = $2
20
24
  @info[:media_id] = $3
25
+ @info[:media_api_type] = FLICKR_PHOTO
21
26
  media_secret = $4
22
27
  # if !$5.nil?
23
28
  # @info[:media_size] = case $5.downcase
@@ -32,20 +37,25 @@ class Muri
32
37
  @info[:media_thumbnail] = "http://farm#{farm}.static.flickr.com/#{server_id}/#{@info[:media_id]}_#{media_secret}_t.jpg"
33
38
  elsif (@url.host + @url.path) =~ /^flic\.kr\/p\/([a-z0-9]*)/i
34
39
  @info[:media_id] = self.class.decode58($1)
40
+ @info[:media_api_type] = FLICKR_PHOTO
35
41
  end
36
42
 
37
- if self.parsed?
43
+ if self.valid?
38
44
  @info[:media_api_id] = @info[:media_id]
39
- @info[:website] = "http://flic.kr/p/" + self.class.encode58(@info[:media_id].to_i)
45
+ if @info[:media_api_type] == FLICKR_PHOTO
46
+ @info[:website] = "http://flic.kr/p/" + self.class.encode58(@info[:media_id].to_i)
47
+ elsif @info[:media_api_type] == FLICKR_SET
48
+ @info[:website] = "http://www.flickr.com/photos/#{media_creator}/sets/#{@info[:media_id]}"
49
+ end
40
50
  else
41
- raise UnsupportedURI
51
+ raise UnsupportedURI
42
52
  end
43
53
 
44
54
  self
45
55
  end
46
56
 
47
57
  def self.parsable?(uri)
48
- uri.host =~ /^(www\.|)(flic\.kr|(farm[0-9]\.static\.|)(flickr)\.com)/i
58
+ uri.host =~ /^(www\.)?(flic\.kr|(farm[0-9]\.static\.|)(flickr)\.com)/i
49
59
  end
50
60
 
51
61
 
@@ -60,4 +70,5 @@ end
60
70
  # photo-id: 2088436532
61
71
  # secret: ee07b4474e
62
72
  # size: m
63
- # * add _d before .jpg in url to create a download URL
73
+ # * add _d before .jpg in url to create a download URL
74
+ # http://www.flickr.com/photos/bananastalktome/sets/72157623467777820/ (set preview)
@@ -26,7 +26,7 @@ class Muri
26
26
  end
27
27
 
28
28
  # imageshack does not currently have API for retrieving individual video information
29
- if self.parsed?
29
+ if self.valid?
30
30
  @info[:website] = "#{url_common}/i/#{@info[:media_id]}.#{@info[:content_type]}/"
31
31
  else
32
32
  raise UnsupportedURI
@@ -2,6 +2,8 @@ class Muri
2
2
  module Filter
3
3
  module Photobucket
4
4
 
5
+ PHOTOBUCKET_MEDIA = "media"
6
+
5
7
  def self.included(base)
6
8
  base.class_eval do
7
9
  self::PARSERS[Muri::Filter::Photobucket] = "photobucket_parse"
@@ -37,7 +39,8 @@ class Muri
37
39
  @info[:website] = "http://gs#{url_common}/?action=view&current=#{@info[:media_id]}.#{@info[:content_type]}"
38
40
  end
39
41
 
40
- if self.parsed?
42
+ if self.valid?
43
+ @info[:media_api_type] = PHOTOBUCKET_MEDIA
41
44
  @info[:media_api_id] = @info[:media_url]
42
45
  @info[:media_thumbnail] = "http://mobth#{direct_url_suffix}"
43
46
  else
@@ -2,7 +2,10 @@ require 'cgi'
2
2
  class Muri
3
3
  module Filter
4
4
  module Vimeo
5
-
5
+
6
+ VIMEO_VIDEO = "video"
7
+ VIMEO_ALBUM = "album"
8
+
6
9
  def self.included(base)
7
10
  base.class_eval do
8
11
  self::PARSERS[Muri::Filter::Vimeo] = "vimeo_parse"
@@ -11,17 +14,20 @@ class Muri
11
14
 
12
15
  def vimeo_parse
13
16
  @info[:service] = 'Vimeo'
14
- params = CGI::parse(@url.query) if !@url.query.nil?
15
-
16
- if @url.path =~ /^\/([0-9]+)/
17
- @info[:media_id] = $1
17
+ params = @url.query.nil? ? {} : CGI::parse(@url.query)
18
+
19
+ if @url.path =~ /^\/(album\/)?([0-9]+)(\/)?$/i
20
+ @info[:media_id] = $2
21
+ @info[:media_api_type] = $1.nil? ? VIMEO_VIDEO : VIMEO_ALBUM
18
22
  elsif ((@url.path =~ /^\/moogaloop\.swf/i) && (params.include?("clip_id")))
19
23
  @info[:media_id] = params["clip_id"].first if (params["clip_id"].first =~ /([0-9]*)/)
24
+ @info[:media_api_type] = VIMEO_VIDEO
20
25
  end
21
26
 
22
- if self.parsed?
27
+ if self.valid?
23
28
  @info[:media_api_id] = @info[:media_id]
24
- @info[:website] = "http://vimeo.com/#{@info[:media_id]}"
29
+ album = (@info[:media_api_type] == VIMEO_ALBUM) ? "album/" : ""
30
+ @info[:website] = "http://vimeo.com/#{album}#{@info[:media_id]}"
25
31
  else
26
32
  raise UnsupportedURI
27
33
  end
@@ -37,4 +43,5 @@ class Muri
37
43
  end
38
44
  end
39
45
  # 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"
40
- # http://vimeo.com/7312128
46
+ # http://vimeo.com/7312128
47
+ # http://vimeo.com/album/89702
@@ -3,6 +3,9 @@ class Muri
3
3
  module Filter
4
4
  module Youtube
5
5
 
6
+ YOUTUBE_VIDEO = "video"
7
+ YOUTUBE_PLAYLIST = "playlist"
8
+
6
9
  def self.included(base)
7
10
  base.class_eval do
8
11
  self::PARSERS[Muri::Filter::Youtube] = "youtube_parse"
@@ -12,30 +15,47 @@ class Muri
12
15
  def youtube_parse
13
16
  @info[:service] = 'Youtube'
14
17
  url_common = "http://www.youtube.com"
18
+ params = @url.query.nil? ? {} : CGI::parse(@url.query)
15
19
 
16
- if (@url.path == "/watch") && !@url.query.nil?
17
- params = CGI::parse(@url.query)
20
+ if (@url.path =~ /\/watch$/i) && params.include?("v")
18
21
  @info[:media_id] = params["v"].first
22
+ @info[:media_api_type] = YOUTUBE_VIDEO
19
23
  elsif (@url.path =~ /\/v\/([a-z0-9\-\_]*)/i)
20
24
  @info[:media_id] = $1
25
+ @info[:media_api_type] = YOUTUBE_VIDEO
26
+ elsif (@url.path =~ /\/p\/([a-z0-9\-\_]*)/i)
27
+ @info[:media_id] = $1
28
+ @info[:media_api_type] = YOUTUBE_PLAYLIST
29
+ elsif (@url.path =~ /^\/view\_play\_list/i) && (params.include?('p'))
30
+ @info[:media_id] = params['p'].first
31
+ @info[:media_api_type] = YOUTUBE_PLAYLIST
21
32
  end
22
33
 
23
- if self.parsed?
24
- @info[:website] = "#{url_common}/watch?v=#{@info[:media_id]}"
25
- @info[:media_url] = "#{url_common}/v/#{@info[:media_id]}"
34
+ if self.valid?
35
+ if @info[:media_api_type] == YOUTUBE_VIDEO
36
+ @info[:website] = "#{url_common}/watch?v=#{@info[:media_id]}"
37
+ @info[:media_url] = "#{url_common}/v/#{@info[:media_id]}"
38
+ @info[:media_thumbnail] = "http://i.ytimg.com/vi/#{@info[:media_id]}/default.jpg"
39
+ elsif @info[:media_api_type] == YOUTUBE_PLAYLIST
40
+ @info[:website] = "#{url_common}/view_play_list?p=#{@info[:media_id]}"
41
+ @info[:media_url] = "#{url_common}/p/#{@info[:media_id]}"
42
+ end
26
43
  @info[:media_api_id] = @info[:media_id]
27
- @info[:media_thumbnail] = "http://i.ytimg.com/vi/#{@info[:media_id]}/default.jpg"
28
44
  else
29
- raise UnsupportedURI
45
+ raise UnsupportedURI
30
46
  end
31
47
 
32
48
  self
33
49
  end
34
50
  def self.parsable?(uri)
35
- uri.host =~ /^(www\.|)youtube\.com$/i
51
+ uri.host =~ /^(www\.)?youtube\.com$/i
36
52
  end
37
53
  end
38
54
  end
39
55
  end
40
56
  # http://www.youtube.com/v/4CYDFoEz8rg&hl=en_US&fs=1& (direct)
41
- # http://www.youtube.com/watch?v=l983Uob0Seo&feature=rec-LGOUT-exp_fresh+div-1r-1-HM (preview)
57
+ # http://www.youtube.com/watch?v=l983Uob0Seo&feature=rec-LGOUT-exp_fresh+div-1r-1-HM (preview)
58
+
59
+ # PLAYLISTS
60
+ # http://www.youtube.com/p/57633EC69B4A10A2&hl=en_US&fs=1 (direct)
61
+ # http://www.youtube.com/view_play_list?p=57633EC69B4A10A2 (preview)
data/lib/muri.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # Register built-in filters
2
- #
3
2
  Dir["#{File.dirname(__FILE__) + '/muri/filters'}/**/*"].each do |filter|
4
3
  require "#{filter}"
5
4
  end
6
5
 
6
+ # Just base now..more later(?)
7
7
  %w(base).each do |f|
8
8
  require File.dirname(__FILE__) + "/muri/#{f}"
9
9
  end
10
-
10
+
data/muri.gemspec CHANGED
@@ -5,24 +5,25 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muri}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
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-02}
12
+ s.date = %q{2010-03-05}
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 = [
16
- "README.rdoc"
16
+ "README.textile"
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
- "README.rdoc",
20
+ "README.textile",
21
21
  "Rakefile",
22
22
  "VERSION.yml",
23
23
  "lib/muri.rb",
24
24
  "lib/muri/base.rb",
25
25
  "lib/muri/filter.rb",
26
+ "lib/muri/filters/facebook.rb",
26
27
  "lib/muri/filters/flickr.rb",
27
28
  "lib/muri/filters/imageshack.rb",
28
29
  "lib/muri/filters/photobucket.rb",
@@ -30,6 +31,7 @@ Gem::Specification.new do |s|
30
31
  "lib/muri/filters/youtube.rb",
31
32
  "muri.gemspec",
32
33
  "test/error_test.rb",
34
+ "test/facebook_test.rb",
33
35
  "test/flickr_test.rb",
34
36
  "test/imageshack_test.rb",
35
37
  "test/photobucket_test.rb",
@@ -42,11 +44,12 @@ Gem::Specification.new do |s|
42
44
  s.rubygems_version = %q{1.3.5}
43
45
  s.summary = %q{Media URI Parser}
44
46
  s.test_files = [
45
- "test/photobucket_test.rb",
46
- "test/vimeo_test.rb",
47
- "test/imageshack_test.rb",
48
- "test/error_test.rb",
47
+ "test/error_test.rb",
48
+ "test/facebook_test.rb",
49
49
  "test/flickr_test.rb",
50
+ "test/imageshack_test.rb",
51
+ "test/photobucket_test.rb",
52
+ "test/vimeo_test.rb",
50
53
  "test/youtube_test.rb"
51
54
  ]
52
55
 
data/test/error_test.rb CHANGED
@@ -13,14 +13,20 @@ describe "Parse Errors" do
13
13
  "http://vimeo.com/moogaloop.swf?server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1"]
14
14
 
15
15
  @no_parser.each do |a|
16
- it "#{a} should raise NoParser" do
17
- lambda { Muri.parse a }.should raise_exception(Muri::NoParser)
16
+ it "#{a} should return NoParser" do
17
+ #lambda { Muri.parse a }.should raise_exception(Muri::NoParser)
18
+ m = Muri.parse a
19
+ m.valid? == false
20
+ m.errors == "Muri::NoParser"
18
21
  end
19
22
  end
20
23
 
21
24
  @unsupported.each do |b|
22
- it "#{b} should raise UnsupportedURI" do
23
- lambda { Muri.parse b }.should raise_exception(Muri::UnsupportedURI)
25
+ it "#{b} should return UnsupportedURI" do
26
+ #lambda { Muri.parse b }.should raise_exception(Muri::UnsupportedURI)
27
+ m = Muri.parse b
28
+ m.valid? == false
29
+ m.errors == "Muri::UnsupportedURI"
24
30
  end
25
31
  end
26
32
 
@@ -0,0 +1,62 @@
1
+ require 'lib/muri.rb'
2
+
3
+ shared_examples_for "Facebook parse" do
4
+ it "should be Facebook service" do
5
+ @a.service == 'Facebook'
6
+ end
7
+
8
+ it "should be valid" do
9
+ @a.valid? == true
10
+ end
11
+ end
12
+ shared_examples_for "Facebook parse photo" do
13
+ it_should_behave_like "Facebook parse"
14
+ it "should have media api type = FACEBOOK_PHOTO" do
15
+ @a.media_api_type == Muri::FACEBOOK_PHOTO
16
+ end
17
+ end
18
+
19
+ shared_examples_for "Facebook parse video" do
20
+ it_should_behave_like "Facebook parse"
21
+ it "should have media api type = FACEBOOK_VIDEO" do
22
+ @a.media_api_type == Muri::FACEBOOK_VIDEO
23
+ end
24
+ end
25
+
26
+ describe "Facebook parse first" do
27
+ before(:all) do
28
+ @a = Muri.parse 'http://www.facebook.com/v/614695029223'
29
+ end
30
+ it_should_behave_like "Facebook parse video"
31
+
32
+ it "should have media id" do
33
+ @a.media_id == '614695029223'
34
+ end
35
+
36
+ it "should have a media_url" do
37
+ @a.website == 'http://www.facebook.com/v/614695029223'
38
+ end
39
+
40
+ it "should have media api id" do
41
+ @a.media_api_id == '614695029223'
42
+ end
43
+ end
44
+
45
+ describe "Facebook parse second" do
46
+ before(:all) do
47
+ @a = Muri.parse 'http://www.facebook.com/photo.php?pid=34929102&l=a1abf8cd37&id=15201063'
48
+ end
49
+ it_should_behave_like "Facebook parse photo"
50
+
51
+ it "should have media id" do
52
+ @a.media_id == '34929102'
53
+ end
54
+
55
+ it "should have a website" do
56
+ @a.website == 'http://www.facebook.com/photo.php?pid=34929102&l=a1abf8cd37&id=15201063'
57
+ end
58
+
59
+ it "should have media api id" do
60
+ @a.media_api_id == { :pid => '34929102', :user_id => '15201063' }
61
+ end
62
+ end
data/test/flickr_test.rb CHANGED
@@ -1,10 +1,32 @@
1
1
  require 'lib/muri.rb'
2
-
3
2
  shared_examples_for "Flickr parse" do
4
3
  it "should be Flickr service" do
5
4
  @a.service == 'Flickr'
6
5
  end
7
-
6
+ it "should be valid" do
7
+ @a.valid? == true
8
+ end
9
+ end
10
+
11
+ shared_examples_for "Flickr parse photo" do
12
+ it_should_behave_like "Flickr parse"
13
+ it "should have media api type = FLICKR_PHOTO" do
14
+ @a.media_api_type == Muri::FLICKR_PHOTO
15
+ end
16
+ end
17
+
18
+ shared_examples_for "Flickr parse set" do
19
+ it_should_behave_like "Flickr parse"
20
+ it "should have media api type = FLICKR_SET" do
21
+ @a.media_api_type == Muri::FLICKR_SET
22
+ end
23
+ end
24
+
25
+ describe "Flickr parse first" do
26
+ before(:all) do
27
+ @a = Muri.parse 'http://www.flickr.com/photos/bananastalktome/2088436532/'
28
+ end
29
+ it_should_behave_like "Flickr parse photo"
8
30
  it "should have media id" do
9
31
  @a.media_id == '2088436532'
10
32
  end
@@ -15,21 +37,45 @@ shared_examples_for "Flickr parse" do
15
37
 
16
38
  it "should have media api id" do
17
39
  @a.media_api_id == '2088436532'
18
- end
19
- end
20
- describe "Flickr parse first" do
21
- before(:all) do
22
- @a = Muri.parse 'http://www.flickr.com/photos/bananastalktome/2088436532/'
23
- end
24
- it_should_behave_like "Flickr parse"
40
+ end
25
41
  end
26
42
  describe "Flickr parse second" do
27
43
  before(:all) do
28
44
  @a = Muri.parse 'http://farm3.static.flickr.com/2178/2088436532_ee07b4474e_m.jpg'
29
45
  end
30
- it_should_behave_like "Flickr parse"
46
+ it_should_behave_like "Flickr parse photo"
47
+ it "should have media id" do
48
+ @a.media_id == '2088436532'
49
+ end
31
50
 
51
+ it "should have a website" do
52
+ @a.website == 'http://flic.kr/p/4bxMqq'
53
+ end
54
+
55
+ it "should have media api id" do
56
+ @a.media_api_id == '2088436532'
57
+ end
32
58
  it "should have media thumbnail" do
33
59
  @a.media_thumbnail == 'http://farm3.static.flickr.com/2178/2088436532_ee07b4474e_t.jpg'
34
60
  end
35
- end
61
+ end
62
+
63
+ describe "Flickr parse set first" do
64
+ before(:all) do
65
+ @a = Muri.parse 'http://www.flickr.com/photos/bananastalktome/sets/72157623467777820/'
66
+ end
67
+ it_should_behave_like "Flickr parse set"
68
+
69
+ it "should have media id" do
70
+ @a.media_id == '72157623467777820'
71
+ end
72
+
73
+ it "should have a website" do
74
+ @a.website == 'http://www.flickr.com/photos/bananastalktome/sets/72157623467777820'
75
+ end
76
+
77
+ it "should have media api id" do
78
+ @a.media_api_id == '72157623467777820'
79
+ end
80
+ end
81
+
@@ -4,24 +4,28 @@ shared_examples_for "Imageshack parse" do
4
4
  it "should be Imageshack service" do
5
5
  @a.service == 'Imageshack'
6
6
  end
7
+ it "should be valid" do
8
+ @a.valid? == true
9
+ end
10
+ end
11
+
12
+ describe "Imageshack parse first" do
13
+ before(:all) do
14
+ @a = Muri.parse 'http://img178.imageshack.us/i/dsc01576lo7.jpg/'
15
+ end
16
+ it_should_behave_like "Imageshack parse"
7
17
 
8
18
  it "should have media id" do
9
19
  @a.media_id == 'dsc01576lo7'
10
20
  end
11
21
 
12
- it "should have media url" do
22
+ it "should have website" do
13
23
  @a.website == 'http://img178.imageshack.us/i/dsc01576lo7.jpg/'
14
24
  end
15
25
 
16
26
  it "should have content_type" do
17
27
  @a.content_type == 'jpg'
18
- end
19
- end
20
- describe "Imageshack parse first" do
21
- before(:all) do
22
- @a = Muri.parse 'http://img178.imageshack.us/i/dsc01576lo7.jpg/'
23
- end
24
- it_should_behave_like "Imageshack parse"
28
+ end
25
29
  end
26
30
  describe "Imageshack parse second" do
27
31
  before(:all) do
@@ -29,6 +33,18 @@ describe "Imageshack parse second" do
29
33
  end
30
34
  it_should_behave_like "Imageshack parse"
31
35
 
36
+ it "should have media id" do
37
+ @a.media_id == 'dsc01576lo7'
38
+ end
39
+
40
+ it "should have website" do
41
+ @a.website == 'http://img178.imageshack.us/i/dsc01576lo7.jpg/'
42
+ end
43
+
44
+ it "should have content_type" do
45
+ @a.content_type == 'jpg'
46
+ end
47
+
32
48
  it "should have website" do
33
49
  @a.media_url == 'http://img178.imageshack.us/img178/773/dsc01576lo7.jpg'
34
50
  end
@@ -4,7 +4,16 @@ shared_examples_for "Photobucket parse" do
4
4
  it "should be Photobucket service" do
5
5
  @a.service == 'Photobucket'
6
6
  end
7
+
8
+ it "should be valid" do
9
+ @a.valid? == true
10
+ end
11
+
12
+ it "should have media api type = PHOTOBUCKET_MEDIA" do
13
+ @a.api_media_type == Muri::PHOTOBUCKET_MEDIA
14
+ end
7
15
  end
16
+
8
17
  describe "Photobucket parse first" do
9
18
  before(:all) do
10
19
  @a = Muri.parse 'http://i244.photobucket.com/albums/gg17/pbapi/file.jpg'
@@ -35,6 +44,7 @@ describe "Photobucket parse first" do
35
44
  @a.media_thumbnail == 'http://mobth244.photobucket.com/albums/gg17/pbapi/file.jpg'
36
45
  end
37
46
  end
47
+
38
48
  describe "Photobucket parse second" do
39
49
  before(:all) do
40
50
  @a = Muri.parse 'http://gi0006.photobucket.com/groups/0006/G5PAK3TBQS/DSCF0015-1-1.jpg'
data/test/vimeo_test.rb CHANGED
@@ -5,6 +5,33 @@ shared_examples_for "Vimeo parse" do
5
5
  @a.service == 'Vimeo'
6
6
  end
7
7
 
8
+ it "should be valid" do
9
+ @a.valid? == true
10
+ end
11
+
12
+ end
13
+
14
+ shared_examples_for "Vimeo parse video" do
15
+ it_should_behave_like "Vimeo parse"
16
+
17
+ it "should have media api type = VIMEO_VIDEO" do
18
+ @a.media_api_type == Muri::VIMEO_VIDEO
19
+ end
20
+ end
21
+ shared_examples_for "Vimeo parse album" do
22
+ it_should_behave_like "Vimeo parse"
23
+
24
+ it "should have media api type = VIMEO_ALBUM" do
25
+ @a.media_api_type == Muri::VIMEO_ALBUM
26
+ end
27
+ end
28
+
29
+ describe "Vimeo parse first" do
30
+ before(:all) do
31
+ @a = Muri.parse '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'
32
+ end
33
+ it_should_behave_like "Vimeo parse video"
34
+
8
35
  it "should have media id" do
9
36
  @a.media_id == '7312128'
10
37
  end
@@ -17,15 +44,41 @@ shared_examples_for "Vimeo parse" do
17
44
  @a.media_api_id == '7312128'
18
45
  end
19
46
  end
20
- describe "Vimeo parse first" do
47
+
48
+ describe "Vimeo parse second" do
21
49
  before(:all) do
22
- @a = Muri.parse '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'
50
+ @a = Muri.parse 'http://vimeo.com/7312128'
51
+ end
52
+ it_should_behave_like "Vimeo parse video"
53
+
54
+ it "should have media id" do
55
+ @a.media_id == '7312128'
56
+ end
57
+
58
+ it "should have a website" do
59
+ @a.website == 'http://vimeo.com/7312128'
60
+ end
61
+
62
+ it "should have media api id" do
63
+ @a.media_api_id == '7312128'
23
64
  end
24
- it_should_behave_like "Vimeo parse"
25
65
  end
26
- describe "Vimeo parse second" do
66
+
67
+ describe "Vimeo parse album first" do
27
68
  before(:all) do
28
- @a = Muri.parse 'http://vimeo.com/7312128'
69
+ @a = Muri.parse 'http://vimeo.com/album/89702'
29
70
  end
30
- it_should_behave_like "Vimeo parse"
31
- end
71
+ it_should_behave_like "Vimeo parse album"
72
+
73
+ it "should have media id" do
74
+ @a.media_id == '89702'
75
+ end
76
+
77
+ it "should have a website" do
78
+ @a.website == 'http://vimeo.com/album/89702'
79
+ end
80
+
81
+ it "should have media api id" do
82
+ @a.media_api_id == '89702'
83
+ end
84
+ end
data/test/youtube_test.rb CHANGED
@@ -1,10 +1,36 @@
1
1
  require 'lib/muri.rb'
2
-
3
2
  shared_examples_for "Youtube parse" do
4
3
  it "should be Youtube service" do
5
4
  @a.service == 'Youtube'
6
5
  end
7
6
 
7
+ it "should be valid" do
8
+ @a.valid? == true
9
+ end
10
+ end
11
+
12
+ shared_examples_for "Youtube parse single" do
13
+ it_should_behave_like "Youtube parse"
14
+
15
+ it "should have media api type = YOUTUBE_VIDEO" do
16
+ @a.media_api_type == Muri::YOUTUBE_VIDEO
17
+ end
18
+ end
19
+
20
+ shared_examples_for "Youtube parse playlist" do
21
+ it_should_behave_like "Youtube parse"
22
+
23
+ it "should have media api type = YOUTUBE_PLAYLIST" do
24
+ @a.media_api_type == Muri::YOUTUBE_PLAYLIST
25
+ end
26
+ end
27
+
28
+ describe "Youtube parse first" do
29
+ before(:all) do
30
+ @a = Muri.parse 'http://www.youtube.com/v/4CYDFoEz8rg&hl=en_US&fs=1&'
31
+ end
32
+ it_should_behave_like "Youtube parse single"
33
+
8
34
  it "should have media id" do
9
35
  @a.media_id == '4CYDFoEz8rg'
10
36
  end
@@ -23,17 +49,75 @@ shared_examples_for "Youtube parse" do
23
49
 
24
50
  it "should have thumbnail" do
25
51
  @a.media_thumbnail == 'http://i.ytimg.com/vi/4CYDFoEz8rg/default.jpg'
52
+ end
53
+ end
54
+ describe "Youtube parse second" do
55
+ before(:all) do
56
+ @a = Muri.parse 'http://www.youtube.com/watch?v=4CYDFoEz8rg'
57
+ end
58
+ it_should_behave_like "Youtube parse single"
59
+
60
+ it "should have media id" do
61
+ @a.media_id == '4CYDFoEz8rg'
62
+ end
63
+
64
+ it "should have media api id" do
65
+ @a.media_api_id == '4CYDFoEz8rg'
66
+ end
67
+
68
+ it "should have media url" do
69
+ @a.website == 'http://www.youtube.com/watch?v=4CYDFoEz8rg'
70
+ end
71
+
72
+ it "should have website" do
73
+ @a.media_url == 'http://www.youtube.com/v/4CYDFoEz8rg'
26
74
  end
75
+
76
+ it "should have thumbnail" do
77
+ @a.media_thumbnail == 'http://i.ytimg.com/vi/4CYDFoEz8rg/default.jpg'
78
+ end
27
79
  end
28
- describe "Youtube parse first" do
80
+
81
+ describe "Youtube parse playlist first" do
29
82
  before(:all) do
30
- @a = Muri.parse 'http://www.youtube.com/v/4CYDFoEz8rg&hl=en_US&fs=1&'
83
+ @a = Muri.parse 'http://www.youtube.com/p/57633EC69B4A10A2&hl=en_US&fs=1'
31
84
  end
32
- it_should_behave_like "Youtube parse"
85
+ it_should_behave_like "Youtube parse playlist"
86
+ it "should have media id" do
87
+ @a.media_id == '57633EC69B4A10A2'
88
+ end
89
+
90
+ it "should have media api id" do
91
+ @a.media_api_id == '57633EC69B4A10A2'
92
+ end
93
+
94
+ it "should have media url" do
95
+ @a.website == 'http://www.youtube.com/view_play_list?p=57633EC69B4A10A2'
96
+ end
97
+
98
+ it "should have website" do
99
+ @a.media_url == 'http://www.youtube.com/p/57633EC69B4A10A2'
100
+ end
33
101
  end
34
- describe "Youtube parse second" do
102
+
103
+ describe "Youtube parse playlist second" do
35
104
  before(:all) do
36
- @a = Muri.parse 'http://www.youtube.com/watch?v=4CYDFoEz8rg'
105
+ @a = Muri.parse 'http://www.youtube.com/view_play_list?p=57633EC69B4A10A2'
37
106
  end
38
- it_should_behave_like "Youtube parse"
39
- end
107
+ it_should_behave_like "Youtube parse playlist"
108
+ it "should have media id" do
109
+ @a.media_id == '57633EC69B4A10A2'
110
+ end
111
+
112
+ it "should have media api id" do
113
+ @a.media_api_id == '57633EC69B4A10A2'
114
+ end
115
+
116
+ it "should have media url" do
117
+ @a.website == 'http://www.youtube.com/view_play_list?p=57633EC69B4A10A2'
118
+ end
119
+
120
+ it "should have website" do
121
+ @a.media_url == 'http://www.youtube.com/p/57633EC69B4A10A2'
122
+ end
123
+ 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.4
4
+ version: 0.0.5
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-02 00:00:00 -05:00
12
+ date: 2010-03-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,15 +20,16 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.rdoc
23
+ - README.textile
24
24
  files:
25
25
  - .gitignore
26
- - README.rdoc
26
+ - README.textile
27
27
  - Rakefile
28
28
  - VERSION.yml
29
29
  - lib/muri.rb
30
30
  - lib/muri/base.rb
31
31
  - lib/muri/filter.rb
32
+ - lib/muri/filters/facebook.rb
32
33
  - lib/muri/filters/flickr.rb
33
34
  - lib/muri/filters/imageshack.rb
34
35
  - lib/muri/filters/photobucket.rb
@@ -36,6 +37,7 @@ files:
36
37
  - lib/muri/filters/youtube.rb
37
38
  - muri.gemspec
38
39
  - test/error_test.rb
40
+ - test/facebook_test.rb
39
41
  - test/flickr_test.rb
40
42
  - test/imageshack_test.rb
41
43
  - test/photobucket_test.rb
@@ -70,9 +72,10 @@ signing_key:
70
72
  specification_version: 3
71
73
  summary: Media URI Parser
72
74
  test_files:
73
- - test/photobucket_test.rb
74
- - test/vimeo_test.rb
75
- - test/imageshack_test.rb
76
75
  - test/error_test.rb
76
+ - test/facebook_test.rb
77
77
  - test/flickr_test.rb
78
+ - test/imageshack_test.rb
79
+ - test/photobucket_test.rb
80
+ - test/vimeo_test.rb
78
81
  - test/youtube_test.rb
data/README.rdoc DELETED
@@ -1,56 +0,0 @@
1
- = Media URI Parser - MURI
2
-
3
- A simple to use media URI Parser. Pass a URI in, get helpful information out.
4
-
5
- MURI Currently supports:
6
- * Youtube
7
- * Vimeo
8
- * Flickr
9
- * Imageshack
10
- * Photobucket
11
-
12
- == Installation & basic usage
13
-
14
- Install muri as a ruby gem (you might need to run this command as root by prepending +sudo+ to it):
15
-
16
- $ gem install muri
17
-
18
- Using muri is just as easy!
19
-
20
- a = Muri.parse('http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM')
21
- a.service # 'Youtube'
22
- a.media_id # 'blahblahblah'
23
- a.original_url # 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
24
- a.uri # URI object for 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
25
-
26
- Due to variations in information which can be gathered from a uri, some services provide more information than others. For example:
27
- * All but Imageshack have a +media_api_id+, which is the ID which can be used in API calls to the related services. Typically the same as +media_id+.
28
-
29
- a.media_api_id # 'blahblahblah'
30
-
31
- * A direct media url for Youtube, Photobucket, and Imageshack (img#{num}.imageshack.us/img#{num}/#{NUMBER}/#{IMAGENAME} format)
32
-
33
- a.media_url # 'http://www.youtube.com/v/blahblahblah'
34
-
35
- * A media landing website url for Youtube, Photobucket, Imageshack, Vimeo, and Flickr (flickr media_url's provide the flic.kr/p/ID short url)
36
-
37
- a.website # 'http://www.youtube.com/watch?v=blahblahblah'
38
-
39
- * Content type for Imageshack, Photobucket and Flickr URI's (flickr in the farm#{num}.static.flickr.com/ format)
40
-
41
- a.content_type # 'jpg' (Content Type also for Imageshack and Photobucket)
42
-
43
- * Thumbnails URL for Youtube Photobucket, and Flickr (flickr in the farm#{num}.static.flickr.com/ format)
44
-
45
- a.media_thumbnail # 'http://i.ytimg.com/vi/4CYDFoEz8rg/default.jpg'
46
-
47
- * Some additional information may be provided, which can be determined by looking through each filters code.
48
-
49
-
50
- If an attribute is not present, muri returns +nil+.
51
-
52
- I plan on including more services _and_ more parse information with updates. That being said, MURI is currently not production quality. Please use with caution and in development only. Thank you.
53
-
54
- == Contact
55
-
56
- If you would like to get in contact with me, my email is bananastalktome@gmail.com. I appreciate any information or assistance reverse-engineering media website URI's.