1 /*
2 * Copyright (C) 2009-2012 Christian Heckendorf <heckendorfc@gmail.com>
3 *
4 * This program is free software: you can redistribute it AND/or modify
5 * it under the terms of the GNU General Public License AS published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "list.h"
19 #include "defs.h"
20 #include "tree.h"
21 #include "dbact.h"
22
list(int * ids,int length)23 int list(int *ids, int length){
24 char query[401];
25 int x,exception[10];
26 for(x=1;x<10;x++)exception[x]=listconf.exception;
27 exception[0]=1;
28 switch(arglist[ATYPE].subarg[0]){
29 case 's':
30 exception[1]=exception[2]=exception[3]=exception[4]=1;
31 for(x=0;x<length;x++){
32 sprintf(query,"SELECT SongID,SongTitle,Location,AlbumTitle,ArtistName FROM SongPubInfo WHERE SongID=%d ORDER BY ArtistName,AlbumTitle,SongTrack",ids[x]);
33 doTitleQuery(query,exception,listconf.maxwidth);
34 printf("\n");
35 }
36 break;
37
38 case 'p':
39 exception[0]=exception[1]=1;
40 for(x=0;x<length;x++){
41 sprintf(query,"SELECT PlaylistID,Title FROM Playlist WHERE PlaylistID=%d",ids[x]);
42 doTitleQuery(query,exception,listconf.maxwidth);
43 printf("\nContents:\n");
44
45 sprintf(query,"SELECT \"Order\" AS \"#\", SongID,SongTitle,AlbumTitle,ArtistName FROM PlaylistSong NATURAL JOIN SongPubInfo WHERE PlaylistID=%d ORDER BY \"Order\"",ids[x]);
46 printf("------\nTotal:%d\n",doTitleQuery(query,exception,listconf.maxwidth));
47 }
48 break;
49
50 case 'r':
51 exception[0]=exception[1]=1;
52 for(x=0;x<length;x++){
53 sprintf(query,"SELECT Artist.ArtistID, Artist.Name FROM Artist WHERE ArtistID=%d",ids[x]);
54 doTitleQuery(query,exception,listconf.maxwidth);
55 printf("\nContents:\n");
56
57 sprintf(query,"SELECT Song.SongID, Song.Track, Song.Title, Album.Title AS Album, Artist.Name AS Artist FROM Artist NATURAL JOIN AlbumArtist NATURAL JOIN Album INNER JOIN Song USING(AlbumID) WHERE Artist.ArtistID=%d ORDER BY Artist.Name, Album.Date, Album.Title, Song.Track",ids[x]);
58 printf("------\nTotal:%d\n",doTitleQuery(query,exception,listconf.maxwidth));
59 }
60 break;
61
62 case 'a':
63 exception[0]=exception[1]=1;
64 for(x=0;x<length;x++){
65 sprintf(query,"SELECT Album.AlbumID,Album.Title,Album.Date FROM Album WHERE AlbumID=%d",ids[x]);
66 doTitleQuery(query,exception,listconf.maxwidth);
67 printf("\nContents:\n");
68
69 sprintf(query,"SELECT Song.SongID, Song.Track, Song.Title, Album.Title AS Album, Artist.Name AS Artist FROM Artist NATURAL JOIN AlbumArtist NATURAL JOIN Album INNER JOIN Song USING(AlbumID) WHERE Album.AlbumID=%d ORDER BY Artist.Name, Album.Date, Album.Title, Song.Track",ids[x]);
70 printf("------\nTotal:%d\n",doTitleQuery(query,exception,listconf.maxwidth));
71 }
72 break;
73
74 case 'g':
75 for(x=0;x<length;x++){
76 printGenreTree(ids[x],(void *)tierChildPrint);
77 }
78 break;
79 case 't':
80 for(x=0;x<length;x++){
81 sprintf(query,"SELECT SongPubInfo.SongID as SongID,SongTitle,Location,AlbumTitle,ArtistName FROM SongPubInfo,SongTag WHERE SongTag.SongID=SongPubInfo.SongID AND TagID=%d ORDER BY ArtistName,AlbumTitle,SongTrack",ids[x]);
82 doTitleQuery(query,exception,listconf.maxwidth);
83 printf("\n");
84 }
85 break;
86
87 }
88 return 0;
89 }
90
listall()91 int listall(){
92 char query[401];
93 int x,exception[10];
94 for(x=1;x<10;x++)exception[x]=listconf.exception;
95 exception[0]=1;
96 switch(arglist[ATYPE].subarg[0]){
97 case 's':
98 sprintf(query,"SELECT Song.SongID, Song.Title, Song.Location, Album.Title AS Album, Artist.Name AS Artist FROM Song,Album,Artist,AlbumArtist WHERE Song.AlbumID=Album.AlbumID AND Album.AlbumID=AlbumArtist.AlbumID AND AlbumArtist.ArtistID=Artist.ArtistID ORDER BY Artist.Name, Album.Date, Album.Title, Song.Track");
99 exception[1]=exception[2]=exception[3]=exception[4]=1;
100 break;
101
102 case 'p':
103 sprintf(query,"SELECT PlaylistID,Title FROM Playlist");
104 break;
105
106 case 'r':
107 sprintf(query,"SELECT Artist.ArtistID, Artist.Name FROM Artist");
108 break;
109
110 case 'a':
111 sprintf(query,"SELECT Album.AlbumID,Album.Title FROM Album");
112 break;
113
114 case 'g':
115 printGenreTree(0,(void *)tierCatPrint);
116 return 0;
117
118 case 't':
119 sprintf(query,"SELECT TagID,Name FROM Tag");
120 break;
121
122 default:return 1;
123 }
124 doTitleQuery(query,exception,listconf.maxwidth);
125 return 0;
126 }
127