muri 0.0.1 → 0.0.2
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/README.rdoc +42 -0
- data/Rakefile +2 -2
- data/VERSION.yml +1 -1
- data/lib/muri/base.rb +15 -15
- data/lib/muri/filters/flickr.rb +9 -12
- data/lib/muri/filters/vimeo.rb +22 -18
- data/lib/muri/filters/youtube.rb +9 -8
- data/muri.gemspec +4 -5
- metadata +4 -5
- data/README +0 -0
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
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
|
+
|
10
|
+
== Installation & basic usage
|
11
|
+
|
12
|
+
Install muri as a ruby gem (you might need to run this command as root by prepending +sudo+ to it):
|
13
|
+
|
14
|
+
$ gem install muri
|
15
|
+
|
16
|
+
Using muri is just as easy!
|
17
|
+
|
18
|
+
a = Muri.parse('http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM')
|
19
|
+
a.service # 'Youtube'
|
20
|
+
a.media_id # 'blahblahblah'
|
21
|
+
a.media_url # 'http://www.youtube.com/watch?v=blahblahblah' (flickr media_url's provide the flic.kr/p/ID short url)
|
22
|
+
a.original_url # 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
|
23
|
+
a.uri # Parsed URI object for 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
|
24
|
+
|
25
|
+
Due to variations in information which can be gathered from a uri, some services provide more information than others. For example:
|
26
|
+
* A direct media url for Youtube videos
|
27
|
+
a.url # 'http://www.youtube.com/v/blahblahblah'
|
28
|
+
|
29
|
+
* Media creator name for Flickr URI's (for uri's in the http://www.flickr.com/photos/USER/PHOTO-ID/ format)
|
30
|
+
a.media_creator # 'bananastalktome'
|
31
|
+
|
32
|
+
* Media size and content type for Flickr URI's (for uri's in the http://farm3.static.flickr.com/NUMBERS/MORE-NUMBERS_LETTERS-AND-NUMBERS_SIZE-INDICATOR.jpg
|
33
|
+
a.media_size # 'small'
|
34
|
+
a.content_type # 'jpg'
|
35
|
+
|
36
|
+
If an attribute is not present, muri returns +nil+.
|
37
|
+
|
38
|
+
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.
|
39
|
+
|
40
|
+
== Contact
|
41
|
+
|
42
|
+
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.
|
data/Rakefile
CHANGED
@@ -2,13 +2,13 @@ begin
|
|
2
2
|
require 'jeweler'
|
3
3
|
Jeweler::Tasks.new do |gem|
|
4
4
|
gem.name = "muri"
|
5
|
-
gem.summary =
|
5
|
+
gem.summary = "Media URI Parser"
|
6
6
|
gem.email = "bananastalktome@gmail.com"
|
7
7
|
gem.homepage = "http://github.com/bananastalktome/muri/"
|
8
8
|
gem.description = "Automatically get media information from the URL."
|
9
9
|
gem.authors = ["William Schneider"]
|
10
10
|
gem.files.exclude 'test.sqlite3'
|
11
|
-
gem.has_rdoc =
|
11
|
+
gem.has_rdoc = true
|
12
12
|
end
|
13
13
|
rescue LoadError
|
14
14
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
data/lib/muri/base.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'uri'
|
2
|
-
class
|
3
|
-
class
|
2
|
+
class Muri
|
3
|
+
class NoParser < StandardError; end
|
4
4
|
|
5
5
|
PARSERS = { }
|
6
|
-
|
6
|
+
|
7
7
|
include Filter::Youtube
|
8
8
|
include Filter::Flickr
|
9
9
|
include Filter::Vimeo
|
@@ -24,11 +24,15 @@ class MURI
|
|
24
24
|
def to_s
|
25
25
|
@info.to_s
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
def parsed?
|
29
|
+
@info[:media_id].nil? ? false : true
|
30
|
+
end
|
31
|
+
|
28
32
|
# Taken from uri/generic.rb
|
29
33
|
@@to_s = Kernel.instance_method(:to_s)
|
30
34
|
def inspect
|
31
|
-
@@to_s.bind(self).call.sub!(/>\z/) {"
|
35
|
+
@@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self.original_url}>"}
|
32
36
|
end
|
33
37
|
|
34
38
|
def parsers
|
@@ -48,22 +52,18 @@ class MURI
|
|
48
52
|
@info[:original_url] = raw_url
|
49
53
|
send(parse_function)
|
50
54
|
else
|
51
|
-
raise
|
55
|
+
raise NoParser.new("No Transformer found for URL")
|
52
56
|
end
|
53
57
|
|
54
58
|
#rescue => e
|
55
59
|
#raise "failed #{e}"
|
56
60
|
end
|
57
|
-
|
58
|
-
def field_value(field_name)
|
59
|
-
if @info[field_name.to_sym] != nil
|
60
|
-
@info[field_name.to_sym]
|
61
|
-
else
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
end
|
65
61
|
|
66
62
|
def method_missing(func, args = nil)
|
67
|
-
|
63
|
+
if @info[func.to_sym] != nil
|
64
|
+
@info[func.to_sym]
|
65
|
+
else
|
66
|
+
nil #super(func,args)
|
67
|
+
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/muri/filters/flickr.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class Muri
|
2
2
|
module Filter
|
3
3
|
module Flickr
|
4
4
|
|
@@ -13,10 +13,9 @@ class MURI
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def flickr_parse
|
16
|
-
|
17
16
|
@info[:service] = 'Flickr'
|
18
17
|
|
19
|
-
if @url.path =~
|
18
|
+
if @url.path =~ /^\/photos\/([a-zA-Z0-9\@]*?)\/[^(?:sets)]([0-9]*)/i
|
20
19
|
@info[:media_creator] = $1
|
21
20
|
@info[:media_id] = $2
|
22
21
|
elsif (@url.host + @url.path) =~ /^farm([1-3])\.static.flickr.com\/([0-9]*?)\/([0-9]*?)\_([a-zA-Z0-9]*?)(\_[a-zA-Z]){0,1}\.([a-zA-Z]*)/i
|
@@ -34,14 +33,12 @@ class MURI
|
|
34
33
|
elsif (@url.host + @url.path) =~ /^flic\.kr\/p\/([a-zA-Z0-9]*)/i
|
35
34
|
@info[:media_id] = self.decode58($1)
|
36
35
|
end
|
37
|
-
|
38
|
-
self
|
39
|
-
|
40
|
-
|
41
|
-
def self.create_short_url
|
42
|
-
if !self.media_id.nil?
|
43
|
-
@info[:media_url] = "http://flic.kr/p/" + self.encode58(self.media_id.to_i)
|
36
|
+
|
37
|
+
if self.parsed?
|
38
|
+
@info[:media_url] = "http://flic.kr/p/" + self.encode58(@info[:media_id].to_i)
|
44
39
|
end
|
40
|
+
|
41
|
+
self
|
45
42
|
end
|
46
43
|
|
47
44
|
def decode58(str)
|
@@ -70,8 +67,8 @@ class MURI
|
|
70
67
|
end
|
71
68
|
encoded = alphabet[str,1] + encoded if str
|
72
69
|
encoded
|
73
|
-
end
|
74
|
-
|
70
|
+
end
|
71
|
+
|
75
72
|
end
|
76
73
|
end
|
77
74
|
end
|
data/lib/muri/filters/vimeo.rb
CHANGED
@@ -1,30 +1,34 @@
|
|
1
1
|
require 'cgi'
|
2
|
-
class
|
2
|
+
class Muri
|
3
3
|
module Filter
|
4
4
|
module Vimeo
|
5
5
|
|
6
6
|
def self.included(base)
|
7
7
|
base.class_eval do
|
8
8
|
self::PARSERS["vimeo.com"] = "vimeo_parse"
|
9
|
+
|
10
|
+
|
9
11
|
end
|
10
12
|
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
def vimeo_parse
|
14
|
+
@info[:service] = 'Vimeo'
|
15
|
+
|
16
|
+
if @url.path =~ /^\/([0-9]*)/
|
17
|
+
@info[:media_id] = $1
|
18
|
+
elsif (@url.path =~ /^\/moogaloop\.swf/i)
|
19
|
+
params = CGI::parse(@url.query)
|
20
|
+
if params.include?("clip_id")
|
21
|
+
@info[:media_id] = params["clip_id"].first if (params["clip_id"].first =~ /([0-9]*)/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if self.parsed?
|
26
|
+
@info[:media_url] = "http://vimeo.com/" + @info[:media_id].to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
28
32
|
|
29
33
|
end
|
30
34
|
end
|
data/lib/muri/filters/youtube.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
require 'cgi'
|
2
|
-
class
|
2
|
+
class Muri
|
3
3
|
module Filter
|
4
4
|
module Youtube
|
5
5
|
|
6
6
|
def self.included(base)
|
7
7
|
base.class_eval do
|
8
8
|
self::PARSERS["www.youtube.com"] = "youtube_parse"
|
9
|
-
self::PARSERS["youtube.com"] = "youtube_parse"
|
9
|
+
self::PARSERS["youtube.com"] = "youtube_parse"
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
12
13
|
def youtube_parse
|
13
|
-
|
14
14
|
@info[:service] = 'Youtube'
|
15
15
|
|
16
16
|
if (@url.path == "/watch") && !@url.query.nil?
|
17
|
-
#params = url_components.query.to_params
|
18
17
|
params = CGI::parse(@url.query)
|
19
18
|
@info[:media_id] = params["v"].first
|
20
|
-
|
21
19
|
elsif (@url.path =~ /\/v\/([a-zA-Z0-9\-\_]*)/i)
|
22
20
|
@info[:media_id] = $1
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
if self.parsed?
|
24
|
+
@info[:media_url] = "http://www.youtube.com/watch?v=" + @info[:media_id]
|
25
|
+
@info[:url] = "http://www.youtube.com/v/" + @info[:media_id]
|
26
|
+
end
|
27
|
+
|
27
28
|
self
|
28
|
-
end
|
29
|
+
end
|
29
30
|
|
30
31
|
end
|
31
32
|
end
|
data/muri.gemspec
CHANGED
@@ -5,18 +5,18 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{muri}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
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-02-
|
12
|
+
s.date = %q{2010-02-24}
|
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"
|
16
|
+
"README.rdoc"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"README",
|
19
|
+
"README.rdoc",
|
20
20
|
"Rakefile",
|
21
21
|
"VERSION.yml",
|
22
22
|
"lib/muri.rb",
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
"lib/muri/filters/flickr.rb",
|
26
26
|
"lib/muri/filters/vimeo.rb",
|
27
27
|
"lib/muri/filters/youtube.rb",
|
28
|
-
"muri-0.0.1.gem",
|
29
28
|
"muri.gemspec"
|
30
29
|
]
|
31
30
|
s.homepage = %q{http://github.com/bananastalktome/muri/}
|
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
|
+
version: 0.0.2
|
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-02-
|
12
|
+
date: 2010-02-24 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,9 +20,9 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README
|
23
|
+
- README.rdoc
|
24
24
|
files:
|
25
|
-
- README
|
25
|
+
- README.rdoc
|
26
26
|
- Rakefile
|
27
27
|
- VERSION.yml
|
28
28
|
- lib/muri.rb
|
@@ -31,7 +31,6 @@ files:
|
|
31
31
|
- lib/muri/filters/flickr.rb
|
32
32
|
- lib/muri/filters/vimeo.rb
|
33
33
|
- lib/muri/filters/youtube.rb
|
34
|
-
- muri-0.0.1.gem
|
35
34
|
- muri.gemspec
|
36
35
|
has_rdoc: true
|
37
36
|
homepage: http://github.com/bananastalktome/muri/
|
data/README
DELETED
File without changes
|