1 |
joko |
1.1 |
#!/usr/bin/perl -w |
2 |
|
|
# |
3 |
|
|
################################################## |
4 |
|
|
# |
5 |
|
|
# GiantDisc mp3 Jukebox, Extended Tool Functions: |
6 |
|
|
# Activate Playlist by ID |
7 |
|
|
# |
8 |
|
|
# 2005 Andreas Motl |
9 |
|
|
# Functions stolen from gdlircclient.pl |
10 |
|
|
# |
11 |
|
|
################################################## |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
package gdgentools_extended; |
15 |
|
|
|
16 |
|
|
use strict; |
17 |
|
|
use warnings; |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
my $pl_list = 0; # playlist type |
21 |
|
|
|
22 |
|
|
#my $digitL = 0; # low digit of playlist number |
23 |
|
|
#my $digitH = 0; # high digit of playlist number |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
sub empty_tracklist { |
27 |
|
|
my ($dbh, $playerid, $audiochannel) = @_; #parameters: database handle, player id, sound out it |
28 |
|
|
# stop playing |
29 |
|
|
gdgentools::stop_play_processes($dbh, $playerid, $audiochannel); |
30 |
|
|
# reset list+state |
31 |
|
|
gdgentools::tracklist_delete($dbh, $playerid, 0); |
32 |
|
|
gdgentools::pll_write_playstate($dbh, $playerid, $audiochannel, 0, "st"); |
33 |
|
|
gdgentools::pll_write_playtime($dbh, $playerid, $audiochannel, 0, 0); |
34 |
|
|
#gdgentools::pll_write_shuffleparameters($dbh, $playerid, $audiochannel, "", ""); |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
sub playlist_to_tracklist { |
38 |
|
|
my ($dbh, $playerid, $audiochannel, $playlist_id) = @_; #parameters: database handle, player id, sound out it |
39 |
|
|
my $row; |
40 |
|
|
my @tracklist; |
41 |
|
|
|
42 |
|
|
# load all track ids for this playlist |
43 |
|
|
my $stmt = $dbh->prepare( |
44 |
|
|
"SELECT trackid FROM playlistitem " |
45 |
|
|
."WHERE playlist=$playlist_id ORDER BY tracknumber" ); |
46 |
|
|
|
47 |
|
|
$stmt->execute; |
48 |
|
|
|
49 |
|
|
while( $row = $stmt->fetchrow_hashref) { |
50 |
|
|
push( @tracklist, $row->{trackid}); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
$stmt->finish; |
54 |
|
|
|
55 |
|
|
if( @tracklist) { |
56 |
|
|
#debug( "New Tracklist\n@tracklist\n\n"); |
57 |
|
|
|
58 |
|
|
# Stop playing and drop tracklist |
59 |
|
|
empty_tracklist($dbh, $playerid, $audiochannel); |
60 |
|
|
# Set new tracklist |
61 |
|
|
gdgentools::tracklist_append_list($dbh, $playerid, $pl_list, @tracklist); |
62 |
|
|
} |
63 |
|
|
else { |
64 |
|
|
print( "Seems like the playlist is empty!\n"); |
65 |
|
|
} |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
|
69 |
|
|
sub cmd_call_playlist { |
70 |
|
|
# I replace the current tracklist with a playlist. |
71 |
|
|
# The name of the playlist is "x Some Text". Where x is a number |
72 |
|
|
# between 0 and 99. It comes from $digitH$digitL. |
73 |
|
|
# The number must be followed by a blank!!! |
74 |
|
|
# E.g. "5 Greatest Hits 1889-2003" |
75 |
|
|
# It's the same as with cmd_random_tracklist. I may confuse the palm... |
76 |
|
|
|
77 |
|
|
my ($dbh, $playerid, $audiochannel, $plnum) = @_; #parameters: database handle, player id, sound out it |
78 |
|
|
|
79 |
|
|
my $id; |
80 |
|
|
my $title; |
81 |
|
|
my $row; |
82 |
|
|
|
83 |
|
|
#my $plnum = 10*$digitH + $digitL; |
84 |
|
|
#$digitL = 0; |
85 |
|
|
#$digitH = 0; |
86 |
|
|
|
87 |
|
|
if (!$plnum) { |
88 |
|
|
print "Error: Playlist ID not specified!", "\n"; |
89 |
|
|
return; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
if( $plnum == 99) { # 99 is a special case. It loads random tracks. |
93 |
|
|
print( "call cmd_call_random\n"); |
94 |
|
|
#cmd_call_random; |
95 |
|
|
print( "Error: out-of-order!\n"); |
96 |
|
|
} |
97 |
|
|
else { |
98 |
|
|
# TODO: also query by title |
99 |
|
|
my $stmt = $dbh->prepare( "SELECT id,title FROM playlist WHERE id=$plnum" ); |
100 |
|
|
|
101 |
|
|
$stmt->execute; |
102 |
|
|
|
103 |
|
|
if( $row = $stmt->fetchrow_hashref){ |
104 |
|
|
# Playlist found |
105 |
|
|
$id = $row->{id}; |
106 |
|
|
$title = $row->{title}; |
107 |
|
|
print( "Playlist $title Id $id\n"); |
108 |
|
|
# replace current tracklist with playlist. |
109 |
|
|
playlist_to_tracklist($dbh, $playerid, $audiochannel, $id); |
110 |
|
|
|
111 |
|
|
# automatically randomize the playlist |
112 |
|
|
#if( $lircparms{"auto_random"} == 1) |
113 |
|
|
#{ |
114 |
|
|
# cmd_random_tracklist(); |
115 |
|
|
#} |
116 |
|
|
} |
117 |
|
|
else { |
118 |
|
|
print( "Playlist not found!\n"); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
$stmt->finish; |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
1; |