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 +4 -4
- data/README.md +13 -1
- data/lib/yt_util/scrape.rb +2 -2
- data/lib/yt_util/url.rb +2 -0
- data/lib/yt_util/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c902427a3738d2f25906a56a4617e9235b8e3f7
|
4
|
+
data.tar.gz: d82c5058ce703d46aa97853acf80e49a4d2f5a7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
data/lib/yt_util/scrape.rb
CHANGED
@@ -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(
|
65
|
-
views: try {result.css('li').select {|i| i.text =~ /^[\d,]{1,} views/ }.first.text.split.first.gsub
|
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},
|
data/lib/yt_util/url.rb
CHANGED
@@ -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) }
|
data/lib/yt_util/version.rb
CHANGED