fc2video 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 859cbb7cd60684ec514147dd680fa108b55cb29f
4
+ data.tar.gz: ea9d642f2509b2ce17d4a2238850ad7e4c43bc49
5
+ SHA512:
6
+ metadata.gz: 597d9845c35ac5370442dd71a23e84da1d52ced0d592ccf73c673282d0c05e3c5be57a693b97b734d67af38ae7ef5dfa674d40edb08c700a46bd3beb0e735216
7
+ data.tar.gz: 7aa8171ab644fcbc57cda630657bdd141bb94ea51566ae7a21a547473ba20d9393c79364c36918d6cf3795b93a97106f94fbe3ab0d3bfafb95eb8f3ba2b6cd32
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fc2video.gemspec
4
+ gem 'nokogiri'
@@ -0,0 +1,86 @@
1
+ # fc2video
2
+ The fc2video gem can be used for managing videos of http://video.fc2.com.
3
+ You can easily scrape videos' metadata.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fc2video'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fc2video
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # scrape newest 100 general(not adult) videos
25
+ videos = Fc2video::Scraper.start(:general, 100, 0)
26
+ videos.each do |video|
27
+ video.title
28
+ #=> return: 'a excellent movie'
29
+
30
+ video.duration
31
+ # format: 'mmm:ss' (not 'hh:mm:ss')
32
+ #=> return: '117:28', '23:11'
33
+
34
+ video.url
35
+ #=> return: 'http://video.fc2.com/en/content/foo'
36
+
37
+ video.image_url
38
+ # url of thumbnail
39
+ #=> return: 'http://vip.video00000-thumbnail.fc2.com/up/thumb/foo/bar'
40
+
41
+ video.views
42
+ # how many times the video was watched.
43
+ #=> return: 58818
44
+
45
+ video.bookmarks
46
+ # how many times the video was bookmarked.
47
+ #=> return: 118
48
+
49
+ video.adult?
50
+ # return true if it is adult video.
51
+ #=> return: true or false
52
+
53
+ video.status
54
+ # return: :all or :premium or :sale
55
+
56
+ video.for_all?
57
+ # all user can watch for free.
58
+ #=> return: true or false
59
+
60
+ video.for_premium?
61
+ # only VIP user can watch premium videos.
62
+ #=> return: true or false
63
+
64
+ video.for_sale?
65
+ # pay to watch video
66
+ #=> return: true or false
67
+ end
68
+ ```
69
+
70
+ ### Scraping Options
71
+ * type (`:general` or `:adult`)
72
+ * size (Fixnum)
73
+ * offset (Fixnum)
74
+
75
+ The number of `size` and `offset` is better for multiples of 50. That's why there are 50 videos information in every page we scrape.
76
+
77
+ ```ruby
78
+ #Fc2video::Scraper.start(:type, :size, :offset)
79
+ Fc2video::Scraper.start(:adult, 1000, 500)
80
+ ```
81
+
82
+ ### Scraping Speed
83
+ It takes 20~30sec for scraping 1000 videos.
84
+
85
+ ## Contributing
86
+ Bug reports and pull requests are welcome.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fc2video"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fc2video/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fc2video'
8
+ spec.version = Fc2video::VERSION
9
+ spec.authors = ['showwin']
10
+ spec.email = ['showwin_kmc@yahoo.co.jp']
11
+
12
+ spec.summary = %q{ scraping video information from http://video.fc2.com }
13
+ spec.description = %q{ scraping video information from http://video.fc2.com }
14
+ spec.homepage = 'https://github.com/showwin/fc2video'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'nokogiri'
25
+ spec.add_development_dependency 'open-uri'
26
+ end
@@ -0,0 +1,9 @@
1
+ require 'fc2video/version'
2
+ require 'fc2video/scraper'
3
+ require 'fc2video/video'
4
+ require 'open-uri'
5
+ require 'nokogiri'
6
+
7
+ # module fc2video
8
+ module Fc2video
9
+ end
@@ -0,0 +1,89 @@
1
+ module Fc2video
2
+ class Scraper
3
+ VIDEOS_PER_PAGE = 50
4
+
5
+ ADULT_SEARCH_URL = 'http://video.fc2.com/en/a/movie_search.php?perpage=50&page='
6
+ NORMAL_SEARCH_URL = 'http://video.fc2.com/en/movie_search.php?perpage=50&page='
7
+ VIDEO_PATH = '//div[@class="video_list_renew clearfix"]'
8
+ TITLE_PATH = './div[@class="video_info_right"]/h3'
9
+ DURATION_PATH = './div[@class="video_list_renew_thumb"]/span'
10
+ URL_PATH = './div[@class="video_info_right"]/h3/a'
11
+ IMAGE_URL_PATH = './div[@class="video_list_renew_thumb"]/div/a/img'
12
+ VIEWS_PATH = './div[@class="video_info_right"]/ul/li'
13
+ FAVS_PATH = './div[@class="video_info_right"]/ul/li'
14
+ STATUS_PATH = './div[@class="video_info_right"]/ul/li'
15
+
16
+ class << self
17
+ def start(type, size, offset)
18
+ @type = type
19
+ @size = size
20
+ @offset = offset
21
+
22
+ scrape
23
+ end
24
+
25
+ private
26
+
27
+ def scrape
28
+ arr = []
29
+ page_from.upto(page_to) do |i|
30
+ begin
31
+ arr.concat(scrape_page(Nokogiri::HTML(open(search_url + i.to_s))))
32
+ rescue
33
+ next
34
+ end
35
+ end
36
+ arr
37
+ end
38
+
39
+ def search_url
40
+ adult_flg ? ADULT_SEARCH_URL : NORMAL_SEARCH_URL
41
+ end
42
+
43
+ def adult_flg
44
+ @type == :adult
45
+ end
46
+
47
+ def page_from
48
+ (@offset / VIDEOS_PER_PAGE) + 1
49
+ end
50
+
51
+ def page_to
52
+ ((@offset + @size) / VIDEOS_PER_PAGE)
53
+ end
54
+
55
+ def scrape_page(page)
56
+ result = []
57
+ VIDEOS_PER_PAGE.times do |j|
58
+ params = scrape_params(page.xpath(VIDEO_PATH)[j])
59
+ result << Fc2video::Video.new(params)
60
+ end
61
+ result
62
+ end
63
+
64
+ def scrape_params(elm)
65
+ params = {}
66
+ params[:title] = elm.xpath(TITLE_PATH).first.content
67
+ params[:duration] = elm.xpath(DURATION_PATH).first.content
68
+ params[:url] = elm.xpath(URL_PATH).first['href']
69
+ params[:image_url] = elm.xpath(IMAGE_URL_PATH).first['src']
70
+ params[:views] = elm.xpath(VIEWS_PATH)[1].content.to_i
71
+ params[:bookmarks] = elm.xpath(FAVS_PATH)[2].content.to_i
72
+ params[:adult] = adult_flg
73
+ params[:status] = status_to_sym(elm.xpath(STATUS_PATH)[0].content)
74
+ params
75
+ end
76
+
77
+ def status_to_sym(str)
78
+ case str
79
+ when 'All', 'All ★'
80
+ :all
81
+ when 'Premium'
82
+ :premium
83
+ when 'For Sale'
84
+ :sale
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ module Fc2video
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ module Fc2video
2
+ class Video
3
+ attr_reader :title, :duration, :url, :image_url, :views, :bookmarks, :status
4
+
5
+ def initialize(params)
6
+ @title = params[:title]
7
+ @duration = params[:duration]
8
+ @url = params[:url]
9
+ @image_url = params[:image_url]
10
+ @views = params[:views]
11
+ @bookmarks = params[:bookmarks]
12
+ @adult = params[:adult]
13
+ @status = params[:status]
14
+ end
15
+
16
+ def adult?
17
+ @adult
18
+ end
19
+
20
+ def for_all?
21
+ @status == :all
22
+ end
23
+
24
+ def for_premium?
25
+ @status == :premium
26
+ end
27
+
28
+ def for_sale?
29
+ @status == :sale
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fc2video
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - showwin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: open-uri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: " scraping video information from http://video.fc2.com "
84
+ email:
85
+ - showwin_kmc@yahoo.co.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - fc2video.gemspec
99
+ - lib/fc2video.rb
100
+ - lib/fc2video/scraper.rb
101
+ - lib/fc2video/version.rb
102
+ - lib/fc2video/video.rb
103
+ homepage: https://github.com/showwin/fc2video
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: scraping video information from http://video.fc2.com
126
+ test_files: []
127
+ has_rdoc: