url_to_contents 0.0.3
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/Gemfile +6 -0
- data/Gemfile.lock +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/lib/url_to_contents/models/tudou.rb +7 -0
- data/lib/url_to_contents/models/weibo.rb +7 -0
- data/lib/url_to_contents/models/youku.rb +7 -0
- data/lib/url_to_contents/parser.rb +34 -0
- data/lib/url_to_contents/site.rb +7 -0
- data/lib/url_to_contents/url.rb +32 -0
- data/lib/url_to_contents/version.rb +3 -0
- data/lib/url_to_contents.rb +9 -0
- data/url_to_contents.gemspec +19 -0
- metadata +59 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# UrlToContents
|
2
|
+
|
3
|
+
Get some special contents base on URL.
|
4
|
+
|
5
|
+
The following contents are supported now:
|
6
|
+
1. The Flash Player's url of video on youku.com
|
7
|
+
2. The main content of post on weibo.com
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'url_to_contents'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install url_to_contents
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### youku
|
26
|
+
url = UrlToContents::Url.new('http://v.youku.com/v_show/id_XMjk1MTM0Njky.html')
|
27
|
+
|
28
|
+
youku = url.parse
|
29
|
+
=> #<UrlToContents::Models::Youku:0x000000028cf170 @content="http://player.youku.com/player.php/Type/Folder/Fid/18443230/Ob/1/sid/XNDY1NDcwMDQ0/v.swf">
|
30
|
+
|
31
|
+
youku.content
|
32
|
+
=> "http://player.youku.com/player.php/sid/XMjk1MTM0Njky/v.swf"
|
33
|
+
|
34
|
+
### weibo
|
35
|
+
|
36
|
+
url = UrlToContents::Url.new('http://weibo.com/1708332824/z11Bsbg1o')
|
37
|
+
|
38
|
+
weibo = url.parse
|
39
|
+
=> #<UrlToContents::Models::Weibo:0x00000002c11d60 @author="西岸男孩-小号", @content=":本周五晚上9点10分西岸男孩将亮相浙江卫视梦想秀,讲述我们这些年坎坷又执着的梦想道路,我将告诉大家除了唱歌以外我们的兼职工作。", @date="10月18日 11:36">
|
40
|
+
|
41
|
+
weibo.author
|
42
|
+
=> "西岸男孩-小号"
|
43
|
+
|
44
|
+
weibo.content
|
45
|
+
=> ":本周五晚上9点10分西岸男孩将亮相浙江卫视梦想秀,讲述我们这些年坎坷又执着的梦想道路,我将告诉大家除了唱歌以外我们的兼职工作。"
|
46
|
+
|
47
|
+
weibo.date
|
48
|
+
=> "10月18日 11:36"
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'url_to_contents/models/tudou'
|
3
|
+
require 'url_to_contents/models/weibo'
|
4
|
+
require 'url_to_contents/models/youku'
|
5
|
+
|
6
|
+
|
7
|
+
module UrlToContents
|
8
|
+
|
9
|
+
class Parser
|
10
|
+
def initialize(doc)
|
11
|
+
@doc = doc
|
12
|
+
end
|
13
|
+
|
14
|
+
def youku
|
15
|
+
youku = UrlToContents::Models::Youku.new
|
16
|
+
@doc.css('#panel_share > .panel_con > .p1 > .item').each do |u|
|
17
|
+
youku.content = u.xpath('input').attr('value').value if u.css('.label').children.text == "flash地址: "
|
18
|
+
end
|
19
|
+
return youku
|
20
|
+
end
|
21
|
+
|
22
|
+
def weibo
|
23
|
+
weibo = UrlToContents::Models::Weibo.new
|
24
|
+
weibo.author = @doc.at('#M_ div a').text
|
25
|
+
weibo.content = @doc.at('#M_ div .ctt').text
|
26
|
+
weibo.date = @doc.at('#M_ div .ct').text
|
27
|
+
return weibo
|
28
|
+
end
|
29
|
+
|
30
|
+
def todou
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module UrlToContents
|
5
|
+
|
6
|
+
class Url
|
7
|
+
include UrlToContents::Site
|
8
|
+
|
9
|
+
attr_accessor :url, :doc
|
10
|
+
|
11
|
+
def initialize(url)
|
12
|
+
@url = prepared_url(url)
|
13
|
+
@doc = Nokogiri::HTML(open(@url))
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepared_url(url)
|
17
|
+
return url.sub(/weibo.com/,'weibo.cn') if which_site?(url) == Weibo
|
18
|
+
return url
|
19
|
+
end
|
20
|
+
|
21
|
+
def which_site?(url = @url)
|
22
|
+
return Youku if url.include?('v.youku.com')
|
23
|
+
return Weibo if (url.include?('weibo.com')|| url.include?('weibo.cn'))
|
24
|
+
return Tudou if url.include?('tudou.com')
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse
|
28
|
+
UrlToContents::Parser.new(@doc).send which_site?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'url_to_contents/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "url_to_contents"
|
8
|
+
gem.version = UrlToContents::VERSION
|
9
|
+
gem.authors = ["skywalker"]
|
10
|
+
gem.email = ["skywalker418@gmail.com"]
|
11
|
+
gem.description = [""]
|
12
|
+
gem.summary = ""
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url_to_contents
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- skywalker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! '[""]'
|
15
|
+
email:
|
16
|
+
- skywalker418@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/url_to_contents.rb
|
27
|
+
- lib/url_to_contents/models/tudou.rb
|
28
|
+
- lib/url_to_contents/models/weibo.rb
|
29
|
+
- lib/url_to_contents/models/youku.rb
|
30
|
+
- lib/url_to_contents/parser.rb
|
31
|
+
- lib/url_to_contents/site.rb
|
32
|
+
- lib/url_to_contents/url.rb
|
33
|
+
- lib/url_to_contents/version.rb
|
34
|
+
- url_to_contents.gemspec
|
35
|
+
homepage: ''
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.24
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: ''
|
59
|
+
test_files: []
|