Skip to content

Commit

Permalink
Update 1.8.3
Browse files Browse the repository at this point in the history
Added trash support, track downloading to file, bug fixes, better logging and artist view
  • Loading branch information
Codrax committed Nov 11, 2023
1 parent 078f092 commit 1ea40e3
Show file tree
Hide file tree
Showing 14 changed files with 3,970 additions and 1,483 deletions.
216 changes: 216 additions & 0 deletions BroadcastAPI.pas
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ TSession = record
function TouchupPlaylist(ID: integer): boolean;
function UpdatePlayList(ID: integer; Name, Description: string; ReloadLibrary: boolean): boolean;
function DeletePlayList(ID: integer): boolean;
function DeleteTracks(Tracks: TArray<integer>): boolean;
function DeleteTrack(ID: integer): boolean;
function DeleteAlbum(ID: integer): boolean;
function DeleteArtist(ID: integer): boolean;
function RestoreTracks(Tracks: TArray<integer>): boolean;
function RestoreTrack(ID: integer): boolean;
function RestoreAlbum(ID: integer): boolean;
function RestoreArtist(ID: integer): boolean;
function EmptyTrash(Tracks: TArray<integer>): boolean;
function CompleteEmptyTrash: boolean;

// History
function PushHistory(Items: TArray<THistoryItem>): boolean;
Expand Down Expand Up @@ -394,6 +404,22 @@ TSession = record
+ '"description": "%S"'
+ '}';

// Track
REQUEST_TRACK_DELETE = REQUEST_HEADER + ','
+ '"mode": "trash",'
+ '"tracks": [%S]'
+ '}';

REQUEST_TRACK_RESTORE = REQUEST_HEADER + ','
+ '"mode": "restore",'
+ '"tracks": [%S]'
+ '}';

REQUEST_TRACK_EMPTYTRASH = REQUEST_HEADER + ','
+ '"mode": "empty_trash",'
+ '"tracks": [%S]'
+ '}';

// Rating
REQUEST_RATE_TRACK = REQUEST_HEADER + ','
+ '"mode": "ratetrack",'
Expand Down Expand Up @@ -1150,6 +1176,188 @@ function DeletePlayList(ID: integer): boolean;
LoadLibraryAdvanced([TLoad.PlayList]);
end;

function DeleteTracks(Tracks: TArray<integer>): boolean;
var
Request: string;
JResult: ResultType;

ATracks: string;
ATotal: integer;
I: integer;

JSONValue: TJSONValue;
begin
// Get Tracks
ATracks := '';
ATotal := High(Tracks);
for I := 0 to ATotal do
ATracks := ATracks + Tracks[I].ToString + ',';

ATracks := Copy(ATracks, 1, Length(ATracks)-1);

// Prepare request string
Request := Format(REQUEST_TRACK_DELETE, [USER_ID, TOKEN, ATracks]); // supports multi-delete

// Parse response and extract numbers
SetWorkStatus('Deleting track');
JSONValue := SendClientRequest(Request);
try
// Error
JResult.AnaliseFrom(JSONVALUE);

Result := JResult.Success;
finally
JSONValue.Free;
end;

// Re-load playlists
LoadLibraryAdvanced([TLoad.Track, TLoad.Album, TLoad.Artist, TLoad.PlayList]);
end;

function RestoreTracks(Tracks: TArray<integer>): boolean;
var
Request: string;
JResult: ResultType;

ATracks: string;
ATotal: integer;
I: integer;

JSONValue: TJSONValue;
begin
// Get Tracks
ATracks := '';
ATotal := High(Tracks);
for I := 0 to ATotal do
ATracks := ATracks + Tracks[I].ToString + ',';

ATracks := Copy(ATracks, 1, Length(ATracks)-1);

// Prepare request string
Request := Format(REQUEST_TRACK_RESTORE, [USER_ID, TOKEN, ATracks]); // supports multi-delete

// Parse response and extract numbers
SetWorkStatus('Restoring track');
JSONValue := SendClientRequest(Request);
try
// Error
JResult.AnaliseFrom(JSONVALUE);

Result := JResult.Success;
finally
JSONValue.Free;
end;

// Re-load playlists
LoadLibraryAdvanced([TLoad.Track, TLoad.Album, TLoad.Artist, TLoad.PlayList]);
end;

function EmptyTrash(Tracks: TArray<integer>): boolean;
var
Request: string;
JResult: ResultType;

ATracks: string;
ATotal: integer;
I: integer;

JSONValue: TJSONValue;
begin
// Get Tracks
ATracks := '';
ATotal := High(Tracks);
for I := 0 to ATotal do
ATracks := ATracks + Tracks[I].ToString + ',';

ATracks := Copy(ATracks, 1, Length(ATracks)-1);

// Prepare request string
Request := Format(REQUEST_TRACK_EMPTYTRASH, [USER_ID, TOKEN, ATracks]); // supports multi-delete

// Parse response and extract numbers
SetWorkStatus('Deleting from trash');
JSONValue := SendClientRequest(Request);
try
// Error
JResult.AnaliseFrom(JSONVALUE);

Result := JResult.Success;
finally
JSONValue.Free;
end;

// Re-load playlists
LoadLibraryAdvanced([TLoad.Track, TLoad.Album, TLoad.Artist, TLoad.PlayList]);
end;

function CompleteEmptyTrash: boolean;
var
ATracks: TArray<integer>;
I: integer;
begin
ATracks := [];
for I := 0 to High(Tracks) do
if Tracks[I].IsInTrash then
ATracks.AddValue(Tracks[I].ID);

