meuh 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/meuh +1 -1
- data/lib/meuh.rb +12 -6
- data/lib/meuh/formatting.rb +4 -4
- data/tests/formatting_tests.rb +60 -0
- data/tests/query_tests.rb +88 -0
- data/tests/tests.rb +61 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12129f88831e373a1c718dbd93b7244b3ac7b22b
|
4
|
+
data.tar.gz: 6a5193cfdc69968d92c36bdd1344083317fbca49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ef7bca9c01debbc8cefa08ba00d8dfc0c0dec2435f0968dd6f63e7b4f876212a1c2f13ab7d899c5ad515a6d7085b88921d812694c5658a9d497f40ba29f1a6
|
7
|
+
data.tar.gz: 86b50d7811ef7db789159dbacdac443e0b1eaa27d5a484ea179d87a1b17975c27437c49eb4d685c6d40d65cc8d08e04125bc0fc31452f8cb05933588221a080c
|
data/bin/meuh
CHANGED
data/lib/meuh.rb
CHANGED
@@ -11,13 +11,17 @@ module Meuh
|
|
11
11
|
class << self
|
12
12
|
|
13
13
|
def version
|
14
|
-
'0.1.
|
14
|
+
'0.1.2'
|
15
15
|
end
|
16
16
|
|
17
17
|
def url
|
18
18
|
'http://www.radiomeuh.com/meuh/playlist/index.php'
|
19
19
|
end
|
20
20
|
|
21
|
+
def user_agent
|
22
|
+
"Meuh/#{version} +github.com/bfontaine/meuh"
|
23
|
+
end
|
24
|
+
|
21
25
|
# Get the text of an element. This is an helper for internal usage.
|
22
26
|
def text(el)
|
23
27
|
el.text.strip.gsub(/\r/, "\n")
|
@@ -38,11 +42,11 @@ module Meuh
|
|
38
42
|
# :remaining => "...", <-- remaining time
|
39
43
|
# :time => "..." <-- time for previous tracks
|
40
44
|
# }
|
41
|
-
def tracks
|
42
|
-
opts = opts[0] || {}
|
45
|
+
def tracks
|
43
46
|
tracks = { :previous => [], :current => nil, :next => [] }
|
44
47
|
|
45
|
-
|
48
|
+
html = open(url, 'User-Agent' => user_agent).read.encode!(Encoding::UTF_8)
|
49
|
+
doc = Nokogiri::HTML(html)
|
46
50
|
|
47
51
|
def parse_track t
|
48
52
|
lines = t.inner_html.split(/<br\/?\s*>/).map do |l|
|
@@ -56,12 +60,14 @@ module Meuh
|
|
56
60
|
artist = nil
|
57
61
|
end
|
58
62
|
|
63
|
+
time = lines[0].strip
|
64
|
+
|
59
65
|
{
|
60
66
|
:artist => artist,
|
61
67
|
:album => lines[2].strip,
|
62
68
|
:title => title,
|
63
69
|
:remaining => t.css('font').text.gsub(/^:\s+/, ''),
|
64
|
-
:time =>
|
70
|
+
:time => time == '...' ? '' : time
|
65
71
|
}
|
66
72
|
end
|
67
73
|
|
@@ -76,7 +82,7 @@ module Meuh
|
|
76
82
|
tracks[:next] << parse_track(td)
|
77
83
|
end
|
78
84
|
else
|
79
|
-
tracks[:previous] << parse_track(td)
|
85
|
+
tracks[:previous] << parse_track(td) unless td.text =~ /\(jingle\)/i
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
data/lib/meuh/formatting.rb
CHANGED
@@ -14,10 +14,10 @@ module Meuh
|
|
14
14
|
s = []
|
15
15
|
|
16
16
|
def track_text(t, style, color) # :previous, :next, :curr
|
17
|
-
title
|
18
|
-
artist
|
19
|
-
album
|
20
|
-
time
|
17
|
+
title = t[:title] || ''
|
18
|
+
artist = t[:artist]
|
19
|
+
album = t[:album]
|
20
|
+
time = style == :previous ? "[#{t[:time]}] " : ''
|
21
21
|
|
22
22
|
title.strip!
|
23
23
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
|
3
|
+
class Meuh_formatting_test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@tracks = {
|
7
|
+
:previous => [
|
8
|
+
{
|
9
|
+
:artist => 'Artist1',
|
10
|
+
:album => 'Album1',
|
11
|
+
:title => 'Track1',
|
12
|
+
:time => '00:01:01',
|
13
|
+
},
|
14
|
+
{
|
15
|
+
:artist => 'Artist2',
|
16
|
+
:album => 'Album2',
|
17
|
+
:title => 'Track2',
|
18
|
+
:time => '00:01:00',
|
19
|
+
},
|
20
|
+
{
|
21
|
+
:artist => 'Artist3',
|
22
|
+
:album => 'Album3',
|
23
|
+
:title => 'Track3',
|
24
|
+
:time => '00:00:45',
|
25
|
+
}
|
26
|
+
],
|
27
|
+
:current => {
|
28
|
+
:artist => nil,
|
29
|
+
:album => 'CurrBar',
|
30
|
+
:title => 'Current Track',
|
31
|
+
:time => '00:01:02'
|
32
|
+
},
|
33
|
+
:next => [
|
34
|
+
{
|
35
|
+
:artist => 'Foo',
|
36
|
+
:album => 'FooBar',
|
37
|
+
:title => 'Bar',
|
38
|
+
:time => ''
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_general_format_no_color
|
45
|
+
r = /^.+\n\nPreviously:\n(?:\* \[.*?\] .*\n)+\nNext:\n\* .+/
|
46
|
+
assert_not_nil(Meuh::Formatting.text(@tracks, false) =~ r)
|
47
|
+
assert_not_nil(Meuh::Formatting.text(@tracks, true) =~ r)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_general_format_color
|
51
|
+
r = /^.+\n\nPreviously:\n(?:\* \[.*?\] .*\n)+\nNext:\n\* .+/
|
52
|
+
assert_not_nil(Meuh::Formatting.text(@tracks, true) =~ r)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_color_reset
|
56
|
+
assert_equal(nil, Meuh::Formatting.text(@tracks, false).index("\e[0m"))
|
57
|
+
assert_not_nil(Meuh::Formatting.text(@tracks, true).index "\e[0m")
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/fake_responses'
|
4
|
+
|
5
|
+
class Meuh_query_test < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@url = Meuh.url
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_keys
|
12
|
+
t = Meuh.tracks
|
13
|
+
|
14
|
+
assert(t.has_key?(:previous))
|
15
|
+
assert(t.has_key?(:current))
|
16
|
+
assert(t.has_key?(:next))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_next_track
|
20
|
+
next_ary = Meuh.tracks[:next]
|
21
|
+
|
22
|
+
assert_equal(1, next_ary.count)
|
23
|
+
nextt = next_ary.first
|
24
|
+
|
25
|
+
assert(nextt.is_a?(Hash))
|
26
|
+
assert(nextt.has_key?(:artist))
|
27
|
+
assert(nextt.has_key?(:album))
|
28
|
+
assert(nextt.has_key?(:title))
|
29
|
+
assert(nextt.has_key?(:time))
|
30
|
+
|
31
|
+
assert_equal('Foo', nextt[:artist])
|
32
|
+
assert_equal('FooBar', nextt[:album])
|
33
|
+
assert_equal('Bar', nextt[:title])
|
34
|
+
assert_equal('', nextt[:time])
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_current_track
|
39
|
+
curr = Meuh.tracks[:current]
|
40
|
+
|
41
|
+
assert(curr.is_a?(Hash))
|
42
|
+
assert(curr.has_key?(:artist))
|
43
|
+
assert(curr.has_key?(:album))
|
44
|
+
assert(curr.has_key?(:title))
|
45
|
+
assert(curr.has_key?(:time))
|
46
|
+
|
47
|
+
assert_equal(nil, curr[:artist])
|
48
|
+
assert_equal('CurrBar', curr[:album])
|
49
|
+
assert_equal('Current Track', curr[:title])
|
50
|
+
assert_equal('00:01:02', curr[:time])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_previous_tracks
|
54
|
+
prev_ary = Meuh.tracks[:previous]
|
55
|
+
|
56
|
+
assert_equal(3, prev_ary.count)
|
57
|
+
|
58
|
+
assert(prev_ary[0].is_a?(Hash))
|
59
|
+
assert(prev_ary[1].is_a?(Hash))
|
60
|
+
assert(prev_ary[2].is_a?(Hash))
|
61
|
+
|
62
|
+
prev1 = prev_ary[0]
|
63
|
+
|
64
|
+
assert(prev1.is_a?(Hash))
|
65
|
+
assert(prev1.has_key?(:artist))
|
66
|
+
assert(prev1.has_key?(:album))
|
67
|
+
assert(prev1.has_key?(:title))
|
68
|
+
assert(prev1.has_key?(:time))
|
69
|
+
|
70
|
+
assert_equal('Artist1', prev1[:artist])
|
71
|
+
assert_equal('Album1', prev1[:album])
|
72
|
+
assert_equal('Track1', prev1[:title])
|
73
|
+
assert_equal('00:01:01', prev1[:time])
|
74
|
+
|
75
|
+
prev2 = prev_ary[1]
|
76
|
+
assert_equal('Artist2', prev2[:artist])
|
77
|
+
assert_equal('Album2', prev2[:album])
|
78
|
+
assert_equal('Track2', prev2[:title])
|
79
|
+
assert_equal('00:01:00', prev2[:time])
|
80
|
+
|
81
|
+
prev3 = prev_ary[2]
|
82
|
+
assert_equal('Artist3', prev3[:artist])
|
83
|
+
assert_equal('Album3', prev3[:album])
|
84
|
+
assert_equal('Track3', prev3[:title])
|
85
|
+
assert_equal('00:00:45', prev3[:time])
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/tests/tests.rb
CHANGED
@@ -14,6 +14,13 @@ for t in Dir.glob( File.join( test_dir, '*_tests.rb' ) )
|
|
14
14
|
require t
|
15
15
|
end
|
16
16
|
|
17
|
+
class FakeHTMLElement
|
18
|
+
attr_reader :text
|
19
|
+
def initialize(text)
|
20
|
+
@text = text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
17
24
|
class MeuhTests < Test::Unit::TestCase
|
18
25
|
|
19
26
|
# == Meuh#version == #
|
@@ -22,6 +29,60 @@ class MeuhTests < Test::Unit::TestCase
|
|
22
29
|
assert(Meuh.version =~ /^\d+\.\d+\.\d+/)
|
23
30
|
end
|
24
31
|
|
32
|
+
# == Meuh#url == #
|
33
|
+
def test_meuh_url
|
34
|
+
assert(Meuh.url =~ /^https?:\/\//)
|
35
|
+
end
|
36
|
+
|
37
|
+
# == Meuh#user_agent == #
|
38
|
+
|
39
|
+
def test_meuh_ua
|
40
|
+
assert(Meuh.user_agent =~ /^Meuh\/\d+\.\d+\.\d+/)
|
41
|
+
end
|
42
|
+
|
43
|
+
# == Meuh#text == #
|
44
|
+
|
45
|
+
def test_meuh_text_empty
|
46
|
+
e = FakeHTMLElement.new ''
|
47
|
+
assert_equal('', Meuh.text(e))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_meuh_text_spaces
|
51
|
+
e = FakeHTMLElement.new ' '
|
52
|
+
assert_equal('', Meuh.text(e))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_meuh_text_strip
|
56
|
+
txt = ' foobar '
|
57
|
+
e = FakeHTMLElement.new txt
|
58
|
+
assert_equal(txt.strip, Meuh.text(e))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_meuh_text_newlines1
|
62
|
+
txt = "foo\rbar"
|
63
|
+
e = FakeHTMLElement.new txt
|
64
|
+
assert_equal(txt.sub(/\r/, "\n"), Meuh.text(e))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_meuh_text_newlines2
|
68
|
+
txt = "foo\nbar"
|
69
|
+
e = FakeHTMLElement.new txt
|
70
|
+
assert_equal(txt, Meuh.text(e))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_meuh_text
|
74
|
+
txt = 'foobar'
|
75
|
+
e = FakeHTMLElement.new txt
|
76
|
+
assert_equal(txt, Meuh.text(e))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_meuh_text_wrong_element
|
80
|
+
assert_equal('', Meuh.text(nil))
|
81
|
+
assert_equal('', Meuh.text([]))
|
82
|
+
assert_equal('', Meuh.text({}))
|
83
|
+
assert_equal('', Meuh.text('foo'))
|
84
|
+
end
|
85
|
+
|
25
86
|
end
|
26
87
|
|
27
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meuh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Baptiste Fontaine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -118,6 +118,8 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- lib/meuh.rb
|
120
120
|
- lib/meuh/formatting.rb
|
121
|
+
- tests/formatting_tests.rb
|
122
|
+
- tests/query_tests.rb
|
121
123
|
- tests/tests.rb
|
122
124
|
- bin/meuh
|
123
125
|
homepage: https://github.com/bfontaine/meuh-cli
|
@@ -145,4 +147,6 @@ signing_key:
|
|
145
147
|
specification_version: 4
|
146
148
|
summary: scrapper for radiomeuh.com's current playlist
|
147
149
|
test_files:
|
150
|
+
- tests/formatting_tests.rb
|
151
|
+
- tests/query_tests.rb
|
148
152
|
- tests/tests.rb
|