Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r57]: trunk / yulastfm.pl Maximize Restore History

Download this file

yulastfm.pl    606 lines (558 with data), 19.5 kB

  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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#!/usr/bin/perl -w
# YuLastfm - Update Pidgin TUNE status from Last.fm
# Author: Chih-Chun Lin
# Project Homepage:
# https://sourceforge.net/projects/yulastfm/
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
use Purple;
use File::Basename;
use File::Path;
# use Gtk2 '-init';
# require Gtk2;
# program version
my $VERSION="0.4.0";
# global variable
our $plugin;
our $lastfm_account;
our $yulastfm_dir;
our $yulastfm_artworks_dir;
our $refresh_rate = "60";
our $presence;
our $timeout = 0;
our $cur_artist;
our $cur_title;
our $cur_album;
our $cur_date;
our $cmd_id = 0;
our $conv = 0;
our $mw;
our $ll=10; # length of list
our @btns;
our @tl; # track list
%PLUGIN_INFO = (
perl_api_version => 2,
name => "YuLastfm",
version => $VERSION,
summary => "This perl script is a plugin which help you update your " .
"\"now playing\" information from the Last.fm musical " .
"social network.",
description => "Updater for Pidgin TUNE status from Last.FM",
author => "Lin, Chih-Chun <linleno\@users.sourceforge.net>",
url => "https://sourceforge.net/projects/yulastfm/",
load => "plugin_load",
unload => "plugin_unload",
plugin_action_sub => "plugin_actions_cb",
prefs_info => "prefs_info_cb"
);
sub plugin_init {
return %PLUGIN_INFO;
}
sub plugin_load {
$plugin = shift;
dbg_msg( "plguin: " . $plugin);
Purple::Prefs::add_none( "/plugins/core/yulastfm");
Purple::Prefs::add_string( "/plugins/core/yulastfm/username", "");
Purple::Prefs::add_int( "/plugins/core/yulastfm/refreshing_rate", 60);
# update the tune status when refresh rate changed
Purple::Prefs::connect_callback(
$plugin,
"/plugins/core/yulastfm/refreshing_rate",
\&pref_rate_cb,
"refresh rate"
);
# # add item into a extended menu of blist node or conversation
# Purple::Signal::connect(
# Purple::BuddyList::get_handle(),
# "blist-node-extended-menu",
# $plugin,
# \&blist_node_extended_menu_cb,
# $plugin
# );
# slash command register
$cmd_id = Purple::Cmd::register(
$plugin,
"yulastfm",
"ws",
1000,
# PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS
0x01|0x02|0x08,
0,
\&cmd_cb,
"yulastfm: In an IM conversation, you can share the songs' links on Last.fm to your friend by using slash command /yulastfm. After you key-in slash command /yulastfm in your conversation box, a Gtk2 widget will pop up, and then you could click the track which you would like to share with your friend. YuLastfm will send the Last.fm link to your friend."
);
$yulastfm_dir = Purple::Util::user_dir() . "/yulastfm";
$yulastfm_artworks_dir = $yulastfm_dir."/artworks";
Purple::Util::build_dir( $yulastfm_artworks_dir, 0755);
dbg_msg( "Purple::Util::user_dir(): " . Purple::Util::user_dir());
refresh_tune();
dbg_msg("yulastfm loaded");
}
sub prefs_info_cb {
my $frame = Purple::PluginPref::Frame->new();
my $ppref = Purple::PluginPref->new_with_label("YuLastfm");
$ppref->set_type(2);
$frame->add($ppref);
$ppref = Purple::PluginPref->new_with_name_and_label(
"/plugins/core/yulastfm/username",
"Last.fm User");
$ppref->set_type(3); # PURPLE_PLUGIN_PREF_STRING_FORMAT
$frame->add($ppref);
$ppref = Purple::PluginPref->new_with_name_and_label(
"/plugins/core/yulastfm/refreshing_rate",
"Refresh Rate (in sec.)");
$ppref->set_type(3);
# If no bounds are assigned, the value will be restriced to 0
$ppref->set_bounds( 10, 300);
# this line shows how to call "etan" patched get_bounds()
# ( $min_v, $max_v) = $ppref->get_bounds();
$frame->add($ppref);
return $frame;
}
sub pref_rate_cb {
dbg_msg("pref_rate_cb: \"refresh rate\" changed");
if ($timeout) {
Purple::timeout_remove($timeout);
$timeout = 0;
}
refresh_tune();
}
sub plugin_actions_cb {
my @actions = ("Refresh Tune");
}
# sub blist_node_extended_menu_cb {
# dbg_msg("#Signal# blist-node-extended-menu signal received.");
# }
# sub conversation_extended_menu_cb {
# dbg_msg("#Signal# conversation_extended_menu_cb signal received.");
# }
sub cmd_cb {
dbg_msg("yulastfm slash command");
dbg_msg("num of args: ".$#_);
dbg_msg("arg 1: ".$_[1]); # yulastfm
dbg_msg("arg 2: ".$_[2]); # always empty
dbg_msg("arg 3: ".$_[3]); # 1st arg
dbg_msg("arg 4: ".$_[4]); # 2nd arg and it's parameters
my $counts=$#_;
$conv = $_[0];
dbg_msg( "Conversation: " . $conv->get_name());
my $url;
if ( $counts eq 2) {
$url = lastfm_method( "user.getrecenttracks", "&user=" . $lastfm_account . "&limit=" . $ll);
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&refresh_list);
dbg_msg("fetching recent " . $ll . " tracks");
} elsif ( $counts eq 4) {
if ( $_[3] eq "ar" || $_[3] eq "artist") {
$url = lastfm_method( "artist.search", "&artist=" . $_[4] . "&limit=" . $ll);
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&refresh_list_artist);
dbg_msg("Searching ARTIST\(".$_[4]."\) from Last.fm...");
} elsif ( $_[3] eq "tr" || $_[3] eq "track") {
$url = lastfm_method( "track.search", "&track=" . $_[4] . "&limit=" . $ll);
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&refresh_list_track);
dbg_msg("Searching TRACK\(".$_[4]."\) from Last.fm...");
} elsif ( $_[3] eq "al" || $_[3] eq "album") {
$url = lastfm_method( "album.search", "&album=" . $_[4] . "&limit=" . $ll);
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&refresh_list_album);
dbg_msg("Searching ALBUM\(".$_[4]."\) from Last.fm...");
} else {
dbg_msg( "Unkown parameter: ".$_[3]);
return;
}
} else {
dbg_msg("Wrong Slash Command Arguments Number!");
return;
}
# The following code deletes the Gtk2 widget when the conversation gets closed.
# Achieve this by connecting to a deleting-conversation signal
Purple::Signal::connect(
Purple::Conversations::get_handle(),
"deleting-conversation",
$plugin,
sub {
dbg_msg("\"deleting-conversation\" signal received!!");
if ( $conv ne 0 ) {
if ( $conv->get_name() ne $_[0]->get_name()){
dbg_msg( "\$conv =" . $conv->get_name());
dbg_msg( "\$_[0] =" . $_[0]->get_name());
dbg_msg( "Conv not match!");
} else {
dbg_msg( "\$conv =" . $conv->get_name());
$conv = 0;
dbg_msg( "Conv match, reset!");
$mw->destroy();
}
}
},
$plugin
);
}
%plugin_actions = (
"Refresh Tune" => \&refresh_tune);
sub refresh_tune {
$lastfm_account = Purple::Prefs::get_string("/plugins/core/yulastfm/username");
if (!$lastfm_account) { # no account present
dbg_msg("No Last.fm account present!");
Purple::Notify::message(
$plugin,
1, # Warning Type
"YuLastfm",
"A valid Last.fm account is required:",
"This warning message usually implies that you either " .
"haven't done the configuration yet or you have given " .
"an invalid Last.fm account. You have to give a valid " .
"Last.fm account to make YuLastfm work. You can remedy " .
"it in plugins preference setting interface of pidgin. ".
"It locates on menu path\n\n\tTools->Plugins.\n\nFind " .
"YuLastfm, and click Configure Plugin button below to " .
"do further configuration. After configuration, either " .
"reloading the plugin or refreshing it can activate the " .
"lastest configuration. You can refresh it by click " .
"menu path\n\n\tTools->YuLastfm->Refresh Tune.",
NULL, NULL
);
$timeout = 0;
dbg_msg("timeout stoped.");
return 0;
} elsif ( length($lastfm_account) < 2 || length($lastfm_account) > 15) {
dbg_msg("Invalid Last.fm account! (ID Length must between 2-15)");
$timeout = 0;
dbg_msg("timeout stoped.");
return 0;
} else {
my $url = lastfm_method( "user.getrecenttracks", "&user=" . $lastfm_account . "&limit=1");
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&parse_xml);
$refresh_rate = Purple::Prefs::get_int("/plugins/core/yulastfm/refreshing_rate");
if (!$timeout) {
$timeout = Purple::timeout_add( $plugin, $refresh_rate, \&refresh_tune, $plugin);
}
dbg_msg("timeout continues.");
return 1;
}
}
sub button_cb {
dbg_msg( "\$conv = " . $conv);
if ($conv) {
dbg_msg("Sending track info");
my $widget = shift;
my $data = shift;
$conv->get_im_data()->send($data);
} else {
dbg_msg("Conversation has been closed!");
}
}
sub buttons_refresh {
for ( my $i=0; $i<$ll; $i++) {
$btns[$i]->set_image(Gtk2::Image->new_from_file($tl[$i]{"image"}));
}
}
sub gtk2_widget {
dbg_msg("GTK2 Callback");
if ( $mw ) {
$mw->destroy();
}
$mw = Gtk2::Window->new('toplevel');
$mw->set_border_width(0);
$mw->set_position('center_always');
$mw->set_size_request( 250, 350);
my $sw = Gtk2::ScrolledWindow->new();
$sw->set_border_width(0);
$sw->set_policy( GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
my $vbox = Gtk2::VBox->new();
my $vbox0 = Gtk2::VBox->new();
for ( my $i=0; $i<$ll; $i++) {
$btns[$i] = Gtk2::Button->new_with_label( $tl[$i]{"artist"} . "\n" . $tl[$i]{"track"});
$btns[$i]->set_alignment ( 0, 0);
$btns[$i]->set_image(Gtk2::Image->new_from_file($yulastfm_dir."/no_artwork.png"));
$btns[$i]->signal_connect( "clicked" => \&button_cb, "\n".$tl[$i]{"artist"}." - ".$tl[$i]{"track"}."\n".$tl[$i]{"url"});
}
# Appending a label to inform user which person will this message send to.
my $im_label = Gtk2::Label->new( " Send to: " . $conv->get_name());
# accomplishing frame layout
for ( my $i=0; $i<$ll; $i++) {
$vbox->pack_start( $btns[$i], 0, 0, 0);
}
$sw->add_with_viewport($vbox);
$vbox0->pack_start( $sw, 1, 1, 0);
$vbox0->pack_end( $im_label, 0, 0, 0);
$mw->add($vbox0);
$mw->show_all;
}
sub refresh_list {
if (!$_[0]) {
dbg_msg("Cannot get anything from Last.fm!");
return;
}
# Get Pictures and Tracks info
my $rootXmlnode = Purple::XMLNode::from_str($_[0]);
my $lfmStatus = $rootXmlnode->get_attrib("status");
dbg_msg( "lfm status: " . $lfmStatus);
if ( $lfmStatus == "ok") {
dbg_msg("web query status: ok");
# skip inessential node
my $trackXmlnode = $rootXmlnode->get_child("recenttracks")->get_child("track");
my $i = 0;
my $f;
my $url;
# parse xml and fetch information into Track List
while ( $trackXmlnode ne "" ) {
$tl[$i]{"artist"} = $trackXmlnode->get_child("artist")->get_data();
$tl[$i]{"track"} = $trackXmlnode->get_child("name")->get_data();
$tl[$i]{"url"} = $trackXmlnode->get_child("url")->get_data();
$url = $trackXmlnode->get_child("image")->get_next_twin()->get_data();
if ( $url eq "") {
$tl[$i]{"image"} = $yulastfm_dir . "/no_artwork.png";
} else {
$tl[$i]{"image"} = $yulastfm_artworks_dir . "/" . basename($url);
$f = fetch_image_closure( $tl[$i]{"image"});
# $f = sub { open( FH, ">$tl[$i]{\"image\"}"); print FH $_[0]; close(FH);}; # why not work?
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&$f);
}
dbg_msg( "artist: " . $tl[$i]{"artist"});
dbg_msg( "track: " . $tl[$i]{"track"});
dbg_msg( "url: " . $tl[$i]{"url"});
dbg_msg( "image: " . $tl[$i]{"image"});
$trackXmlnode = $trackXmlnode->get_next_twin();
$i++;
}
# Generate Gtk2 UI
gtk2_widget();
# User Select and Send
} elsif ( $lfmStatus == "failed") {
dbg_msg("web query status: failed");
} else {
dbg_msg( "unkown web query status:" . $lfmStatus);
}
}
sub refresh_list_artist {
dbg_msg("refresh_list_artist()");
if (!$_[0]) {
dbg_msg("Cannot get anything from Last.fm!");
return;
}
# Get Pictures and Tracks info
my $rootXmlnode = Purple::XMLNode::from_str($_[0]);
my $lfmStatus = $rootXmlnode->get_attrib("status");
dbg_msg( "lfm status: " . $lfmStatus);
if ( $lfmStatus == "ok") {
dbg_msg("web query status: ok");
# skip inessential node
my $trackXmlnode = $rootXmlnode->get_child("results")->get_child("artistmatches")->get_child("artist");
my $i = 0;
my $f;
my $url;
# parse xml and fetch information into Track List
while ( $trackXmlnode ne "" ) {
$tl[$i]{"artist"} = $trackXmlnode->get_child("name")->get_data();
$tl[$i]{"track"} = "";
$tl[$i]{"url"} = $trackXmlnode->get_child("url")->get_data();
$url = $trackXmlnode->get_child("image")->get_next_twin()->get_data();
if ( $url eq "") {
$tl[$i]{"image"} = $yulastfm_dir . "/no_artwork.png";
} else {
$tl[$i]{"image"} = $yulastfm_artworks_dir . "/" . basename($url);
$f = fetch_image_closure( $tl[$i]{"image"});
# $f = sub { open( FH, ">$tl[$i]{\"image\"}"); print FH $_[0]; close(FH);}; # why not work?
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&$f);
}
dbg_msg( "artist: " . $tl[$i]{"artist"});
dbg_msg( "track: " . $tl[$i]{"track"});
dbg_msg( "url: " . $tl[$i]{"url"});
dbg_msg( "image: " . $tl[$i]{"image"});
$trackXmlnode = $trackXmlnode->get_next_twin();
$i++;
}
# Generate Gtk2 UI
gtk2_widget();
# User Select and Send
} elsif ( $lfmStatus == "failed") {
dbg_msg("web query status: failed");
} else {
dbg_msg( "unkown web query status:" . $lfmStatus);
}
}
# FIXME there are some bugs in this func
sub refresh_list_track {
dbg_msg("refresh_list_track()");
if (!$_[0]) {
dbg_msg("Cannot get anything from Last.fm!");
return;
}
# Get Pictures and Tracks info
my $rootXmlnode = Purple::XMLNode::from_str($_[0]);
my $lfmStatus = $rootXmlnode->get_attrib("status");
dbg_msg( "lfm status: " . $lfmStatus);
if ( $lfmStatus == "ok") {
dbg_msg("web query status: ok");
# skip inessential node
my $trackXmlnode = $rootXmlnode->get_child("results")->get_child("trackmatches")->get_child("track");
my $i = 0;
my $f;
my $url;
# parse xml and fetch information into Track List
while ( $trackXmlnode ne "" ) {
$tl[$i]{"track"} = $trackXmlnode->get_child("name")->get_data();
$tl[$i]{"artist"} = $trackXmlnode->get_child("artist")->get_data();
$tl[$i]{"url"} = $trackXmlnode->get_child("url")->get_data();
$url = $trackXmlnode->get_child("image")->get_next_twin()->get_data();
if ( $url eq "") {
$tl[$i]{"image"} = $yulastfm_dir . "/no_artwork.png";
} else {
$tl[$i]{"image"} = $yulastfm_artworks_dir . "/" . basename($url);
$f = fetch_image_closure( $tl[$i]{"image"});
# $f = sub { open( FH, ">$tl[$i]{\"image\"}"); print FH $_[0]; close(FH);}; # why not work?
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&$f);
}
dbg_msg( "artist: " . $tl[$i]{"artist"});
dbg_msg( "track: " . $tl[$i]{"track"});
dbg_msg( "url: " . $tl[$i]{"url"});
dbg_msg( "image: " . $tl[$i]{"image"});
$trackXmlnode = $trackXmlnode->get_next_twin();
$i++;
}
# Generate Gtk2 UI
gtk2_widget();
# User Select and Send
} elsif ( $lfmStatus == "failed") {
dbg_msg("web query status: failed");
} else {
dbg_msg( "unkown web query status:" . $lfmStatus);
}
}
sub refresh_list_album {
dbg_msg("refresh_list_album()");
if (!$_[0]) {
dbg_msg("Cannot get anything from Last.fm!");
return;
}
# Get Pictures and Tracks info
my $rootXmlnode = Purple::XMLNode::from_str($_[0]);
my $lfmStatus = $rootXmlnode->get_attrib("status");
dbg_msg( "lfm status: " . $lfmStatus);
if ( $lfmStatus == "ok") {
dbg_msg("web query status: ok");
# skip inessential node
my $trackXmlnode = $rootXmlnode->get_child("results")->get_child("albummatches")->get_child("album");
my $i = 0;
my $f;
my $url;
# parse xml and fetch information into Track List
while ( $trackXmlnode ne "" ) {
$tl[$i]{"artist"} = $trackXmlnode->get_child("artist")->get_data();
$tl[$i]{"track"} = $trackXmlnode->get_child("name")->get_data();
$tl[$i]{"url"} = $trackXmlnode->get_child("url")->get_data();
$url = $trackXmlnode->get_child("image")->get_next_twin()->get_data();
if ( $url eq "") {
$tl[$i]{"image"} = $yulastfm_dir . "/no_artwork.png";
} else {
$tl[$i]{"image"} = $yulastfm_artworks_dir . "/" . basename($url);
$f = fetch_image_closure( $tl[$i]{"image"});
# $f = sub { open( FH, ">$tl[$i]{\"image\"}"); print FH $_[0]; close(FH);}; # why not work?
Purple::Util::fetch_url( $plugin, $url, TRUE, "Mozilla/5.0", TRUE, \&$f);
}
dbg_msg( "artist: " . $tl[$i]{"artist"});
dbg_msg( "track: " . $tl[$i]{"track"});
dbg_msg( "url: " . $tl[$i]{"url"});
dbg_msg( "image: " . $tl[$i]{"image"});
$trackXmlnode = $trackXmlnode->get_next_twin();
$i++;
}
# Generate Gtk2 UI
gtk2_widget();
# User Select and Send
} elsif ( $lfmStatus == "failed") {
dbg_msg("web query status: failed");
} else {
dbg_msg( "unkown web query status:" . $lfmStatus);
}
}
sub fetch_image_closure {
my $x = shift;
return sub {
my $y = shift;
open( FH, ">$x");
print FH $y;
close(FH);
buttons_refresh();
};
}
sub parse_xml {
# dbg_msg($_[0]); # dump raw xml
dbg_msg("parsing xml");
if (!$_[0]) {
dbg_msg("Cannot get anything from Last.fm!");
return;
}
my $rootXmlnode = Purple::XMLNode::from_str($_[0]);
my $lfmStatus = $rootXmlnode->get_attrib("status");
dbg_msg( "lfm status: " . $lfmStatus);
if ( $lfmStatus == "ok") {
dbg_msg("web query status: ok");
my $trackXmlnode = $rootXmlnode->get_child("recenttracks")->get_child("track");
if ( $trackXmlnode->get_attrib("nowplaying") ) {
# now playing
$cur_artist = $trackXmlnode->get_child("artist")->get_data();
$cur_title = $trackXmlnode->get_child("name")->get_data();
$cur_album = $trackXmlnode->get_child("album")->get_data();
$cur_date = $trackXmlnode->get_child("date")->get_attrib("uts");
dbg_msg("artist: " . $cur_artist);
dbg_msg("name: " . $cur_title);
dbg_msg("album: " . $cur_album);
dbg_msg("date: " . $cur_date);
Purple::Util::set_current_song( $cur_title, $cur_artist, $cur_album);
} else {
# no music is playing
# TODO something need to take care in this situation
dbg_msg("no music is playing");
Purple::Util::set_current_song( "", "", "");
}
} elsif ( $lfmStatus == "failed") {
dbg_msg("web query status: failed");
} else {
dbg_msg( "unkown web query status:" . $lfmStatus);
}
}
sub plugin_unload {
my @accounts = Purple::Accounts::get_all();
my $i = 0;
while ( $i<=$#accounts) {
if ( $account = $accounts[$i]) {
if( $presence = Purple::Account::get_presence($account)) {
Purple::Util::set_current_song( "", "", "");
}
}
$i++;
}
if ($timeout) {
dbg_msg( "remove existing timeout: " . $timeout);
Purple::timeout_remove($timeout);
$timeout = 0;
}
if ($cmd_id) {
Purple::Cmd::unregister($cmd_id);
$cmd_id = 0;
}
rmtree( [$yulastfm_artworks_dir], 0, 1);
dbg_msg("yulastfm unloaded");
}
sub dbg_msg {
Purple::Debug::info( "yulastfm: ", $_[0] . "\n");
}
sub lastfm_method {
# param_1: method
# param_2: other param
my $tmp = "http://ws.audioscrobbler.com/2.0/?method=" . $_[0] . $_[1] . "&api_key=7aed2418de442e85a6e7af89f325d8f6";
$tmp =~ s/ /%20/g;
dbg_msg($tmp);
return $tmp;
}