social_net 0.2.12 → 0.2.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d501f1bc53f1dcdee920829ddb5070d891bb1c74
4
- data.tar.gz: a475f8ccd93d602887ec8affca0f6489f9cc5cf8
3
+ metadata.gz: fd4101beba6793ca6dde37ce03672a04a77f66c7
4
+ data.tar.gz: fe7e39fad2cce5e6f899d27e4f0f7e09dfa22757
5
5
  SHA512:
6
- metadata.gz: 7e3f919d2d081c21c68194f3aaa13d9e4493d4ba618b516ea0b9854cdc43f464b581b7c417a17738cc4a901e9f9683ece6f67dfb6adfb1c664e15f2d51fcfce5
7
- data.tar.gz: 10f6239c2dff174385f827b2b416206f0ef7fd461624c373373712e9c400e71b5cc18bae981bca192e0e32a77da3dabbf065f67ed4c7eca489beaa23df391929
6
+ metadata.gz: af977dafd9b9f9ead3e393dfda24057b2fdbaa202829493fb582b70700652baed86eecd326b7f34a7ce6588e56f5b46bfe04d14b9eca015f2f6cf1903d808c68
7
+ data.tar.gz: 20f61722e84829b115bad08ad32d8cdca896a92124c091d4ea97e6b22d56f86442fc3d967695f696aeb610a8e9926163924d0b0d48f003a87858a7ea0d77ef11
data/CHANGELOG.md CHANGED
@@ -50,3 +50,7 @@ For more information about changelogs, check
50
50
  ## 0.2.12 - 2018-06-04
51
51
 
52
52
  * [BUGFIX] Update deprecated `user.videos` method and add scraping support.
53
+
54
+ ## 0.2.13 - 2018-06-05
55
+
56
+ * [BUGFIX] Improve scraping for `user.videos` method.
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
- After [configuring your Instagram app](#configuring-your-instagram-app), you can run commands like:
15
+
16
+ For Instagram, you can run commands like:
16
17
 
17
18
  ```ruby
18
- user = SocialNet::Instagram::User.find_by username: 'Collab'
19
- user.username #=> "Collab"
20
- user.follower_count #=> 7025
19
+ user = SocialNet::Instagram::User.new username: 'Collab'
21
20
  user.videos #=>
22
- # [SocialNet::Instagram::Models::Video
23
- # @caption='Diet starts Monday... 😂🍩',
24
- # @file='https://scontent.cdninstagram.com/t50.2886-16/17192719_791273527696774_5253726776697290752_n.mp4',
25
- # @id='1464710084172115373_487786346',
26
- # @likes=127,
27
- # @thumbnail='https://scontent.cdninstagram.com/t51.2885-15/e15/17076697_308353549580106_8220285822193106944_n.jpg']"
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
- script_with_data = data.search("script").detect {|script| script.children[0].content.include? "window._sharedData"}
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'] = video_data[:shortcode]
52
- video['likes'] = {'count' => video_data[:edge_media_preview_like][:count]}
53
- video['videos'] = {'standard_resolution' => {'url' => video_data[:video_url]}}
54
- video['images'] = {'standard_resolution' => {'url' => video_data[:display_url]}}
55
- video['link'] = "https://www.instagram.com/p/#{video_data[:shortcode]}/"
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
- ig_data = eval data_string.content.gsub(/window\._sharedData = /,"").gsub(/null/,'nil').gsub(/\\/,'')
47
- user_data = ig_data[:entry_data][:ProfilePage][0][:graphql][:user][:edge_owner_to_timeline_media][:edges]
48
- vs = [].tap do |videos|
49
- user_data.each do |data|
50
- if data[:node][:__typename] == "GraphVideo"
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
- @caption = attrs['caption']['text'] if attrs['caption']
14
- @likes = attrs['likes']['count']
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
@@ -1,3 +1,3 @@
1
1
  module SocialNet
2
- VERSION = "0.2.12"
2
+ VERSION = "0.2.13"
3
3
  end