funky 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +27 -0
- data/lib/funky/url.rb +19 -0
- data/lib/funky/version.rb +1 -1
- data/lib/funky/video.rb +16 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76c2fdd3918dd49adec887a52a8cd55d1062658
|
4
|
+
data.tar.gz: 60c4af9c11e05e4d40c9d077e03a5847131580bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0a9bdfdc29390b523a28d83af059744a3b7ede1a55089881aa83e2b94b0195dfd4acdd93b3cdbcc38f6653fc23ffdf320862fd89fb63d73939e0d7fded85c0e
|
7
|
+
data.tar.gz: b62532c7eeeb17680771a2d30b40cc2a82c6f06b2cce55594d6855bff4d4f6d6e9e8b0318eb7c12a42fd95bbd2506d9a11bdeb0d6488ba6a3d591e0c9503a7d9
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,15 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 0.2.1 - 2016/06/16
|
10
|
+
|
11
|
+
* [FEATURE] Add method to find video by url, `Funky::Video.find_by_url!(url)`.
|
12
|
+
The following URL formats are currently supported:
|
13
|
+
- `https://www.facebook.com/{page_name}/videos/vb.{alt_page_id}/{video_id}/`
|
14
|
+
- `https://www.facebook.com/{page_name}/videos/{video_id}/`
|
15
|
+
- `https://www.facebook.com/{page_id}/videos/{video_id}/`
|
16
|
+
- `https://www.facebook.com/video.php?v={video_id}`
|
17
|
+
|
9
18
|
## 0.2.0 - 2016/06/07
|
10
19
|
|
11
20
|
**How to upgrade**
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[](https://travis-ci.org/Fullscreen/funky)
|
2
2
|
[](https://coveralls.io/github/Fullscreen/funky?branch=master)
|
3
3
|
[](https://gemnasium.com/github.com/Fullscreen/funky)
|
4
|
+
[](https://codeclimate.com/github/Fullscreen/funky)
|
4
5
|
[](https://badge.fury.io/rb/funky)
|
5
6
|
|
6
7
|
# Funky
|
@@ -94,6 +95,32 @@ If a non-existing video ID is passed into #find, Funky::ContentNotFound will be
|
|
94
95
|
Funky::Video.find('doesnotexist') # => raises Funky::ContentNotFound
|
95
96
|
```
|
96
97
|
|
98
|
+
### Use #find_by_url!(url) to get a single video from a url
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
video = Funky::Video.find_by_url!('https://www.facebook.com/video.php?v=10154439119663508')
|
102
|
+
video.id # => '10154439119663508'
|
103
|
+
video.like_count # => 1169
|
104
|
+
video.comment_count # => 65
|
105
|
+
video.share_count # => 348
|
106
|
+
video.view_count # => 10121
|
107
|
+
```
|
108
|
+
|
109
|
+
If a non-existing video url is passed into #find_by, Funky::ContentNotFound will be raised.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
Funky::Video.find_by_url!('https://www.facebook.com/video.php?v=doesnotexist')
|
113
|
+
# => raises Funky::ContentNotFound
|
114
|
+
```
|
115
|
+
|
116
|
+
The current URL formats are supported:
|
117
|
+
|
118
|
+
- `https://www.facebook.com/{page_name}/videos/vb.{alt_page_id}/{video_id}`
|
119
|
+
- `https://www.facebook.com/{page_name}/videos/{video_id}`
|
120
|
+
- `https://www.facebook.com/{page_id}/videos/{video_id}`
|
121
|
+
- `https://www.facebook.com/video.php?v={video_id}`
|
122
|
+
|
123
|
+
|
97
124
|
### Connection error
|
98
125
|
|
99
126
|
Should there be a case where Funky is unable to connect to Facebook, `Funky::ConnectionError` will be raised.
|
data/lib/funky/url.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Funky
|
2
|
+
class URL
|
3
|
+
attr_reader :url
|
4
|
+
VIDEO_ID_REGEXES = [/videos\/(\d*)/i, /v=(\d*)/i, /\/v.\..*\/(\d*)\b/i]
|
5
|
+
|
6
|
+
def initialize(url)
|
7
|
+
@url = url
|
8
|
+
end
|
9
|
+
|
10
|
+
def video_id
|
11
|
+
return unless url.include? 'facebook.com'
|
12
|
+
VIDEO_ID_REGEXES.each do |regex|
|
13
|
+
url.match regex
|
14
|
+
return $1 unless $1.nil? || $1.empty? || !$1.size.between?(15,17)
|
15
|
+
end
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/funky/version.rb
CHANGED
data/lib/funky/video.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'funky/html/page'
|
2
2
|
require 'funky/html/parser'
|
3
|
+
require 'funky/url'
|
3
4
|
|
4
5
|
module Funky
|
5
6
|
class Video
|
@@ -90,6 +91,21 @@ module Funky
|
|
90
91
|
new counters.merge(id: video_id)
|
91
92
|
end
|
92
93
|
|
94
|
+
# Similar to #find, but it finds the video by url instead of video id.
|
95
|
+
# Fetches the data from Facebook's HTML and instantiates the data
|
96
|
+
# into a single Funky::Video object. It can accept one only video url.
|
97
|
+
#
|
98
|
+
# @example Getting a video by url
|
99
|
+
# url = 'https://www.facebook.com/video.php?v=203203106739575'
|
100
|
+
# Funky::Video.find_by_url!(url) # => #<Funky::Video>
|
101
|
+
#
|
102
|
+
# @return [Funky::Video] the data scraped from Facebook's HTML
|
103
|
+
# and encapsulated into a Funky::Video object.
|
104
|
+
def self.find_by_url!(url)
|
105
|
+
url = URL.new(url)
|
106
|
+
find(url.video_id)
|
107
|
+
end
|
108
|
+
|
93
109
|
private
|
94
110
|
|
95
111
|
def self.fetch_and_parse_data(ids)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: funky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philip Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/funky/errors.rb
|
124
124
|
- lib/funky/html/page.rb
|
125
125
|
- lib/funky/html/parser.rb
|
126
|
+
- lib/funky/url.rb
|
126
127
|
- lib/funky/version.rb
|
127
128
|
- lib/funky/video.rb
|
128
129
|
homepage: https://github.com/Fullscreen/funky
|