yt_util 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7b1ed94c177fb7d05f71eae24e87db5467d01c1
4
- data.tar.gz: 487ea160d323c3b8ef432d91523d2afbc1d44a0b
3
+ metadata.gz: 5c902427a3738d2f25906a56a4617e9235b8e3f7
4
+ data.tar.gz: d82c5058ce703d46aa97853acf80e49a4d2f5a7c
5
5
  SHA512:
6
- metadata.gz: d529e7cdf11e6b2f4b5e844eddceec0886213894fa87aa70c642042a325a58ac20684c536cb696a5e2ca4111e17c194294a4ead6692f2d940dd16899b5aecf0c
7
- data.tar.gz: cfa6c69365757262e89dd62ee777c9a7dcef6eede3093393eec9ada9a3b0dd34270d2a9fdadcdc5d656f48af51b22b7db7cc3ec3fa3ac8523eb8593b19808669
6
+ metadata.gz: e0c909ed4de6afafaeb9b2810e62b40a67f28831dcc3865569e8bbc94c7db5396f443fbaa33820816d98f1558b9a56b1bc8a6f41356665fdeebb97ee70d1f92b
7
+ data.tar.gz: 4b700c7d9718bd89013594d62f9a509fd1d1949782de1cd4f474847eb9235fe498cd4f64fcb9aed78e76e749aee77932bc13c53c6cf7f63a166525885d5c0f7d
data/README.md CHANGED
@@ -14,8 +14,20 @@ gem 'yt_util'
14
14
 
15
15
  Usage notes will come in time. Feel free to look at the source code as it's rather short.
16
16
 
17
+ Methods available:
18
+ ```ruby
19
+ YtUtil::Scrape.raw_query(search, filters = "")
20
+ YtUtil::Scrape.query(search = nil, filters = "", &qry)
21
+ YtUtil::Scrape.raw_video_stats(video_code)
22
+ YtUtil::Scrape.video_stats(video_code = nil, &qry)
23
+ YtUtil::Scrape.raw_user_stats(username)
24
+ YtUtil::Scrape.user_stats(username = nil, &qry)
25
+ YtUtil::URL.generate(video_code, options = {})
26
+ ```
27
+
17
28
  ## NOTE
18
- > Any scraping features can break at anytime if Youtube chooses to change their page layout.
29
+ > Any scraping results may become unavailable at anytime if Youtube chooses to change their page layout.
30
+ This library is designed to return nil for any data it fails to scrape.
19
31
 
20
32
  ## Contribute
21
33
 
@@ -61,8 +61,8 @@ module YtUtil
61
61
  query_result.css("ol.item-section > li")[1..-1].map do |result|
62
62
  {
63
63
  title: try {result.css("div:nth-child(1)").css("div:nth-child(2)").css("h3").text},
64
- video: try {result.css("div:nth-child(1)").css("div:nth-child(2)").css("h3 > a").first[:href].dup.tap{|i|i.replace i[(i.index("=").to_i+1)..-1]}},
65
- views: try {result.css('li').select {|i| i.text =~ /^[\d,]{1,} views/ }.first.text.split.first.gsub(",","_").to_i},
64
+ video: try {result.css('a').map { |i| i.attributes["href"]}.try(:[],0).try(:value).try(:match,/\?v=(.{11})/).try(:[],1)},
65
+ views: try {result.css('li').select {|i| i.try(:text) =~ /^[\d,]{1,} views/ }.first.try(:text).try(:split).try(:first).try(:gsub,",","_").to_i},
66
66
  new: try {!!result.css("div:nth-child(1)").css("div:nth-child(2)").css("div:nth-child(4)").css("ul:nth-child(1)").text["New"]},
67
67
  hd: try {!!result.css("div:nth-child(1)").css("div:nth-child(2)").css("div:nth-child(4)").css("ul:nth-child(1)").text["HD"]},
68
68
  description: try {result.css("div:nth-child(1)").css("div:nth-child(2)").css(".yt-lockup-description").text},
@@ -4,6 +4,8 @@ module YtUtil
4
4
  # Recommended included options for embedded video
5
5
  # {:embed => true, :autoplay => true, :origin => request.env["REQUEST_URI"]}
6
6
  def self.generate(video_code, options = {})
7
+ raise "Invalid object type" unless video_code.is_a? String
8
+ raise "Invalid video code" unless video_code.length == 11
7
9
  options.default = false
8
10
  parameters = "?"
9
11
  parameters.define_singleton_method(:ingest) {|item| self.<<("&") unless self[-1]["?"]; self.replace self.<<(item) }
@@ -1,3 +1,3 @@
1
1
  module YtUtil
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark