muri 0.0.1

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 ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "muri"
5
+ gem.summary = %{Media URI Parser}
6
+ gem.email = "bananastalktome@gmail.com"
7
+ gem.homepage = "http://github.com/bananastalktome/muri/"
8
+ gem.description = "Automatically get media information from the URL."
9
+ gem.authors = ["William Schneider"]
10
+ gem.files.exclude 'test.sqlite3'
11
+ gem.has_rdoc = false
12
+ end
13
+ rescue LoadError
14
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
15
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 1
data/lib/muri/base.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'uri'
2
+ class MURI
3
+ class NoTransformer < StandardError; end
4
+
5
+ PARSERS = { }
6
+
7
+ include Filter::Youtube
8
+ include Filter::Flickr
9
+ include Filter::Vimeo
10
+
11
+ def self.parse(url)
12
+ self.new(url)
13
+ end
14
+
15
+ def initialize(url)
16
+ @info = { }
17
+ _parse(url)
18
+ end
19
+
20
+ def to_yaml
21
+ @info.to_yaml
22
+ end
23
+
24
+ def to_s
25
+ @info.to_s
26
+ end
27
+
28
+ # Taken from uri/generic.rb
29
+ @@to_s = Kernel.instance_method(:to_s)
30
+ def inspect
31
+ @@to_s.bind(self).call.sub!(/>\z/) {" #{self}>"}
32
+ end
33
+
34
+ def parsers
35
+ PARSERS.keys
36
+ end
37
+
38
+ private
39
+
40
+ def _parse(raw_url)
41
+ @url = URI.parse(raw_url)
42
+ if @url.scheme.nil?
43
+ raw_url = "http://#{raw_url}"
44
+ @url = URI.parse(raw_url)
45
+ end
46
+ if parse_function = PARSERS[@url.host]
47
+ @info[:uri] = @url
48
+ @info[:original_url] = raw_url
49
+ send(parse_function)
50
+ else
51
+ raise NoTransformer.new("No Transformer found for URL")
52
+ end
53
+
54
+ #rescue => e
55
+ #raise "failed #{e}"
56
+ 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
+
66
+ def method_missing(func, args = nil)
67
+ field_value(func)
68
+ end
69
+ end
File without changes
@@ -0,0 +1,85 @@
1
+ class MURI
2
+ module Filter
3
+ module Flickr
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ self::PARSERS["www.flickr.com"] = "flickr_parse"
8
+ self::PARSERS["farm3.static.flickr.com"] = "flickr_parse"
9
+ self::PARSERS["farm2.static.flickr.com"] = "flickr_parse"
10
+ self::PARSERS["farm1.static.flickr.com"] = "flickr_parse"
11
+ self::PARSERS["flic.kr"] = "flickr_parse"
12
+ end
13
+ end
14
+
15
+ def flickr_parse
16
+
17
+ @info[:service] = 'Flickr'
18
+
19
+ if @url.path =~ /^photos\/([a-zA-Z0-9\@]*?)\/[^(?:sets)]([0-9]*)/i
20
+ @info[:media_creator] = $1
21
+ @info[:media_id] = $2
22
+ 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
23
+ @info[:media_id] = $3
24
+ if !$5.nil?
25
+ @info[:media_size] = case $5.downcase
26
+ when '_s' then 'small'
27
+ when '_t' then 'thumbnail'
28
+ when '_m' then 'medium'
29
+ when '_b' then 'large'
30
+ else nil
31
+ end
32
+ end
33
+ @info[:content_type] = $6.downcase
34
+ elsif (@url.host + @url.path) =~ /^flic\.kr\/p\/([a-zA-Z0-9]*)/i
35
+ @info[:media_id] = self.decode58($1)
36
+ end
37
+ self.create_short_url
38
+ self
39
+ end
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)
44
+ end
45
+ end
46
+
47
+ def decode58(str)
48
+ decoded = 0
49
+ multi = 1
50
+ alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
51
+ while str.length > 0
52
+ digit = str[(str.length - 1),1]
53
+ decoded += multi * alphabet.index(digit)
54
+ multi = multi * alphabet.length
55
+ str.chop!
56
+ end
57
+
58
+ decoded
59
+ end
60
+
61
+ def encode58(str)
62
+ alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
63
+ base_count = alphabet.length
64
+ encoded = ''
65
+ while str >= base_count
66
+ div = str / base_count
67
+ mod = (str-(base_count * div.to_i))
68
+ encoded = alphabet[mod,1] + encoded
69
+ str = div.to_i
70
+ end
71
+ encoded = alphabet[str,1] + encoded if str
72
+ encoded
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ # http://www.flickr.com/photos/bananastalktome/2088436532/
79
+ # http://farm3.static.flickr.com/2178/2088436532_ee07b4474e_m.jpg
80
+ # farm-id: 3
81
+ # server-id: 2178
82
+ # photo-id: 2088436532
83
+ # secret: ee07b4474e
84
+ # size: m
85
+ # * add _d before .jpg in url to create a download URL
@@ -0,0 +1,33 @@
1
+ require 'cgi'
2
+ class MURI
3
+ module Filter
4
+ module Vimeo
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ self::PARSERS["vimeo.com"] = "vimeo_parse"
9
+ end
10
+ end
11
+
12
+ def vimeo_parse
13
+
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
+ @info[:media_url] = "http://vimeo.com/" + @info[:media_id] if !@info.media_id.nil?
25
+
26
+ self
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ # 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"
33
+ # http://vimeo.com/7312128
@@ -0,0 +1,34 @@
1
+ require 'cgi'
2
+ class MURI
3
+ module Filter
4
+ module Youtube
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ self::PARSERS["www.youtube.com"] = "youtube_parse"
9
+ self::PARSERS["youtube.com"] = "youtube_parse"
10
+ end
11
+ end
12
+ def youtube_parse
13
+
14
+ @info[:service] = 'Youtube'
15
+
16
+ if (@url.path == "/watch") && !@url.query.nil?
17
+ #params = url_components.query.to_params
18
+ params = CGI::parse(@url.query)
19
+ @info[:media_id] = params["v"].first
20
+
21
+ elsif (@url.path =~ /\/v\/([a-zA-Z0-9\-\_]*)/i)
22
+ @info[:media_id] = $1
23
+ end
24
+
25
+ @info[:media_url] = "http://www.youtube.com/watch?v=" + @info[:media_id]
26
+ @info[:url] = "http://www.youtube.com/v/" + @info[:media_id]
27
+ self
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ # http://www.youtube.com/v/4CYDFoEz8rg&hl=en_US&fs=1&
34
+ # http://www.youtube.com/watch?v=l983Uob0Seo&feature=rec-LGOUT-exp_fresh+div-1r-1-HM
data/lib/muri.rb ADDED
@@ -0,0 +1,10 @@
1
+ # Register built-in filters
2
+ #
3
+ Dir["#{File.dirname(__FILE__) + '/muri/filters'}/**/*"].each do |filter|
4
+ require "#{filter}"
5
+ end
6
+
7
+ %w(base).each do |f|
8
+ require File.dirname(__FILE__) + "/muri/#{f}"
9
+ end
10
+
data/muri.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{muri}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["William Schneider"]
12
+ s.date = %q{2010-02-22}
13
+ s.description = %q{Automatically get media information from the URL.}
14
+ s.email = %q{bananastalktome@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "lib/muri.rb",
23
+ "lib/muri/base.rb",
24
+ "lib/muri/filter.rb",
25
+ "lib/muri/filters/flickr.rb",
26
+ "lib/muri/filters/vimeo.rb",
27
+ "lib/muri/filters/youtube.rb",
28
+ "muri-0.0.1.gem",
29
+ "muri.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/bananastalktome/muri/}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Media URI Parser}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ else
43
+ end
44
+ else
45
+ end
46
+ end
47
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: muri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - William Schneider
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-22 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Automatically get media information from the URL.
17
+ email: bananastalktome@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - README
26
+ - Rakefile
27
+ - VERSION.yml
28
+ - lib/muri.rb
29
+ - lib/muri/base.rb
30
+ - lib/muri/filter.rb
31
+ - lib/muri/filters/flickr.rb
32
+ - lib/muri/filters/vimeo.rb
33
+ - lib/muri/filters/youtube.rb
34
+ - muri-0.0.1.gem
35
+ - muri.gemspec
36
+ has_rdoc: true
37
+ homepage: http://github.com/bananastalktome/muri/
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Media URI Parser
64
+ test_files: []
65
+