ruby_legendas_tv 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruby_legendas_tv/home_parser.rb +39 -0
- data/lib/ruby_legendas_tv/movie.rb +10 -0
- data/lib/ruby_legendas_tv/search_engine.rb +46 -0
- data/lib/ruby_legendas_tv/subtitle.rb +66 -0
- data/lib/ruby_legendas_tv/title.rb +11 -0
- data/lib/ruby_legendas_tv/website_utils.rb +33 -0
- data/lib/ruby_legendas_tv.rb +37 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2a0d53e10d26b90a085e1b90eeeeb021c176712
|
4
|
+
data.tar.gz: 53372597d786b399886ba053b4c3e8fc6af0cdc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5a69842596ba945b6d12efd80e3bb3bb58a175bb344cf35eea10d2be1bc141a08e982a1d9dd998d8878daf688ff1b6787ee18e3a0af2411959b1a5df9546127
|
7
|
+
data.tar.gz: 0e790d6b560fc5cc3785af5c56b5a375c62e96479a5426791f5bf44a01ae399e4a612a0395afe129690af066f475257240eeea689ae474af7b61a79e2b41a3df
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class HomeParser
|
2
|
+
def self.get_most_downloaded_subtitles(base_url)
|
3
|
+
|
4
|
+
document = WebsiteUtils.open_document(base_url)
|
5
|
+
|
6
|
+
subtitles = Array.new
|
7
|
+
items_div = document.css('div.item').children
|
8
|
+
items_div.each{|link|
|
9
|
+
#puts link['href']
|
10
|
+
subtitle = Subtitle.get_subtitle_from_link(base_url, link['href'])
|
11
|
+
subtitles.push(subtitle)
|
12
|
+
}
|
13
|
+
subtitles
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_highlights(base_url, page=1)
|
17
|
+
link = 'util/carrega_destaques'
|
18
|
+
if page != 1
|
19
|
+
link = link+'/todos/page:' + page.to_s
|
20
|
+
end
|
21
|
+
document = WebsiteUtils.open_document(base_url+link)
|
22
|
+
|
23
|
+
unless document.nil?
|
24
|
+
subtitles = Array.new
|
25
|
+
items_div = document.css('div.galery').css('div.clearfix').children
|
26
|
+
items_div.each{|link|
|
27
|
+
unless link.nil?
|
28
|
+
a = link.children.css('a')
|
29
|
+
unless a.nil? || a.empty?
|
30
|
+
href = a.attr('href')
|
31
|
+
subtitle = Subtitle.get_subtitle_from_link(base_url, href)
|
32
|
+
subtitles.push(subtitle)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
}
|
36
|
+
subtitles
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
class SearchEngine
|
4
|
+
def self.search_subtitle(base_url, query, page=1)
|
5
|
+
unless query.nil?
|
6
|
+
query = URI.escape(query)
|
7
|
+
link = 'util/carrega_legendas_busca/termo:' + query
|
8
|
+
if page != 1
|
9
|
+
link = link + '/page:' + page
|
10
|
+
end
|
11
|
+
document = WebsiteUtils.open_document(base_url+link)
|
12
|
+
unless document.nil?
|
13
|
+
subtitles = Array.new
|
14
|
+
urls = WebsiteUtils.get_article_urls(document)
|
15
|
+
urls.each_pair do |url, language|
|
16
|
+
subtitle = Subtitle.get_subtitle_from_link(base_url, url, language)
|
17
|
+
subtitles.push(subtitle)
|
18
|
+
end
|
19
|
+
subtitles
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.search_title(base_url, query)
|
25
|
+
unless query.nil?
|
26
|
+
query = URI.escape(query)
|
27
|
+
link = 'busca?q=' + query
|
28
|
+
|
29
|
+
document = WebsiteUtils.open_document(base_url+link)
|
30
|
+
unless document.nil?
|
31
|
+
titles = Array.new
|
32
|
+
items_div = document.css('div.slider').children.css('div.item')
|
33
|
+
items_div.each{|link|
|
34
|
+
url = link.css('a').attr('href').text
|
35
|
+
img_url = link.css('img').attr('src').text
|
36
|
+
name = link.css('span').text
|
37
|
+
description = link.css('p').text
|
38
|
+
|
39
|
+
title = Title.new(name, description, img_url, url)
|
40
|
+
titles.push(title)
|
41
|
+
}
|
42
|
+
titles
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Subtitle
|
2
|
+
attr_accessor :movie, :release, :date, :uploader, :download_num, :download_link, :likes, :unlikes, :description, :lang
|
3
|
+
|
4
|
+
def initialize(movie, release, date, uploader, download_num, download_link, likes, unlikes, description, lang=nil)
|
5
|
+
@movie = movie
|
6
|
+
@release = release
|
7
|
+
@date = date
|
8
|
+
@uploader = uploader #not implemented yet
|
9
|
+
@download_num = download_num
|
10
|
+
@download_link = download_link
|
11
|
+
@likes = likes #not implemented yet
|
12
|
+
@unlikes = unlikes #not implemented yet
|
13
|
+
@description = description
|
14
|
+
@lang=lang
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_subtitle_from_link(base_url, link, lang=nil)
|
18
|
+
if link.nil?
|
19
|
+
return nil
|
20
|
+
else
|
21
|
+
page = WebsiteUtils.open_document(base_url+link)
|
22
|
+
if page.nil?
|
23
|
+
return nil
|
24
|
+
else
|
25
|
+
info = page.css('div.middle').css('section.first')
|
26
|
+
movie_title = info.css('h3').text
|
27
|
+
movie_description = info.css('h5').text
|
28
|
+
movie_sinopsis = info.css('div.t1').css('p').text
|
29
|
+
movie_img = info.css('img').attr('src')
|
30
|
+
|
31
|
+
movie = Movie.new(movie_title, movie_description, movie_sinopsis, movie_img)
|
32
|
+
|
33
|
+
release = page.css('h2')[0].text
|
34
|
+
date = page.css('span.date').text
|
35
|
+
hour = page.css('span.hour').text
|
36
|
+
if hour.nil?
|
37
|
+
datetime=Date.new(date)
|
38
|
+
else
|
39
|
+
datetime = DateTime.strptime(date + ' ' + hour, '%d/%m/%Y %Hh%M')
|
40
|
+
end
|
41
|
+
download_num = page.css('span.number').text.to_i
|
42
|
+
description = page.css('div.t2').css('p').text
|
43
|
+
download_link = page.css('button.icon_arrow').attr('onclick').text
|
44
|
+
download_link = download_link.gsub("window.open('", '')
|
45
|
+
download_link = download_link.gsub("', '_self')", '')
|
46
|
+
|
47
|
+
subtitle = Subtitle.new(movie, release, datetime, nil, download_num, download_link, nil, nil, description, lang)
|
48
|
+
subtitle
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.get_subtitles_from_title(base_url, title)
|
54
|
+
link = title.link
|
55
|
+
document = WebsiteUtils.open_document(base_url+link)
|
56
|
+
unless document.nil?
|
57
|
+
subtitles = Array.new
|
58
|
+
urls = WebsiteUtils.get_article_urls(document)
|
59
|
+
urls.each_pair do |url, language|
|
60
|
+
subtitle = self.get_subtitle_from_link(base_url, url, language)
|
61
|
+
subtitles.push(subtitle)
|
62
|
+
end
|
63
|
+
subtitles
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Title
|
2
|
+
attr_accessor :name, :description, :image_url, :link, :id
|
3
|
+
|
4
|
+
def initialize(name, description, image_url, link)
|
5
|
+
@name = name
|
6
|
+
@description = description
|
7
|
+
@image_url = image_url
|
8
|
+
@id = link.split('/').last.split(':').last
|
9
|
+
@link = link
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
class WebsiteUtils
|
4
|
+
#Returns a hash where key is link and value is the language of subtitle
|
5
|
+
def self.get_article_urls(document)
|
6
|
+
unless document.nil?
|
7
|
+
links = Hash.new
|
8
|
+
items_div = document.css('div.gallery').css('article').children
|
9
|
+
#puts items_div.inspect
|
10
|
+
items_div.each{|link|
|
11
|
+
links[link.css('a').attr('href').text] = link.css('img').attr('title')
|
12
|
+
}
|
13
|
+
links
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.open_document(url, tries=0)
|
18
|
+
begin
|
19
|
+
if tries > 3
|
20
|
+
return nil
|
21
|
+
else
|
22
|
+
status = Timeout::timeout(30) {
|
23
|
+
document = Nokogiri::HTML(open(url, "User-Agent" => "Chrome/15.0.874.121"))
|
24
|
+
return document
|
25
|
+
}
|
26
|
+
end
|
27
|
+
rescue Timeout::Error
|
28
|
+
puts 'Timeout error... Trying again'
|
29
|
+
document = open_document(url, tries+1)
|
30
|
+
return document
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
load 'lib/ruby_legendas_tv/home_parser.rb'
|
6
|
+
load 'lib/ruby_legendas_tv/movie.rb'
|
7
|
+
load 'lib/ruby_legendas_tv/search_engine.rb'
|
8
|
+
load 'lib/ruby_legendas_tv/subtitle.rb'
|
9
|
+
load 'lib/ruby_legendas_tv/title.rb'
|
10
|
+
load 'lib/ruby_legendas_tv/website_utils.rb'
|
11
|
+
|
12
|
+
class RubyLegendasTv
|
13
|
+
|
14
|
+
@@base_url = "http://legendas.tv/"
|
15
|
+
|
16
|
+
public
|
17
|
+
|
18
|
+
def self.search_titles(query)
|
19
|
+
SearchEngine.search_title(@@base_url, query)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.search_subtitles_from_title(title)
|
23
|
+
Subtitle.get_subtitles_from_title(@@base_url, title)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.search_subtitles(query)
|
27
|
+
SearchEngine.search_subtitle(@@base_url, query)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_most_downloaded_subtitles
|
31
|
+
HomeParser.get_most_downloaded_subtitles(@@base_url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_highlights(page=1)
|
35
|
+
HomeParser.get_highlights(@@base_url, page)
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_legendas_tv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gustavo Chapim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem for LegendasTV new website
|
14
|
+
email: gustavo.chapim@ufrj.br
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ruby_legendas_tv.rb
|
20
|
+
- lib/ruby_legendas_tv/home_parser.rb
|
21
|
+
- lib/ruby_legendas_tv/movie.rb
|
22
|
+
- lib/ruby_legendas_tv/search_engine.rb
|
23
|
+
- lib/ruby_legendas_tv/subtitle.rb
|
24
|
+
- lib/ruby_legendas_tv/title.rb
|
25
|
+
- lib/ruby_legendas_tv/website_utils.rb
|
26
|
+
homepage: http://rubygems.org/gems/ruby_legendas_tv
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.0.14
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: RubyLegendasTv!
|
50
|
+
test_files: []
|