recochoku-chart 0.0.0
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/recochoku-chart.rb +95 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 7fdc9872e24ef46ea50c6cb4e48bbd03f4681677
|
|
4
|
+
data.tar.gz: 72346eadceb49d06a0b09adc22bebdcfe116c433
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a348359deac5240c4ffdb1df47a4e0820268944dcf1e34cd84d409d7435b6e5a34f77c2fbe4beddb2ee1362f45a5cb6e40efcb57b396a4298992658557e1b8dc
|
|
7
|
+
data.tar.gz: 0127f8bf343d0d46bcae851bb6399f01c2aa634a741da4b76e8826ac5a661cf79ce6151734338f861b6a9277be90ce26aeb76d2a1b4d3f29784ca6ed6aee9043
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'mechanize'
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Represents an Recochoku music chart, found at http://recochoku.jp/ranking/
|
|
5
|
+
#
|
|
6
|
+
# Attributes:
|
|
7
|
+
# => url - HTTP url of chart
|
|
8
|
+
# => rankings - Array of RecochokuRanks containing data for individual tracks.
|
|
9
|
+
##
|
|
10
|
+
class RecochokuChart
|
|
11
|
+
attr_reader :url, :rankings
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# Creates a new chart with rank data.
|
|
15
|
+
#
|
|
16
|
+
# Params:
|
|
17
|
+
# => chart (optional) - specifies which chart to download.
|
|
18
|
+
#
|
|
19
|
+
# If no specific chart is specified, then it defaults to the Daily Singles Chart.
|
|
20
|
+
#
|
|
21
|
+
##
|
|
22
|
+
def initialize(chart = nil)
|
|
23
|
+
if (!chart)
|
|
24
|
+
chart = "single/daily"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@url = "http://recochoku.jp/ranking/" + chart + "/"
|
|
28
|
+
|
|
29
|
+
# Get all chart data
|
|
30
|
+
@rankings = url_to_ranks(@url)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Prints chart out in a nice form
|
|
34
|
+
def to_s
|
|
35
|
+
puts @rankings.map{ |f| f.num + ". '" + f.title + "' by " + f.artist }
|
|
36
|
+
end
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Given a URL, scrapes track titles and artists from HTML source
|
|
41
|
+
# and creates an array of RecochokuRank objects with it
|
|
42
|
+
#
|
|
43
|
+
# Params:
|
|
44
|
+
# => url - the url whose source will be scrapped
|
|
45
|
+
#
|
|
46
|
+
# Returns:
|
|
47
|
+
# => rank_list - array of RecochokuRanks
|
|
48
|
+
##
|
|
49
|
+
def url_to_ranks(url)
|
|
50
|
+
utr_agent = Mechanize.new
|
|
51
|
+
|
|
52
|
+
rank_list, title_list, artist_list = [], [], []
|
|
53
|
+
|
|
54
|
+
utr_agent = utr_agent.get(url)
|
|
55
|
+
|
|
56
|
+
# Track titles
|
|
57
|
+
utr_agent.search('td.info a.ttl').children.each do |c|
|
|
58
|
+
title_list.push(c.text)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Artist titles
|
|
62
|
+
utr_agent.search('td.info p a:not(:has(img))').children.each do |d|
|
|
63
|
+
artist_list.push(d.text)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
0.upto(49) do |i|
|
|
67
|
+
rank_list.push(RecochokuRank.new((i + 1).to_s, title_list[i], artist_list[i]))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return rank_list
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# Represents a ranked musical item in an Recochoku chart.
|
|
76
|
+
#
|
|
77
|
+
# Attributes:
|
|
78
|
+
# => num - current rank #
|
|
79
|
+
# => title - item title
|
|
80
|
+
# => artist - item artist
|
|
81
|
+
#
|
|
82
|
+
##
|
|
83
|
+
class RecochokuRank
|
|
84
|
+
attr_reader :num, :title, :artist
|
|
85
|
+
|
|
86
|
+
def initialize(num, title, artist)
|
|
87
|
+
@num = num
|
|
88
|
+
@title = title
|
|
89
|
+
@artist = artist
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def to_s
|
|
93
|
+
"#{@num}. '#{@title}' by #{@artist}"
|
|
94
|
+
end
|
|
95
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: recochoku-chart
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bryce Matsuda
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-12-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Fetches music chart data from Recochoku.co.jp
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/recochoku-chart.rb
|
|
20
|
+
homepage: http://github.com/brycematsuda/recochoku-chart
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 2.0.0
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.5.1
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Unofficial Recochoku music charts API
|
|
44
|
+
test_files: []
|