// Empty
Result := EmptyTrash(ATracks);
end;

function RestoreTrack(ID: integer): boolean;
begin
Result := RestoreTracks([ID]);
end;

function RestoreAlbum(ID: integer): boolean;
var
Index: integer;
begin
Result := false;
Index := GetAlbum(ID);

if Index <> -1 then
Result := RestoreTracks(Albums[Index].TracksID);
end;

function RestoreArtist(ID: integer): boolean;
var
Index: integer;
begin
Result := false;
Index := GetArtist(ID);

if Index <> -1 then
Result := RestoreTracks(Artists[Index].TracksID);
end;

function DeleteTrack(ID: integer): boolean;
begin
Result := DeleteTracks([ID]);
end;

function DeleteAlbum(ID: integer): boolean;
var
Index: integer;
begin
Result := false;
Index := GetAlbum(ID);

if Index <> -1 then
Result := DeleteTracks(Albums[Index].TracksID);
end;

function DeleteArtist(ID: integer): boolean;
var
Index: integer;
begin
Result := false;
Index := GetArtist(ID);

if Index <> -1 then
Result := DeleteTracks(Artists[Index].TracksID);
end;

function PushHistory(Items: TArray<THistoryItem>): boolean;
var
Request: string;
Expand Down Expand Up @@ -1407,6 +1615,10 @@ procedure LoadLibraryAdvanced(LoadSet: TLoadSet);
SetLength( Albums, Index + 1 );

Albums[Index].LoadFrom( JSONPair );

// Invalid entry, delete from index
if Albums[Index].TracksID.Count = 0 then
SetLength( Albums, Index );
end;

// Updated
Expand Down Expand Up @@ -1438,6 +1650,10 @@ procedure LoadLibraryAdvanced(LoadSet: TLoadSet);
SetLength( Artists, Index + 1 );

Artists[Index].LoadFrom( JSONPair );

// Invalid entry, delete from index
if Artists[Index].TracksID.Count = 0 then
SetLength( Artists, Index );
end;

// Updated
Expand Down
10 changes: 5 additions & 5 deletions CreatePlaylistForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object CreatePlaylist: TCreatePlaylist
Align = alBottom
BevelOuter = bvNone
ParentColor = True
TabOrder = 1
TabOrder = 2
object Download_Item: CButton
AlignWithMargins = True
Left = 431
Expand Down Expand Up @@ -182,7 +182,7 @@ object CreatePlaylist: TCreatePlaylist
Caption = 'Panel2'
ParentColor = True
ShowCaption = False
TabOrder = 2
TabOrder = 4
object Label8: TLabel
AlignWithMargins = True
Left = 60
Expand Down Expand Up @@ -395,7 +395,7 @@ object CreatePlaylist: TCreatePlaylist
Align = alTop
BevelOuter = bvNone
ParentColor = True
TabOrder = 4
TabOrder = 1
object Label2: TLabel
AlignWithMargins = True
Left = 5
Expand Down Expand Up @@ -3225,13 +3225,13 @@ object CreatePlaylist: TCreatePlaylist
Colors.Leave = 16250866
Colors.Enter = 15658729
Colors.Down = 15066593
Colors.Checked = 4745881
Colors.Checked = 1265132
Colors.CheckIndicator = clWhite
Colors.TransparentCenter = True
ColorsBorder.Leave = 9013638
ColorsBorder.Enter = 9013638
ColorsBorder.Down = 12434873
ColorsBorder.Checked = 4745881
ColorsBorder.Checked = 1265132
Checked = False
State = cbUnchecked
end
Expand Down
11 changes: 9 additions & 2 deletions DebugForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ object DebugUI: TDebugUI
Height = 21
Caption = 'Downl Thread:'
end
object Label14: TLabel
Left = 185
Top = 396
Width = 74
Height = 21
Caption = 'Page Path: '
end
object CButton1: CButton
Left = 19
Top = 120
Expand Down Expand Up @@ -1106,7 +1113,7 @@ object DebugUI: TDebugUI
Left = 454
Top = 198
Width = 222
Height = 195
Height = 177
Lines.Strings = (
'JSON response will be '
'shown here')
Expand Down Expand Up @@ -1239,7 +1246,7 @@ object DebugUI: TDebugUI
Left = 323
Top = 34
Width = 118
Height = 359
Height = 341
Lines.Strings = (
'Queue')
ParentColor = True
Expand Down
2 changes: 2 additions & 0 deletions DebugForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TDebugUI = class(TForm)
CButton7: CButton;
CButton8: CButton;
Label13: TLabel;
Label14: TLabel;
procedure CButton1Click(Sender: TObject);
procedure CButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
Expand Down Expand Up @@ -113,6 +114,7 @@ procedure TDebugUI.DataSyncTimer(Sender: TObject);
Label10.Caption := 'Ch Active: ' + BooleanToString( BASS_ChannelIsActive(Player.Stream) = BASS_ACTIVE_PLAYING );
Label11.Caption := 'Img-Thread: ' + TotalThreads.ToString;
Label12.Caption := 'Downl-Thread: ' + DownloadThreadsE.ToString;
Label14.Caption := 'Page Path: ' + Location;
end;

procedure TDebugUI.FormCreate(Sender: TObject);
Expand Down
Loading

0 comments on commit 1ea40e3

Please sign in to comment.