tinyscrobbler 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +1 -0
- data/README.md +41 -8
- data/example.rb +18 -0
- data/lib/{audiometa.rb → parser.rb} +11 -9
- data/lib/tinyscrobbler.rb +1 -0
- metadata +3 -3
data/Changelog
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
soon...
|
data/README.md
CHANGED
@@ -1,41 +1,74 @@
|
|
1
|
+
# Tinyscrobbler
|
2
|
+
|
1
3
|
Tinyscrobbler is a lightweight LastFM track scrobbler library that allows to quickly incorporate the track scrobbling feature in a ruby player app.
|
2
4
|
|
3
|
-
I'm currently learning ruby, so it's very likely that
|
5
|
+
I'm currently learning ruby, so it's very likely that this is not the best ruby code you've ever seen. But it works and I'll be optimizing it as I learn more about the language.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
In order to install Tinyscrobbler you have to download the latest gem from [gemcutter.org](http://gemcutter.org). If you've never installed a gem from gemcutter you need to add it to your sources:
|
10
|
+
|
11
|
+
$ gem sources -a http://gemcutter.org
|
12
|
+
|
13
|
+
Then install the gem just like any other:
|
14
|
+
|
15
|
+
$ gem install tinyscrobbler
|
16
|
+
|
17
|
+
Depending on your system, you might need to use `sudo` to execute gem commands.
|
18
|
+
|
19
|
+
## How to use
|
20
|
+
|
21
|
+
Some code example on how to use tinyscrobbler:
|
4
22
|
|
5
|
-
|
23
|
+
### Without parsing metadata
|
6
24
|
|
7
|
-
|
25
|
+
In this usage example you need to provide the track info (metadata), like artist name, album, song title etc. This is the recommended method, but you have to get the track info yourself.
|
26
|
+
|
27
|
+
|
28
|
+
require 'rubygems'
|
29
|
+
require 'tinyscrobbler'
|
8
30
|
|
9
31
|
ls = Tinyscrobbler::Client.new(lastfm_username, lasftfm_password)
|
10
32
|
|
11
33
|
# Currently listening to...
|
12
34
|
|
13
35
|
current_track = {'artistname' => 'Moonspell', 'track' => 'Alma Mater',
|
14
|
-
'time' =>
|
36
|
+
'time' => Time.now.to_s, 'source' => 'P', 'rating' => '',
|
15
37
|
'secs' => '337', 'album' => 'Wolfheart', 'tracknumber' => '8', 'mbtrackid' => ''}
|
16
38
|
|
17
39
|
ls.now_playing(current_track)
|
18
40
|
|
19
41
|
# after track played
|
20
|
-
|
42
|
+
|
43
|
+
# you need to submit this only after
|
44
|
+
# half of the track length has passed
|
45
|
+
# or lastfm may ignore the submission
|
46
|
+
|
21
47
|
ls.played(current_track)
|
22
48
|
|
49
|
+
### Parsing metadata
|
50
|
+
|
23
51
|
If you prefer to have tinyscrobbler parse the audio metadata for you, here's an example on how to do it.
|
24
|
-
Please notice that currently on mp3 files are supported,
|
52
|
+
Please notice that currently on mp3 files are supported (other formats are under development), this feature is the main reason why the "mp3info" gem is a dependency.
|
25
53
|
|
54
|
+
require 'rubygems'
|
26
55
|
require 'tinyscrobbler'
|
27
|
-
require 'audiometa.rb'
|
28
56
|
|
29
57
|
ls = Tinyscrobbler::Client.new(lastfm_username, lasftfm_password)
|
30
58
|
|
31
59
|
# Currently listening to...
|
32
60
|
file_path = '/Users/rogeriopvl/Music/Moonspell/Wolfheart/08_Alma_Mater.mp3'
|
33
|
-
|
61
|
+
parser = Tinyscrobbler::Parser.new(file_path)
|
62
|
+
current_track = parser.metadata
|
34
63
|
|
35
64
|
ls.now_playing(current_track)
|
36
65
|
|
37
66
|
# after track played
|
38
67
|
|
68
|
+
# you need to submit this only after
|
69
|
+
# half of the track length has passed
|
70
|
+
# or lastfm may ignore the submission
|
71
|
+
|
39
72
|
ls.played(current_track)
|
40
73
|
|
41
74
|
|
data/example.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'tinyscrobbler.rb'
|
3
|
+
|
4
|
+
ls = Tinyscrobbler::Client.new(lastfm_username, lastfm_password)
|
5
|
+
|
6
|
+
# Currently listening to...
|
7
|
+
|
8
|
+
current_track = {'artistname' => 'Moonspell', 'track' => 'Alma Mater',
|
9
|
+
'time' => '1262185646', 'source' => 'P', 'rating' => '',
|
10
|
+
'secs' => '337', 'album' => 'Wolfheart', 'tracknumber' => '8', 'mbtrackid' => ''}
|
11
|
+
|
12
|
+
ls.now_playing(current_track)
|
13
|
+
|
14
|
+
# after track played
|
15
|
+
|
16
|
+
ls.played(current_track)
|
17
|
+
|
18
|
+
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'mp3info'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Tinyscrobbler
|
5
5
|
|
6
6
|
# This class parses metadata from audio files.
|
7
7
|
# It currently supports only mp3 files.
|
8
8
|
|
9
9
|
class Parser
|
10
|
+
|
11
|
+
attr_accessor :metadata
|
10
12
|
|
11
13
|
# Checks if given file exists and if is supported,
|
12
14
|
# and calls the parser method, if not
|
@@ -15,10 +17,10 @@ module Audiometa
|
|
15
17
|
def initialize(file_path)
|
16
18
|
@path = file_path
|
17
19
|
raise 'File not found or unreadable.' unless File.exists? @path and File.readable? @path
|
18
|
-
@extension = File.extname(file_path)
|
20
|
+
@extension = File.extname(file_path).downcase
|
19
21
|
raise 'Not a valid audio file.' unless @extension == '.mp3'
|
20
22
|
|
21
|
-
parse_metadata
|
23
|
+
@metadata = parse_metadata
|
22
24
|
end
|
23
25
|
|
24
26
|
private
|
@@ -27,13 +29,13 @@ module Audiometa
|
|
27
29
|
|
28
30
|
def parse_metadata
|
29
31
|
track = Mp3Info.new(@path)
|
30
|
-
tag = track.
|
31
|
-
|
32
|
+
tag = track.hastag1? ? track.tag1 : track.tag2
|
33
|
+
|
32
34
|
track_meta = {}
|
33
|
-
track_meta['track'] = tag.title
|
34
|
-
track_meta['artistname'] = tag.artist
|
35
|
-
track_meta['album'] = tag.album
|
36
|
-
track_meta['tracknumber'] = tag.tracknum.to_s
|
35
|
+
track_meta['track'] = track.hastag1? ? tag.title : tag.TIT2
|
36
|
+
track_meta['artistname'] = track.hastag1? ? tag.artist : tag.TPE1
|
37
|
+
track_meta['album'] = track.hastag1? ? tag.album : tag.TALB
|
38
|
+
track_meta['tracknumber'] = track.hastag1? ? tag.tracknum.to_s : tag.TRCK.to_s
|
37
39
|
track_meta['secs'] = track.length.round.to_s
|
38
40
|
track_meta['time'] = Time.now.to_s
|
39
41
|
track_meta['source'] = 'P'
|
data/lib/tinyscrobbler.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinyscrobbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rogerio Vicente
|
@@ -35,7 +35,7 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Changelog
|
37
37
|
- example.rb
|
38
|
-
- lib/
|
38
|
+
- lib/parser.rb
|
39
39
|
- lib/tinyscrobbler.rb
|
40
40
|
has_rdoc: true
|
41
41
|
homepage: http://github.com/rogeriopvl/tinyscrobbler
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version:
|
61
61
|
requirements: []
|
62
62
|
|
63
|
-
rubyforge_project:
|
63
|
+
rubyforge_project:
|
64
64
|
rubygems_version: 1.3.5
|
65
65
|
signing_key:
|
66
66
|
specification_version: 3
|