YoutubeVideoParser 0.0.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 +7 -0
- data/lib/youtubevideoparser.rb +47 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0025048bbdbbf847d2dd3e04f797f5a95eb1523f
|
4
|
+
data.tar.gz: 77b63af970cca5c1d5af70688d285776ab204979
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ac4047151521a8a5a66fe57ddb5f541bd1883aeca19b7cabb0613939082f49b6a91025b1403161f1a6cdf05211499cf46ece8582505e1339e23335e33baa637
|
7
|
+
data.tar.gz: 4794802174e690c31248750897d3e84af65d8f660e34b7a44e88b50be6b55be08943ac90ccf28f4247cacc080654b7fa96c1000aa0fc2635f2ec466ccf3d2ab5
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rexml/document'
|
3
|
+
include REXML
|
4
|
+
|
5
|
+
class YoutubeVideoParser
|
6
|
+
|
7
|
+
def initialize(user, num)
|
8
|
+
url_base = "http://gdata.youtube.com/feeds/api/users/#{user}/uploads?max-results=#{num}"
|
9
|
+
xml = Net::HTTP.get_response(URI.parse(url_base)).body
|
10
|
+
check_channel(xml)
|
11
|
+
@doc = REXML::Document.new(xml)
|
12
|
+
end
|
13
|
+
|
14
|
+
def video_list
|
15
|
+
video_paths = get_paths
|
16
|
+
video_titles = get_titles
|
17
|
+
|
18
|
+
Hash[video_titles.zip(video_paths)]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def get_titles
|
23
|
+
video_titles = Array.new
|
24
|
+
XPath.each(@doc, '//media:title') do |title|
|
25
|
+
title = String(title).split('>')
|
26
|
+
title = title[1].split('<')
|
27
|
+
video_titles << title[0]
|
28
|
+
end
|
29
|
+
video_titles
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_paths
|
33
|
+
video_paths = Array.new
|
34
|
+
XPath.each(@doc, '//media:player') do |video|
|
35
|
+
video_paths << video.attribute('url').to_s
|
36
|
+
end
|
37
|
+
video_paths
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_channel(xml)
|
41
|
+
if xml == 'User not found'
|
42
|
+
raise ArgumentError, xml
|
43
|
+
elsif
|
44
|
+
xml
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: YoutubeVideoParser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gláuber Brennon
|
8
|
+
- Mauricio Vieira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby script to parse Youtube channels listing title and link to the video
|
15
|
+
email: glauberbrennon@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/youtubevideoparser.rb
|
21
|
+
homepage: http://rubygems.org/gems/yvt
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: YoutubeVideoParser!
|
45
|
+
test_files: []
|