detektorfm 0.0.2
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/LICENSE.txt +25 -0
- data/README.md +31 -0
- data/Rakefile +33 -0
- data/VERSION +1 -0
- data/detektorfm.gemspec +30 -0
- data/lib/detektorfm.rb +83 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 97948505cdcf9b4cf5287ab4229718a05cf2ddee
|
4
|
+
data.tar.gz: 8057e2407bd3adcfd8080848a762174d57c44484
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cbd0b231b4cac18175ec41e374041b80041d4d4bba414fbcc162fd5d1cac18d1972d578296869a0086cd26cb298c734bad39db2d1ffa4168907484e63be09c7a
|
7
|
+
data.tar.gz: a8d8d79a8565d12abe9aa023ee0fdd3be8b8bdbdfab433384cedd3e36379d6176b7a8b5eef9b9c40a42ecce40da7ec0b3c2ba7d7deb87e53d35a2e5facb77ae6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Armin Widegreen
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
Redistributions in binary form must reproduce the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer in the documentation and/or
|
12
|
+
other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
18
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
21
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.jkj
|
24
|
+
All rights reserved.
|
25
|
+
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# detektorfm
|
2
|
+
|
3
|
+
Library for the *detektor.fm* website.
|
4
|
+
|
5
|
+
Features:
|
6
|
+
* querying last played songs
|
7
|
+
* most played artist in last 7 weeks
|
8
|
+
* ... to be extended ...
|
9
|
+
|
10
|
+
For example implementations, see awidegreen/detektorfm-tools
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install detektorfm
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Get an instance of `DetektorFm::MusikStream` or `DetektorFm::WortStream` and
|
22
|
+
start querying the playlist with `played()` or get specific stream url
|
23
|
+
`get_stream_url`.
|
24
|
+
|
25
|
+
|
26
|
+
## License
|
27
|
+
Licensed under BSD (2-Clause), see LICENSE.txt
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
[awidegreen](http://github.com/awidegreen)
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rake"
|
3
|
+
|
4
|
+
VERSION = File.read(File.join(".", "VERSION"))
|
5
|
+
|
6
|
+
desc "Build gem from gemspec"
|
7
|
+
task :build do
|
8
|
+
system "gem build detektorfm.gemspec"
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Deploy gem to rubygems.org"
|
12
|
+
task :deploy do
|
13
|
+
system "gem push detektorfm-#{VERSION.gsub( /\n/, "" )}.gem"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Tag git repo with release"
|
17
|
+
task :tag do
|
18
|
+
system "git tag v#{VERSION}"
|
19
|
+
puts "Tag v#{VERSION} created"
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Push tags to github"
|
23
|
+
task :push_tags do
|
24
|
+
system "git push --tags origin master"
|
25
|
+
end
|
26
|
+
|
27
|
+
#desc "Release new version: build, deploy, and tag"
|
28
|
+
#task :release do
|
29
|
+
#["build", "deploy", "tag", "push_tags"].each do |t|
|
30
|
+
#Rake::Task[t].reenable
|
31
|
+
#Rake::Task[t].invoke
|
32
|
+
#end
|
33
|
+
#end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/detektorfm.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path File.join(File.dirname(__FILE__), 'lib')
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require 'bundler'
|
6
|
+
require 'rake'
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = 'detektorfm'
|
10
|
+
s.version = File.read('VERSION').strip
|
11
|
+
s.date = '2013-09-24'
|
12
|
+
s.summary = 'detektorfm library'
|
13
|
+
s.description = 'Interfacing (Querying) the detektor.fm (webradio) website.'
|
14
|
+
s.authors = ["Armin Widegreen"]
|
15
|
+
s.email = 'armin.widegreen@gmail.com'
|
16
|
+
s.files = [
|
17
|
+
"lib/detektorfm.rb",
|
18
|
+
"detektorfm.gemspec",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"README.md",
|
22
|
+
"LICENSE.txt"
|
23
|
+
]
|
24
|
+
s.homepage = 'http://github.com/awidegreen/detektorfm'
|
25
|
+
s.license = 'BSD (2-Clause)'
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
|
28
|
+
s.add_runtime_dependency 'nokogiri'
|
29
|
+
end
|
30
|
+
|
data/lib/detektorfm.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
module DetektorFm
|
7
|
+
def self.most_played_artist_overall
|
8
|
+
Stream.new.most_played_artist
|
9
|
+
end
|
10
|
+
|
11
|
+
class Stream
|
12
|
+
@@PLAYLIST_URL = "http://detektor.fm/playlisten"
|
13
|
+
@@STREAM_URL = "http://detektor.fm/stream"
|
14
|
+
|
15
|
+
def played(limit = 100)
|
16
|
+
timetable = []
|
17
|
+
# only 100 are show per page, so iterate over page in case
|
18
|
+
# limit >100 requested
|
19
|
+
(limit/101+1).times do |i|
|
20
|
+
url = "#{get_playlist_url}/P#{i*100}"
|
21
|
+
html_doc = Nokogiri::HTML(open(url))
|
22
|
+
parse_htmldoc_played(html_doc) do |time, artist, title|
|
23
|
+
timetable << {:time => time, :artist => artist, :title => title}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
timetable[0,limit].each do |e|
|
28
|
+
yield e[:time], e[:artist], e[:title]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def most_played_artist
|
33
|
+
artists = []
|
34
|
+
url = "#{get_playlist_url}"
|
35
|
+
html_doc = Nokogiri::HTML(open(url))
|
36
|
+
html_doc.xpath('//ul[@class="tagcloud"]/li/a/text()').each do |a|
|
37
|
+
artists << a.to_s.strip
|
38
|
+
end
|
39
|
+
return artists
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_playlist_url
|
43
|
+
"#{@@PLAYLIST_URL}/#{get_stream_key}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_stream_url(type = :mp3)
|
47
|
+
"#{@@STREAM_URL}/#{type}/#{get_stream_key}"
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def parse_htmldoc_played(html_doc)
|
52
|
+
html_doc.xpath('//table[@class="timetable"]/tbody/tr').each do |row|
|
53
|
+
time = row.xpath('td[@class="time"]/text()').to_s.strip
|
54
|
+
#stream = row.xpath('td[@class="stream"]/a/text()').to_s.strip
|
55
|
+
artist = row.xpath('td[@class="artist"]/a/text()').to_s.strip
|
56
|
+
title = row.xpath('td[@class="title"]/text()').to_s.strip
|
57
|
+
|
58
|
+
yield time, artist, title
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class MusikStream < Stream
|
64
|
+
def get_stream_key
|
65
|
+
"musik"
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_name
|
69
|
+
"MusikStream"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class WortStream < Stream
|
74
|
+
def get_stream_key
|
75
|
+
"wort"
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_name
|
79
|
+
"WortStream"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: detektorfm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Armin Widegreen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Interfacing (Querying) the detektor.fm (webradio) website.
|
28
|
+
email: armin.widegreen@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/detektorfm.rb
|
34
|
+
- detektorfm.gemspec
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- README.md
|
38
|
+
- LICENSE.txt
|
39
|
+
homepage: http://github.com/awidegreen/detektorfm
|
40
|
+
licenses:
|
41
|
+
- BSD (2-Clause)
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.0.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: detektorfm library
|
63
|
+
test_files: []
|