-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample_scrobbler.php
executable file
·108 lines (91 loc) · 3.27 KB
/
example_scrobbler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require_once 'Scrobbler.php';
class example_scrobbler
{
var $help = false;
var $appname, $debug;
var $password, $api_key, $api_secret, $api_sk, $clientId, $clientVer, $source = 'P', $rating, $mbTrackId;
function main($argc, $argv) {
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
try
{
$this->parseOptions($argv);
if($this->help)
{
$this->usage($this->appname, $argv);
return;
}
$scrobbler = new md_Scrobbler($this->username, $this->password,
$this->api_key, $this->api_secret, $this->api_sk,
$this->clientId, $this->clientVer);
$scrobbler->debug = $this->debug;
$scrobbler->add($this->artist, $this->track, $this->album, $this->trackDuration,
$this->scrobbleTime, $this->trackNumber, $this->source, $this->rating,
$this->mbTrackId);
$scrobbler->submit();
echo "Done\n";
}
catch(Exception $e)
{
echo $e->getMessage() . "\n";
echo "Try $appname --help\n";
}
}
function usage($appname, array $argv)
{
echo "Usage: {$appname} [OPTIONS]\n";
echo " --help: This message.\n\n";
echo " --username: last.fm username\n";
echo " --password: last.fm password (optional)\n";
echo " --api_key: You can use api_key, api_secret and api_sk instead of password.\n";
echo " --api_secret\n";
echo " --api_sk\n";
echo "\n";
echo " --clientId Something like TST\n";
echo " --clientVer Something like 1.0\n";
echo "\n";
echo "Data for the actual scrobble: --artist --track --scrobbleTime --trackDuration\n";
echo " --album --trackNumber --source --rating --mbTrackId\n";
echo "\n";
}
function parseOptions(array $argv)
{
$this->appname = array_shift($argv);
while($arg = array_shift($argv))
{
if($arg == '--help' || $arg == '-h')
{
$this->help = true;
return;
}
if($arg == '--debug')
{
$this->debug = true;
continue;
}
$this->parseOption($arg, $argv);
}
}
function parseOption($arg, &$argv)
{
$options = array( 'username', 'password', 'api_key', 'api_secret', 'api_sk',
'clientId', 'clientVer',
'artist', 'track', 'scrobbleTime', 'trackDuration', 'album',
'trackNumber', 'source', 'rating', 'mbTrackId' );
foreach($options as $option_name)
{
if($arg == '--' . $option_name)
{
$this->$option_name = array_shift($argv);
if($this->debug)
{
echo "Saw --" . $option_name . " as " . $this->$option_name . "\n";
}
return;
}
}
}
}
$example_scrobbler = new example_scrobbler();
$example_scrobbler->main($argc, $argv);