social_net 0.2.12 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -10
- data/lib/social_net/instagram/api/scrape_request.rb +7 -13
- data/lib/social_net/instagram/api/scrape_user_videos_request.rb +6 -9
- data/lib/social_net/instagram/models/video.rb +3 -4
- data/lib/social_net/version.rb +1 -1
- data/spec/support/cassettes/SocialNet_Instagram_Models_User/_videos/given_an_existing_user/returns_an_array_of_video_posts_from_the_user.yml +1146 -50
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd4101beba6793ca6dde37ce03672a04a77f66c7
|
4
|
+
data.tar.gz: fe7e39fad2cce5e6f899d27e4f0f7e09dfa22757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af977dafd9b9f9ead3e393dfda24057b2fdbaa202829493fb582b70700652baed86eecd326b7f34a7ce6588e56f5b46bfe04d14b9eca015f2f6cf1903d808c68
|
7
|
+
data.tar.gz: 20f61722e84829b115bad08ad32d8cdca896a92124c091d4ea97e6b22d56f86442fc3d967695f696aeb610a8e9926163924d0b0d48f003a87858a7ea0d77ef11
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,19 +12,20 @@ user = SocialNet::Twitter::User.find_by screen_name: 'collab'
|
|
12
12
|
user.screen_name #=> "Collab"
|
13
13
|
user.follower_count #=> 48_200
|
14
14
|
```
|
15
|
-
|
15
|
+
|
16
|
+
For Instagram, you can run commands like:
|
16
17
|
|
17
18
|
```ruby
|
18
|
-
user = SocialNet::Instagram::User.
|
19
|
-
user.username #=> "Collab"
|
20
|
-
user.follower_count #=> 7025
|
19
|
+
user = SocialNet::Instagram::User.new username: 'Collab'
|
21
20
|
user.videos #=>
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
21
|
+
# @caption=
|
22
|
+
# "30 Likes, 3 Comments - Collab (@collab) on Instagram: “@dribble2much’s ‘Ankle Bully’ ft. @lianev and @globalhooper is out now. Hit our Stories for the…”",
|
23
|
+
# @id="BjGBDnMA7tk",
|
24
|
+
# @link="https://www.instagram.com/p/BjGBDnMA7tk/",
|
25
|
+
# @thumbnail_url=
|
26
|
+
# "https://scontent-lax3-2.cdninstagram.com/vp/b022f60aa0dca66bf69b42ef120bebaa/5B196165/t51.2885-15/e15/32276184_235590730544586_2982097953704902656_n.jpg",
|
27
|
+
# @video_url=
|
28
|
+
# "https://scontent-lax3-2.cdninstagram.com/vp/dca9fd7707b3e00d5efd18c98c54e6ba/5B19755C/t50.2886-16/32028990_233788607376727_7097250491033190400_n.mp4">
|
28
29
|
```
|
29
30
|
|
30
31
|
After [configuring your Facebook app](#configuring-your-facebook-app), you can run commands like:
|
@@ -10,6 +10,7 @@ module SocialNet
|
|
10
10
|
class ScrapeRequest
|
11
11
|
def initialize(attrs = {})
|
12
12
|
@host = 'www.instagram.com'
|
13
|
+
@shortcode = attrs[:shortcode]
|
13
14
|
@path = attrs.fetch :path, "/p/#{attrs[:shortcode]}/"
|
14
15
|
@method = attrs.fetch :method, :get
|
15
16
|
end
|
@@ -42,20 +43,13 @@ module SocialNet
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def parse_video_data(data)
|
45
|
-
|
46
|
-
data_string = script_with_data.children[0].content
|
47
|
-
ig_data = eval data_string.gsub(/window\._sharedData = /,"").gsub(/null/,'nil').gsub(/\\/,'')
|
48
|
-
video_data = ig_data[:entry_data][:PostPage][0][:graphql][:shortcode_media]
|
49
|
-
raise Errors::UnknownVideo unless video_data[:is_video]
|
46
|
+
raise Errors::UnknownVideo unless data.at("meta[property='og:type']")['content'] == 'video'
|
50
47
|
{}.tap do |video|
|
51
|
-
video['id'] =
|
52
|
-
video['
|
53
|
-
video['
|
54
|
-
video['
|
55
|
-
video['
|
56
|
-
if video_data[:edge_media_to_caption][:edges].present?
|
57
|
-
video['caption'] = {'text' => video_data[:edge_media_to_caption][:edges][0][:node][:text]}
|
58
|
-
end
|
48
|
+
video['id'] = @shortcode
|
49
|
+
video['video_url'] = data.at("meta[property='og:video']")['content']
|
50
|
+
video['thumbnail_url'] = data.at("meta[property='og:image']")['content']
|
51
|
+
video['link'] = data.at("meta[property='og:url']")['content']
|
52
|
+
video['caption'] = data.at("meta[property='og:description']")['content']
|
59
53
|
end
|
60
54
|
end
|
61
55
|
|
@@ -43,16 +43,13 @@ module SocialNet
|
|
43
43
|
|
44
44
|
def parse_video_data(data)
|
45
45
|
data_string = data.search("script")[3].children.first
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
video = Models::Video.find_by shortcode: data[:node][:shortcode]
|
52
|
-
videos << video
|
53
|
-
end
|
46
|
+
shortcodes = data_string.content.gsub(/window\._sharedData = /,"").gsub(/\\/,'').delete('\\"').scan(/shortcode:([\w_-]{10,39})/).flatten
|
47
|
+
[].tap do |videos|
|
48
|
+
shortcodes.each do |shortcode|
|
49
|
+
video = Models::Video.find_by shortcode: shortcode
|
50
|
+
videos << video
|
54
51
|
end
|
55
|
-
end
|
52
|
+
end.compact
|
56
53
|
end
|
57
54
|
|
58
55
|
def as_curl
|
@@ -10,11 +10,10 @@ module SocialNet
|
|
10
10
|
|
11
11
|
def initialize(attrs = {})
|
12
12
|
@id = attrs['id']
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@file = attrs['videos']['standard_resolution']['url']
|
16
|
-
@thumbnail = attrs['images']['standard_resolution']['url']
|
13
|
+
@video_url = attrs['video_url']
|
14
|
+
@thumbnail_url = attrs['thumbnail_url']
|
17
15
|
@link = attrs['link']
|
16
|
+
@caption = attrs['caption'] if attrs['caption']
|
18
17
|
end
|
19
18
|
|
20
19
|
# Returns the existing Instagram video matching the provided attributes or
|
data/lib/social_net/version.rb
CHANGED