28 Commits

Author SHA1 Message Date
e7af7f471f (front) Update to Angular 17
npm update

man update
2024-01-29 23:43:51 +01:00
eb13944e46 (front) Update to Angular 16
npm audit fix
2024-01-29 23:43:48 +01:00
20f4fdbd39 (typesense) Suggester 2024-01-23 23:54:46 +01:00
b789c925c4 (typesense) Main dashboard
Lot of duplicate to have a simple improvment
2024-01-23 23:54:36 +01:00
1ff074aac3 (front) Use a compatible ng-bootstrap version 2023-09-20 01:17:35 +02:00
f6eb99fa67 (front) Update to Angular 15 2023-02-06 23:58:43 +01:00
46c4a0b40c (front) Update to Angular 14 2023-02-06 23:51:56 +01:00
05cbe19b4d (front) Update package-lock
Why?...
2023-02-06 23:36:50 +01:00
003ad4917e (front) NVM update node version 2023-02-06 23:27:24 +01:00
25828bb789 (front) Service refactoring for sorting operations
- Create an ElsArtistService to use common query
- Move services in a subfolder

Use a function to add sort filter
2023-02-06 23:08:56 +01:00
29350c36cd (front) Another way to get toSort boolean at Service 2023-01-30 01:30:38 +01:00
9f4ef952b3 (front) Use a 'tosort' filter 2023-01-30 01:23:35 +01:00
2ddafaff1b (front) Improve ToSort using album index 2023-01-29 22:34:23 +01:00
7e0a791fbe (back) Add location for albums 2023-01-29 19:38:24 +01:00
cf8cd046f4 (front) To sort: reorganize stats panels 2023-01-09 00:06:56 +01:00
a10c9ae060 (front) Update to Angular 13 2023-01-09 00:06:56 +01:00
754ee9213c (front) Adapt query for ELS 8.5 2023-01-09 00:06:56 +01:00
40aed6039d (front) Run after a long time
Use a nvmrc file to keep in memory node version used
2023-01-09 00:06:56 +01:00
4399018b4a (back) Readme udpate 2023-01-09 00:06:56 +01:00
bb51af68cd (front)(update) Add ng-bootstrap
Reverse 098d095 and take last version
2021-08-23 01:07:24 +02:00
5ee9781463 (front)(update) Upgrading npm from 6.14.14 to 7.21.0
Reverse dc47dfe
2021-08-23 01:07:18 +02:00
00a5427950 (front)(update) Update Angular 2021-08-23 01:07:13 +02:00
fada5f475b (front)(update) Lowering npm to 7.21.0 to 6.14.14
https://github.com/angular/angular-cli/issues/20208
2021-08-23 01:07:07 +02:00
d307012aca (front)(update) Remove ng-bootstrap for update
Avoid dependancy error
2021-08-23 01:06:43 +02:00
755f5e5c24 (front) tsconfig use strict template 2021-08-22 22:31:53 +02:00
f40ee2b6d2 Suggester - Autocomplete Serch
Merge branch 'poc/suggester/ng-bootstrap' into dev
2021-08-22 17:39:30 +02:00
d011d5738f (front) Fix top buttons 2021-08-22 17:39:17 +02:00
e5de38b9d9 (front) Create 'To Sort' component
With a specific ELS Services to query element in a specific folder

TODO: Parameterize folder
2021-08-22 17:39:13 +02:00
44 changed files with 9857 additions and 24594 deletions

21
README.md Normal file
View File

@@ -0,0 +1,21 @@
# Classic data
1. Analyze data :
```sh
python3 iTunesParser.py
```
2. Send data to ELS :
```sh
python3 send_data.py -D -A
```
# Suggester
To use suggester, create index with data in `suggester.es` file.
Then :
```sh
python3 suggester.py
```

View File

@@ -25,6 +25,7 @@
!.vscode/extensions.json
# misc
/.angular/cache
/.sass-cache
/connect.lock
/coverage

1
dashboard/.nvmrc Normal file
View File

@@ -0,0 +1 @@
v18.12.1

View File

@@ -18,7 +18,6 @@
"main": "src/main.ts",
"tsConfig": "tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"aot": true,
"assets": [
"src/assets",
"src/favicon.ico"
@@ -27,7 +26,13 @@
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": []
"scripts": [],
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
"production": {
@@ -57,23 +62,24 @@
}
]
}
}
},
"defaultConfiguration": ""
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "dashboard:build"
"buildTarget": "dashboard:build"
},
"configurations": {
"production": {
"browserTarget": "dashboard:build:production"
"buildTarget": "dashboard:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "dashboard:build"
"buildTarget": "dashboard:build"
}
},
"test": {
@@ -94,19 +100,6 @@
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
@@ -121,6 +114,5 @@
}
}
}
},
"defaultProject": "dashboard"
}
}

31726
dashboard/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,38 +11,38 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~11.0.4",
"@angular/common": "~11.0.4",
"@angular/compiler": "~11.0.4",
"@angular/core": "~11.0.4",
"@angular/forms": "~11.0.4",
"@angular/platform-browser": "~11.0.4",
"@angular/platform-browser-dynamic": "~11.0.4",
"@angular/router": "~11.0.4",
"@ng-bootstrap/ng-bootstrap": "^9.1.3",
"bootstrap": "^3.3.7",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
"@angular/animations": "^17.1.0",
"@angular/common": "^17.1.0",
"@angular/compiler": "^17.1.0",
"@angular/core": "^17.1.0",
"@angular/forms": "^17.1.0",
"@angular/localize": "^17.1.0",
"@angular/platform-browser": "^17.1.0",
"@angular/platform-browser-dynamic": "^17.1.0",
"@angular/router": "^17.1.0",
"@ng-bootstrap/ng-bootstrap": "^16.0.0",
"bootstrap": "^3.4.1",
"rxjs": "~7.8.1",
"tslib": "^2.6.2",
"zone.js": "^0.14.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1100.4",
"@angular/cli": "~11.0.4",
"@angular/compiler-cli": "~11.0.4",
"@angular/localize": "^11.0.4",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"@angular-devkit/build-angular": "^17.1.0",
"@angular/cli": "^17.1.0",
"@angular/compiler-cli": "^17.1.0",
"@types/jasmine": "~5.1.4",
"@types/node": "^20.11.5",
"codelyzer": "^6.0.2",
"jasmine-core": "~5.1.1",
"jasmine-spec-reporter": "~7.0.0",
"karma": "~6.4.2",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.1",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"ts-node": "~10.9.2",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
"typescript": "~5.3.3"
}
}

View File

@@ -1,6 +1,11 @@
<div class="container">
<h1>{{albumName}}</h1>
<div *ngIf="sortFilter" class="alert alert-danger">
To sort filter applyed. Songs are filter on location. <br/>
Album folder: {{album['Location']}}
</div>
<div class="alert alert-warning">
<h3>Debug Zone</h3>
Returned song: {{songs.length}}<br />
@@ -20,7 +25,7 @@
<div class="col-xs-9 text-right">
<div>
<h3 *ngIf="!album"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="album">{{album.Rating}}/100</h3>
<h3 *ngIf="album">{{album['Album Rating']}}/100</h3>
</div>
<div><br>Rating</div>
</div>

View File

@@ -1,12 +1,13 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
import { ElsService } from './../els.service';
import { Song } from './../model/song';
import { Album } from './../model/album';
import { SongTableComponent } from '../song-table/song-table.component';
import { TsService } from '../ts-service/ts.service';
import { TsAlbumService } from '../ts-service/ts-album.service';
@Component({
selector: 'app-album',
templateUrl: './album.component.html',
@@ -19,24 +20,24 @@ export class AlbumComponent implements OnInit {
albumName = '';
songs: Array<Song> = [];
album: Album = new Album(); // If album not found, will be replaced by 'undefined'
sortFilter: boolean = false; // Show only song to sort
// Prevent useless data load + activate button in interface var
moreDataAvailable = true;
lockLoadData = false;
constructor(
private elsService: ElsService,
private route: ActivatedRoute,
private location: Location
private tsAlbumService: TsAlbumService,
private route: ActivatedRoute
) { }
ngOnInit(): void {
this.route.params
.subscribe((params: Params) => this.albumName = params['name']);
this.route.params.subscribe((params: Params) => this.albumName = params['name']);
this.route.queryParams.subscribe(params => { this.sortFilter = params.tosort ?? false; });
this.loadSongs();
this.elsService.getAlbum(this.albumName).subscribe(data => this.album = data);
this.tsAlbumService.getAlbum(this.albumName).subscribe(data => this.album = data);
}
loadSongs(): void {
@@ -50,9 +51,9 @@ export class AlbumComponent implements OnInit {
}
this.lockLoadData = true;
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe(
this.tsAlbumService.getAlbumSongs(this.albumName, this.songs.length, this.sortFilter).subscribe(
data => {
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
this.moreDataAvailable = data.length === TsService.DEFAULT_SIZE;
// Erase song array with result for first load, then add elements one by one
// instead use concat => concat will sort table at each load, very consuming! and not user friendly

View File

@@ -1,71 +1,77 @@
import { Component, OnInit } from '@angular/core';
import { ElsAlbumService } from '../els-album.service';
import { Component, OnInit } from "@angular/core";
import { Album } from '../model/album';
import { Album } from "../model/album";
import { Utils } from '../utils';
import { Utils } from "../utils";
import { TsAlbumService } from "../ts-service/ts-album.service";
enum query_edit_type {
exclude = 'must_not',
select = 'must'
exclude = "must_not",
select = "must",
}
@Component({
selector: 'app-albums',
templateUrl: './albums.component.html',
styleUrls: ['./albums.component.css']
selector: "app-albums",
templateUrl: "./albums.component.html",
styleUrls: ["./albums.component.css"],
})
export class AlbumsComponent implements OnInit {
numberToArray = Utils.numberToArray;
numberToArray = Utils.numberToArray; // For star representation
albums: Album[] = [];
filterQuery = Object.assign({}, ElsAlbumService.GET_ALBUMS_DEFAULT_QUERY);
queryEdited = false;
filterParams = TsAlbumService.GET_ALBUMS_DEFAULT_PARAMS();
queryEdited = false; // Show reset button if true
constructor(private elsService : ElsAlbumService) { }
constructor(private tsService: TsAlbumService) {}
ngOnInit(): void {
this.loadData();
}
private editQuery(field: string, value: string, type: query_edit_type): void {
private editQuery(field: string, value: Album, type: query_edit_type): void {
// TODO Move this method to a service
if (value[field] instanceof Array) {
value[field] = value[field][0]
value[field] = value[field][0];
}
// If firt edit, add needed fields in ELS Query
if (!this.filterQuery['query']) {
this.filterQuery['query']['bool'][type].push({ 'must': [] })
this.filterQuery['query']['bool'][type].push({ 'must_not': [] })
if (type == query_edit_type.exclude) {
// Filter can be cumulated
// TODO Specific treatment for array? https://typesense.org/docs/0.25.1/api/search.html#filter-parameters
this.filterParams = this.filterParams.append(
"filter_by",
field + ":!=`" + value[field] + "`"
);
}
this.filterQuery['query']['bool'][type].push({
'match_phrase': {
[field]: value[field]
if (type == query_edit_type.select) {
this.filterParams = this.filterParams
.delete("q")
.append("q", value[field])
.delete("query_by")
.append("query_by", field);
}
})
this.queryEdited = true;
}
exlude(field: string, value: string): void {
this.editQuery(field, value, query_edit_type.exclude)
this.loadData()
exlude(field: string, value: Album): void {
this.editQuery(field, value, query_edit_type.exclude);
this.loadData();
}
select(field: string, value: string): void {
this.editQuery(field, value, query_edit_type.select)
this.loadData()
select(field: string, value: Album): void {
this.editQuery(field, value, query_edit_type.select);
this.loadData();
}
resetQuery(): void {
this.filterQuery = Object.assign({}, ElsAlbumService.GET_ALBUMS_DEFAULT_QUERY);
this.filterParams = TsAlbumService.GET_ALBUMS_DEFAULT_PARAMS();
this.loadData();
}
loadData(): void {
// console.log(JSON.stringify(this.filterQuery))
this.elsService.getAlbums(this.filterQuery).subscribe(data => this.albums = data);
console.log(this.filterParams.toString());
this.tsService
.getAlbums(this.filterParams)
.subscribe((data) => (this.albums = data));
}
}

View File

@@ -7,6 +7,7 @@ import { ArtistComponent } from './artist/artist.component';
import { GenreComponent } from './genre/genre.component';
import { TopPlayedComponent } from './top-played/top-played.component';
import { AlbumsComponent } from './albums/albums.component';
import { ToSortComponent } from './to-sort/to-sort.component';
const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
@@ -15,7 +16,8 @@ const routes: Routes = [
{ path: 'album', component: AlbumsComponent },
{ path: 'artist/:name', component: ArtistComponent },
{ path: 'genre/:name', component: GenreComponent },
{ path: 'top-played', component: TopPlayedComponent }
{ path: 'top-played', component: TopPlayedComponent },
{ path: 'to-sort', component: ToSortComponent }
];
@NgModule({

View File

@@ -36,7 +36,8 @@ nav a.active {
/* FIXME Code Repetition */
.btn-top {
display: inline-block;
display: flex;
flex-direction: column;
position: fixed;
z-index: 1;
-webkit-transition: opacity .3s 0s, visibility 0s 0s;

View File

@@ -1,5 +1,8 @@
<nav>
<a class="btn-top" routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a><br />
<a class="btn-top" routerLink="/album" routerLinkActive="active"><span class="glyphicon glyphicon-cd"></span></a>
<div class="btn-top">
<a routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a><br />
<a routerLink="/album" routerLinkActive="active"><span class="glyphicon glyphicon-cd"></span></a>
<a routerLink="/to-sort" routerLinkActive="active"><span class="glyphicon glyphicon-sort"></span></a>
</div>
</nav>
<router-outlet></router-outlet>

View File

@@ -11,8 +11,9 @@ import { GenreComponent } from './genre/genre.component';
import { SongTableComponent } from './song-table/song-table.component';
import { TopPlayedComponent } from './top-played/top-played.component';
import { ElsService } from './els.service';
import { ElsAlbumService } from './els-album.service';
import { TsService } from './ts-service/ts.service';
import { TsAlbumService } from './ts-service/ts-album.service';
import { TsArtistService } from './ts-service/ts-artist.service';
import { AppRoutingModule } from './app-routing.module';
@@ -22,6 +23,7 @@ import { SortByPipe } from './pipes/sort-by.pipe';
import { ConvertSizeToStringPipe } from './pipes/convert-size-to-string.pipe';
import { RoundPipe } from './pipes/round.pipe';
import { AlbumsComponent } from './albums/albums.component';
import { ToSortComponent } from './to-sort/to-sort.component';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
@@ -46,11 +48,13 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
SortByPipe,
ConvertSizeToStringPipe,
TopPlayedComponent,
RoundPipe
RoundPipe,
ToSortComponent
],
providers: [
ElsService,
ElsAlbumService
TsService,
TsAlbumService,
TsArtistService
],
bootstrap: [ AppComponent ]
})

View File

@@ -1,12 +1,13 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
import { ElsService } from './../els.service';
import { Song } from './../model/song';
import { Artist } from './../model/artist';
import { SongTableComponent } from '../song-table/song-table.component';
import { TsService } from '../ts-service/ts.service';
import { TsArtistService } from '../ts-service/ts-artist.service';
@Component({
selector: 'app-artist',
templateUrl: './artist.component.html',
@@ -25,19 +26,26 @@ export class ArtistComponent implements OnInit {
artist: Artist = new Artist();
lockLoadData = false;
countSong: number;
toSortFilter: boolean = false; // Show only song to sort
constructor(
private elsService: ElsService,
private elsService: TsArtistService,
private route: ActivatedRoute,
private location: Location
) { }
ngOnInit(): void {
this.route.params.subscribe((params: Params) => this.artistName = params['name']);
this.route.queryParams.subscribe(params => { this.toSortFilter = params.tosort ?? false; });
this.elsService.getArtist(this.artistName).subscribe(data => this.artist = data);
this.elsService.getCountArtistSong(this.artistName).subscribe(data => this.countSong = data);
this.elsService.getCountArtistSong(this.artistName, this.toSortFilter).subscribe(data => {
this.countSong = data
this.artist['Track Count'] = this.countSong;
// TODO Async problem: some time, get updated data, some time no
// TODO Use only this value?
// TODO ==> Show each time if there are unsorted songs
});
this.loadSongs();
}
@@ -54,9 +62,11 @@ export class ArtistComponent implements OnInit {
}
this.lockLoadData = true;
this.elsService.getArtistSongs(this.artistName, this.songs.length).subscribe(
this.elsService.getArtistSongs(this.artistName, this.songs.length, this.toSortFilter).subscribe(
data => {
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
this.moreDataAvailable = data.length === TsService.DEFAULT_SIZE;
console.log(data.length)
console.log(this.moreDataAvailable)
// Erase song array with result for first load, then add elements one by one
// instead use concat => concat will sort table at each load, very consuming! and not user friendly

View File

@@ -112,9 +112,9 @@
</thead>
<tbody>
<tr *ngFor="let album of lastAddedAlbums">
<td><a [routerLink]="['/album', album.key]">{{album.key}}</a></td>
<td>{{album.doc_count}}</td>
<td><a [routerLink]="['/artist', albumArtists[album.key]]">{{albumArtists[album.key]}}</a></td>
<td><a [routerLink]="['/album/', album.group_key[0]]">{{album.group_key[0]}}</a></td>
<td>{{album.found}}</td>
<td><a [routerLink]="['/artist', albumArtists[album.group_key[0]]]">{{albumArtists[album.group_key[0]]}}</a></td>
</tr>
</tbody>
</table>
@@ -156,8 +156,8 @@
</thead>
<tbody>
<tr *ngFor="let genre of topGenres">
<td><a [routerLink]="['/genre', genre.key]">{{genre.key}}</a></td>
<td>{{genre.doc_count}}</td>
<td><a [routerLink]="['/genre', genre.value]">{{genre.value}}</a></td>
<td>{{genre.count}}</td>
</tr>
</tbody>
</table>
@@ -173,8 +173,8 @@
</thead>
<tbody>
<tr *ngFor="let genre of bottomGenres">
<td><a [routerLink]="['/genre', genre.key]">{{genre.key}}</a></td>
<td>{{genre.doc_count}}</td>
<td><a [routerLink]="['/genre', genre.value]">{{genre.value}}</a></td>
<td>{{genre.count}}</td>
</tr>
</tbody>
</table>

View File

@@ -1,13 +1,15 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ElsService } from './../els.service';
import { ElsService } from '../els-service/els.service';
import { Song } from './../model/song';
import { Bucket } from './../model/bucket';
import { Suggested } from '../model/suggested';
import {Observable, of, OperatorFunction} from 'rxjs';
import {catchError, debounceTime, distinctUntilChanged, map, tap, switchMap} from 'rxjs/operators';
import { TsService } from '../ts-service/ts.service';
import { TsBucket } from '../model/tsBucket';
@Component({
selector: 'app-dashboard',
@@ -24,48 +26,42 @@ export class DashboardComponent implements OnInit {
albumArtistCount = 0;
topGenres: Bucket[] = [];
bottomGenres: Bucket[] = [];
topGenres: TsBucket[] = [];
bottomGenres: TsBucket[] = [];
mostPlayedSongs: Song[] = [];
lastAddedAlbums: Bucket[] = [];
lastAddedAlbums: TsBucket[] = [];
albumArtists = [];
searchTerm = ''
suggested : Suggested[] = []
constructor(private elsService: ElsService, private route: Router) { }
constructor(private tsService: TsService, private route: Router) { }
ngOnInit(): void {
this.elsService.getTime().then(result => {
this.tsService.getTime().then(result => {
this.totalTime = result;
});
this.elsService.getSize().then(result => this.totalSize = result);
this.tsService.getSize().then(result => this.totalSize = result);
this.elsService.getCountSong(ElsService.SONG_INDEX_NAME)
this.tsService.getCountSong(ElsService.SONG_INDEX_NAME)
.then(result => this.trackCountSong = result);
// TODO: Unused information
// this.elsService.getCountSong(ElsService.ARTIST_INDEX_NAME)
// .then(result => this.trackCountArtist = result);
// this.elsService.getCountSong(ElsService.ALBUM_INDEX_NAME)
// .then(result => this.trackCountAlbum = result);
this.elsService.getCountNeverListenSong()
this.tsService.getCountNeverListenSong()
.then(result => this.neverListenSong = result);
this.elsService.getMostPlayedTrack().subscribe(
this.tsService.getMostPlayedTrack().subscribe(
data => this.mostPlayedSongs = data
);
this.elsService.getGenres().subscribe(data => this.topGenres = data);
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
// this.elsService.getGenreCount().subscribe(data => console.log(data));
this.tsService.getGenres().subscribe(data => this.topGenres = data);
this.tsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
this.tsService.getGenreCount().subscribe(data => console.log(data));
const lastAddedAlbumsTemp: Bucket[] = [];
const BreakException = {};
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
const lastAddedAlbumsTemp: TsBucket[] = [];
this.tsService.getLastAddedAlbums(6).subscribe(buckets => {
buckets.forEach(bucket => {
// console.log(bucket);
@@ -74,8 +70,8 @@ export class DashboardComponent implements OnInit {
} else {
let found = false;
lastAddedAlbumsTemp.forEach(element => {
if (element.key === bucket.key) {
element.doc_count += bucket.doc_count;
if (element.group_key === bucket.group_key) {
element.found += bucket.found;
found = true;
}
});
@@ -84,24 +80,22 @@ export class DashboardComponent implements OnInit {
}
}
});
// console.log("alors");
// console.log(lastAddedAlbumsTemp);
this.lastAddedAlbums = lastAddedAlbumsTemp;
this.lastAddedAlbums.forEach(bucket => this.getArtistName(bucket));
});
}
private getArtistName(albumBucket: Bucket) {
private getArtistName(albumBucket: TsBucket) {
// For each bucket.key (album name), search artist.
// Use track count to compare
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
this.tsService.getArtistFromAlbumName(albumBucket.group_key[0]).subscribe(albums => {
// Identification of the good album
let goodAlbum;
if (albums.length > 1) {
// More than one result for an album name: search good by track count
albums.forEach(album => {
if (album['Track Count'] === albumBucket.doc_count) {
if (album['Track Count'] === albumBucket.found) {
goodAlbum = album;
}
});
@@ -132,7 +126,7 @@ export class DashboardComponent implements OnInit {
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term =>
this.elsService.getSuggest(term).pipe(
this.tsService.getSuggest(term).pipe(
tap(() => this.searchFailed = false),
catchError(() => {
this.searchFailed = true;

View File

@@ -1,10 +1,10 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'
import { HttpClient } from '@angular/common/http'
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { Album } from './model/album';
import { Album } from './../model/album';
import { ElsService } from './els.service';
@Injectable()

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ElsArtistService } from './els-artist.service';
describe('ElsArtistService', () => {
let service: ElsArtistService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ElsArtistService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,121 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { catchError, map } from "rxjs/operators";
import { Artist } from "../model/artist";
import { Song } from "../model/song";
import { ElsService } from "./els.service";
@Injectable()
export class ElsArtistService extends ElsService {
constructor(protected http: HttpClient) {
super(http);
}
private getQuerySongsWithArtistName(
artistName: string,
sortFilter: boolean = false,
size: number = 0,
from: number = 0
) {
let query = {
query: {
bool: {
should: [
{ match_phrase: { "Album Artist": artistName } },
{ match_phrase: { Artist: artistName } },
],
must_not: [],
},
},
};
if (sortFilter) {
console.log("ElsArtistService- TO SORT filter enabled");
query = this.addSortFilterToQuery(query);
}
if (size) {
query["size"] = size;
}
if (from) {
query["from"] = from;
}
return query;
}
public getArtist(artistName: string): Observable<Artist> {
return this.http
.post(
this.elsUrl + ElsService.ARTIST_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
query: {
match_phrase: { Artist: artistName },
},
size: ElsService.DEFAULT_SIZE,
}),
{ headers: this.headers }
)
.pipe(
map((res) => this.responseToOneTypedResult<Artist>(res, artistName)),
catchError((error) =>
this.handleError(error, "getArtist(" + artistName + ")")
)
);
}
public getArtistSongs(
artistName: string,
from: number = 0,
sortFilter = false
): Observable<Song[]> {
console.info(
"getArtistSongs- Artist name: " + artistName + " - from: " + from
);
let query = this.getQuerySongsWithArtistName(
artistName,
sortFilter,
ElsService.DEFAULT_SIZE,
from
);
return this.http
.post(
this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify(query),
{ headers: this.headers }
)
.pipe(
map((res) => this.responseToSongs(res)),
catchError((error) =>
this.handleError(
error,
"getArtistSongs(" + artistName + "," + from + ")"
)
)
);
}
public getCountArtistSong(
artistName: string,
sortFilter = false
): Observable<number> {
console.log("artistname: " + artistName);
const query = this.getQuerySongsWithArtistName(artistName, sortFilter);
return this.http
.post<any>(
this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
JSON.stringify(query),
{ headers: this.headers }
)
.pipe(
map((res) => res.count as number),
catchError((error) =>
this.handleError(error, "getCountArtistSong" + artistName + ")")
)
);
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ElsSortService } from './els-sort.service';
describe('ElsSortService', () => {
let service: ElsSortService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ElsSortService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,169 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { ElsService } from './els.service';
import { Album } from './../model/album';
@Injectable({
providedIn: 'root'
})
export class ElsSortService extends ElsService {
constructor(protected http: HttpClient) {
super(http);
}
getTime(): Promise<number> {
return this.http
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
aggs: {
sum_time: {
sum: { field: 'Total Time'}
}
},
'size': 0
}), {headers: this.headers})
.toPromise()
.then(res => res.aggregations.sum_time.value as number)
.catch(error => this.handleError(error, 'getTime()'));
}
getSize(): Promise<number> {
return this.http
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
aggs: {
sum_time: {
sum: { field: 'Size' }
}
},
'size': 0
}), {headers: this.headers})
.toPromise()
.then(res => res.aggregations.sum_time.value as number)
.catch(error => this.handleError(error, 'getSize()'));
}
getCountSong(): Promise<number> {
return this.http
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
}
}), {headers: this.headers})
.toPromise()
.then(res => res.count as number)
.catch(error => this.handleError(error, 'getCountSong()'));
}
getCountNeverListenSong(): Promise<number> {
return this.http
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
JSON.stringify({
'query': {
'bool': {
'must_not': [
{
'exists': { 'field': 'Play Count'}
}, {
term: {
"Location.tree": "/F:/Musique"
} }
]
}
}
}), {headers: this.headers})
.toPromise()
.then(res => res.count as number)
.catch(error => this.handleError(error, 'getCountNeverListenSong()'));
}
getNbAlbums(): Promise<number> {
return this.http
.post<any>(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
'query': {
'bool': {
'must_not': [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
size: 0,
"aggs": {
"album_count": {
"cardinality": {
"field": "Album.raw"
}
}
}
}), {headers: this.headers})
.toPromise()
.then(res => res.aggregations.album_count.value as number )
.catch(error => this.handleError(error, 'getNbAlbums()'));
}
getAlbums(): Observable<Album[]> {
return this.http
.post(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
'size': 550,
"sort": [
{ "Play Count": "desc"}
]
}), {headers: this.headers})
.pipe(
map(res => this.responseToAlbums(res)),
catchError(error => this.handleError(error, 'getAlbums'))
);
}
}

View File

@@ -1,14 +1,14 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { Song } from './model/song';
import { Album } from './model/album';
import { Artist } from './model/artist';
import { Bucket } from './model/bucket';
import { Suggested } from './model/suggested';
import { Song } from '../model/song';
import { Album } from '../model/album';
import { Artist } from '../model/artist';
import { Bucket } from '../model/bucket';
import { Suggested } from '../model/suggested';
@Injectable()
export class ElsService {
@@ -21,8 +21,9 @@ export class ElsService {
protected static readonly ACTION_SEARCH = '/_search';
protected static readonly ACTION_COUNT = '/_count';
protected elsUrl = 'http://localhost:9200';
protected elsUrl = 'http://192.168.1.20:9200';
protected headers = new HttpHeaders({'Content-Type': 'application/json'});
protected defaultLocation = "/F:/Musique"; // TODO Use conf
constructor(protected http: HttpClient) { }
@@ -172,20 +173,48 @@ export class ElsService {
);
}
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
return this.http
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
'query': {
'match_phrase': { 'Album': albumName }
getAlbumSongs(albumName: string, from: number = 0, toSortFilter = false): Observable<Song[]> {
// TODO Move in els-album service
console.info(
"getAlbumSongs- Album name: " + albumName + " - from: " + from
);
let query = {
query: {
bool: {
must: [
{
match_phrase: {
"Album.raw": albumName,
},
'size': ElsService.DEFAULT_SIZE,
'from': from
}), {headers: this.headers})
},
],
must_not: [],
},
},
size: ElsService.DEFAULT_SIZE,
from: from,
};
if (toSortFilter) {
console.log("getAlbumSongs- TO SORT filter enabled");
query = this.addSortFilterToQuery(query)
}
return this.http
.post(
this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify(query),
{ headers: this.headers }
)
.pipe(
map(res => this.responseToSongs(res)),
catchError(error => this.handleError(error, 'getAlbumSongs(' + albumName + ',' + from + ')'))
map((res) => this.responseToSongs(res)),
catchError((error) =>
this.handleError(
error,
"getAlbumSongs(" + albumName + "," + from + ")"
)
)
);
}
@@ -203,31 +232,11 @@ export class ElsService {
}), {headers: this.headers})
.pipe(
map(res => this.responseToSongs(res)),
catchError(error => this.handleError(error, 'getAlbumSongs(' + genreName + ',' + from + ')'))
catchError(error => this.handleError(error, 'getGenreSongs(' + genreName + ',' + from + ')'))
);
}
getArtistSongs(artistName: string, from: number = 0): Observable<Song[]> {
console.info('getArtistSongs- Artist name: ' + artistName + ' - from: ' + from);
return this.http
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
'query': {
'bool': {
'should': [
{'match_phrase' : { 'Album Artist' : artistName }},
{'match_phrase' : { 'Artist' : artistName }}
]
}
},
'size': ElsService.DEFAULT_SIZE,
'from': from
}), {headers: this.headers})
.pipe(
map(res => this.responseToSongs(res)),
catchError(error => this.handleError(error, 'getArtistSongs(' + artistName + ',' + from + ')'))
);
}
getAlbum(albumName: string): Observable<Album> {
// TODO Why this is used on album pages?
@@ -246,21 +255,6 @@ export class ElsService {
);
}
getArtist(artistName: string): Observable<Artist> {
return this.http
.post(this.elsUrl + ElsService.ARTIST_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
'query': {
'match_phrase': { 'Artist': artistName }
},
'size': ElsService.DEFAULT_SIZE
}), {headers: this.headers})
.pipe(
map(res => this.responseToOneTypedResult<Artist>(res, artistName)),
catchError(error => this.handleError(error, 'getArtist(' + artistName + ')'))
);
}
getGenres(ordering: string = 'desc'): Observable<Bucket[]> {
return this.http
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
@@ -283,25 +277,6 @@ export class ElsService {
);
}
// getGenreCount(): Observable<number> {
// return this.http
// .post<any>(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
// JSON.stringify({
// 'aggs' : {
// 'genres' : {
// 'cardinality' : {
// 'field' : 'Genre.original',
// 'missing': 'N/A',
// }
// }
// },
// 'size': 0
// }), {headers: this.headers})
// .pipe(
// map(res => res.aggregations.genres.value)
// );
// }
getLastAddedAlbums(month: number): Observable<Bucket[]> {
return this.http
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
@@ -319,7 +294,7 @@ export class ElsService {
'date' : {
'terms': {
'field' : 'Date Added',
'order': { '_term': 'desc' },
'order': { '_key': 'desc' },
'size': 20
},
'aggs': {
@@ -339,7 +314,7 @@ export class ElsService {
// TODO Take in consideration "sum_other_doc_count"
}
getArtistFromAlbumName(albumname: string): Observable<Album[]> {
getArtistFromAlbumName(albumname: string): Observable<Album[]> { // TODO Rename ?
return this.http
.post<any>(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
JSON.stringify({
@@ -363,26 +338,6 @@ export class ElsService {
);
}
getCountArtistSong(artistName: string): Observable<number> {
console.log('artistname: ' + artistName);
return this.http
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
JSON.stringify({
'query': {
'bool': {
'should': [
{'match_phrase' : { 'Album Artist' : artistName }},
{'match_phrase' : { 'Artist' : artistName }}
]
}
}
}), {headers: this.headers})
.pipe(
map(res => res.count as number),
catchError(error => this.handleError(error, 'getCountArtistSong' + artistName + ')'))
);
}
getSuggest(text: string): Observable<Suggested[]> {
console.log('search sugget: ' + text);
return this.http
@@ -418,7 +373,7 @@ export class ElsService {
* @param res Response to process
* @param name The searched name - for console output
*/
private responseToOneTypedResult<T>(res: any, name: string): T {
protected responseToOneTypedResult<T>(res: any, name: string): T {
const hits = res.hits.hits;
if (hits.length < 1) {
@@ -436,7 +391,7 @@ export class ElsService {
*
* @param res Response to process
*/
private responseToSongs(res: any): Song[] {
protected responseToSongs(res: any): Song[] {
const result: Array<Song> = [];
res.hits.hits.forEach((hit) => {
result.push(hit._source);
@@ -474,7 +429,7 @@ export class ElsService {
* @param res Response to process
* @param name Name of aggregation
*/
private responseAggregationToBucket(res: any, name: string): Bucket[] {
protected responseAggregationToBucket(res: any, name: string): Bucket[] {
const result: Array<Bucket> = [];
res.aggregations[name].buckets.forEach((bucket) => {
result.push(bucket);
@@ -513,4 +468,13 @@ export class ElsService {
console.error(error); // for demo purposes only
return Promise.reject(error.message || error);
}
protected addSortFilterToQuery(query) {
query.query.bool.must_not.push({
term: {
"Location.tree": this.defaultLocation,
},
});
return query;
}
}

View File

@@ -1,7 +1,7 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { ElsService } from '../els.service';
import { TsService } from '../ts-service/ts.service';
import { SongTableComponent } from '../song-table/song-table.component';
import { Song } from '../model/song';
@@ -17,7 +17,7 @@ export class GenreComponent implements OnInit {
songs: Array<Song> = [];
constructor(
private elsService: ElsService,
private tsService: TsService,
private route: ActivatedRoute
) { }
@@ -29,7 +29,7 @@ export class GenreComponent implements OnInit {
}
loadSongs(): any {
this.elsService.getGenreSongs(this.genreName, this.songs.length).subscribe(
this.tsService.getGenreSongs(this.genreName, this.songs.length).subscribe(
data => {
// this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;

View File

@@ -0,0 +1,6 @@
export class TsBucket {
value: string;
count: number;
group_key: string[];
found: number;
}

View File

@@ -0,0 +1,38 @@
.panel-stat {
min-height: 102px;
}
.panel-green {
background-color: #16a085;
color:white;
}
.panel-yellow {
background-color: #f1c40f;
color:white;
}
.panel-red {
background-color: #d9534f;
color:white;
}
.panel-purple {
background-color: #9b59b6;
color:white;
}
.panel-blue {
background-color: #3498db;
color:white;
}
.stats_icon {
font-size: 3em;
}
.circle {
border-radius: 50%;
background-color: #9b59b6;
margin: 0 auto;
}

View File

@@ -0,0 +1,132 @@
<div class="container">
<h1>To sort Songs - </h1>
<br />
<div class="row cardAdmin">
<div class="col-lg-3 col-md-3">
<div class="panel panel-yellow">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<span class="glyphicon glyphicon-play stats_icon"></span>
</div>
<div class="col-xs-9 text-right">
<div>
<h3 *ngIf="!trackCountSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="trackCountSong">{{trackCountSong}} songs</h3>
</div>
<div>Total songs
<br>~{{totalTime | convertMs}}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3">
<div class="panel panel-blue">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<span class="glyphicon glyphicon-cd stats_icon"></span>
</div>
<div class="col-xs-9 text-right">
<div>
<h3 *ngIf="!neverListenSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="neverListenSong">{{nbAlbums}}</h3>
</div>
<div><br>Albums</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<span class="glyphicon glyphicon-hdd stats_icon"></span>
</div>
<div class="col-xs-9 text-right">
<div>
<h3 *ngIf="!totalSize"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="totalSize">{{totalSize | convertSizeToString}}</h3>
</div>
<div><br>Total size</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3">
<div class="panel panel-red">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<span class="glyphicon glyphicon-stop stats_icon"></span>
</div>
<div class="col-xs-9 text-right">
<div>
<h3 *ngIf="!neverListenSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
<h3 *ngIf="neverListenSong">{{neverListenSong}}</h3>
</div>
<div><br>Never list. songs (~{{neverListenSong / trackCountSong * 100 | round}}%)</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<table class="table table-striped" style="white-space: nowrap;">
<thead>
<tr>
<th>Album</th>
<th>Track Count</th>
<th>Artist/Album Artist</th>
<th>Play Count</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let album of albums">
<td>
<a [routerLink]="['/album', album.Name]" [queryParams]="{tosort: true}">{{album.Name}}</a>&nbsp;
</td>
<td>{{album['Track Count']}}</td>
<ng-template [ngIf]="album['Album Artist']" [ngIfElse]="artistSection">
<td>
<a [routerLink]="['/artist', album['Album Artist']]" [queryParams]="{tosort: true}">{{album['Album Artist']}}</a>&nbsp;
</td>
</ng-template>
<ng-template #artistSection>
<td>
<a [routerLink]="['/artist', album.Artist[0]]">{{album.Artist}}</a>&nbsp;
</td>
</ng-template>
<ng-template #artistSection>
<td>
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>&nbsp;
</td>
</ng-template>
<td>
{{album['Play Count']}} ({{album['Play Count']/album['Track Count'] | number:'1.0-0'}}/songs)
</td>
<td class="star" [title]="(album['Album Rating Computed']?'Computed Rating: ':'Rating: ') + album['Album Rating']">
<span *ngFor="let item of numberToArray(album['Album Rating'], 20)">
<span class="glyphicon" [ngClass]="album['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ToSortComponent } from './to-sort.component';
describe('ToSortComponent', () => {
let component: ToSortComponent;
let fixture: ComponentFixture<ToSortComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ToSortComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ToSortComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,38 @@
import { Component, OnInit } from '@angular/core';
import { ElsSortService } from '../els-service/els-sort.service';
import { Bucket } from '../model/bucket';
import { Utils } from '../utils';
@Component({
selector: 'app-to-sort',
templateUrl: './to-sort.component.html',
styleUrls: ['./to-sort.component.css']
})
export class ToSortComponent implements OnInit {
numberToArray = Utils.numberToArray;
// Stats var
totalTime = 0;
totalSize = 0;
trackCountSong = 0;
neverListenSong = 0;
nbAlbums = 0;
// Global var
toSortAlbum: Bucket[] = [];
albums = []
constructor(private elsService: ElsSortService) { }
ngOnInit(): void {
// **** GET STATS ****//
this.elsService.getTime().then(result => this.totalTime = result);
this.elsService.getSize().then(result => this.totalSize = result);
this.elsService.getCountSong().then(result => this.trackCountSong = result);
this.elsService.getCountNeverListenSong().then(result => this.neverListenSong = result);
this.elsService.getNbAlbums().then(result => this.nbAlbums = result);
this.elsService.getAlbums().subscribe(data => this.albums = data)
}
}

View File

@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ElsService } from '../els.service';
import { TsService } from '../ts-service/ts.service';
import { Album } from '../model/album';
import { Artist } from '../model/artist';
@@ -15,10 +15,10 @@ export class TopPlayedComponent implements OnInit {
mostPlayedArtistsNaive: Artist[] = [];
mostPlayedArtists: Artist[] = [];
constructor(private elsService: ElsService) { }
constructor(private tsService: TsService) { }
ngOnInit() {
this.elsService.getMostPlayedAlbumNaive()
this.tsService.getMostPlayedAlbumNaive()
.then(result => {
result.forEach(album => {
if (album.Artist.length <= 10) {
@@ -29,29 +29,29 @@ export class TopPlayedComponent implements OnInit {
this.mostPlayedAlbumsNaive.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
});
this.elsService.getMostPlayedAlbum().subscribe(result => {
this.mostPlayedAlbums = result;
// this.elsService.getMostPlayedAlbum().subscribe(result => {
// this.mostPlayedAlbums = result;
this.mostPlayedAlbums.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
// TODO Load more! (Use a )
});
// this.mostPlayedAlbums.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
// // TODO Load more! (Use a )
// });
this.elsService.getMostPlayedArtistNaive()
this.tsService.getMostPlayedArtistNaive()
.then(result => {
this.mostPlayedArtistsNaive = result;
this.mostPlayedArtistsNaive.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
});
this.elsService.getMostPlayedArtist().subscribe(result => {
result.forEach(artist => {
if (artist['Track Count'] > 10) {
this.mostPlayedArtists.push(artist);
}
});
// this.tsService.getMostPlayedArtist().subscribe(result => {
// result.forEach(artist => {
// if (artist['Track Count'] > 10) {
// this.mostPlayedArtists.push(artist);
// }
// });
this.mostPlayedArtists.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
});
// this.mostPlayedArtists.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
// });
}
sortByAveragePlay(a: any, b: any) {

View File

@@ -0,0 +1,101 @@
import { HttpClient, HttpParams } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { catchError, map } from "rxjs/operators";
import { TsService } from "./ts.service";
import { Album } from "../model/album";
import { Song } from "../model/song";
@Injectable()
export class TsAlbumService extends TsService {
constructor(protected http: HttpClient) {
super(http);
}
getAlbum(albumName: string): Observable<Album> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", albumName);
queryParams = queryParams.append("query_by", "Name");
console.log("coucou");
return this.http
.get(
this.tsUrl +
TsService.ALBUM_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToOneTypedResult<Album>(res, albumName)),
catchError((error) =>
this.handleError(error, "getAlbum(" + albumName + ")")
)
);
}
getAlbumSongs(
albumName: string,
from: number = 0,
toSortFilter = false
): Observable<Song[]> {
// TODO Move in els-album service
console.info(
"getAlbumSongs- Album name: " + albumName + " - from: " + from
);
let queryParams = new HttpParams();
queryParams = queryParams.append("q", albumName);
queryParams = queryParams.append("query_by", "Album");
queryParams = queryParams.append("per_page", TsService.DEFAULT_SIZE);
queryParams = queryParams.append("offset", from);
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToSongs(res)),
catchError((error) =>
this.handleError(
error,
"getAlbumSongs(" + albumName + "," + from + ")"
)
)
);
}
public static GET_ALBUMS_DEFAULT_PARAMS(): HttpParams {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append(
"sort_by",
"Play Count:desc,Avg Bit Rate:desc"
);
queryParams = queryParams.append("filter_by", "Min Bit Rate:<128");
queryParams = queryParams.append("per_page", "100");
return queryParams;
}
getAlbums(queryParams: HttpParams): Observable<Album[]> {
return this.http
.get<any>(
this.tsUrl +
TsService.ALBUM_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToAlbums(res)),
catchError((error) => this.handleError(error, "getAlbums"))
);
}
}

View File

@@ -0,0 +1,140 @@
import { HttpClient, HttpParams } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { catchError, map } from "rxjs/operators";
import { TsService } from "./ts.service";
import { Artist } from "../model/artist";
import { Song } from "../model/song";
@Injectable()
export class TsArtistService extends TsService {
constructor(protected http: HttpClient) {
super(http);
}
private getQuerySongsWithArtistName(
artistName: string,
sortFilter: boolean = false,
size: number = 0,
from: number = 0
) {
let query = {
query: {
bool: {
should: [
{ match_phrase: { "Album Artist": artistName } },
{ match_phrase: { Artist: artistName } },
],
must_not: [],
},
},
};
if (sortFilter) {
console.log("ElsArtistService- TO SORT filter enabled");
query = this.addSortFilterToQuery(query);
}
if (size) {
query["size"] = size;
}
if (from) {
query["from"] = from;
}
return query;
}
public getArtist(artistName: string): Observable<Artist> {
console.log("getArtist");
let queryParams = new HttpParams();
queryParams = queryParams.append("q", artistName);
queryParams = queryParams.append("query_by", "Name");
return this.http
.get<any>(
this.tsUrl +
TsService.ARTIST_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToOneTypedResult<Artist>(res, artistName)),
catchError((error) =>
this.handleError(error, "getArtist(" + artistName + ")")
)
);
}
public getArtistSongs(
artistName: string,
from: number = 0,
sortFilter = false
): Observable<Song[]> {
console.info(
"getArtistSongs- Artist name: " + artistName + " - from: " + from
);
let query = this.getQuerySongsWithArtistName(
artistName,
sortFilter,
TsService.DEFAULT_SIZE,
from
);
let queryParams = new HttpParams();
queryParams = queryParams.append("q", artistName);
queryParams = queryParams.append("query_by", "Artist,Album Artist");
queryParams = queryParams.append("per_page", TsService.DEFAULT_SIZE);
queryParams = queryParams.append("offset", from);
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToSongs(res)),
catchError((error) =>
this.handleError(
error,
"getArtistSongs(" + artistName + "," + from + ")"
)
)
);
}
public getCountArtistSong(
artistName: string,
sortFilter = false
): Observable<number> {
console.log("artistname: " + artistName);
const query = this.getQuerySongsWithArtistName(artistName, sortFilter);
let queryParams = new HttpParams();
queryParams = queryParams.append("q", artistName);
queryParams = queryParams.append("query_by", "Artist"); // QUESTION ArtistName?
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => res.found as number),
catchError((error) =>
this.handleError(error, "getCountArtistSong" + artistName + ")")
)
);
}
}

View File

@@ -0,0 +1,169 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { TsService } from './ts.service';
import { Album } from '../model/album';
@Injectable({
providedIn: 'root'
})
export class TsSortService extends TsService {
constructor(protected http: HttpClient) {
super(http);
}
getTime(): Promise<number> {
return this.http
.post<any>(this.tsUrl + TsService.SONG_INDEX_NAME + TsService.ACTION_SEARCH,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
aggs: {
sum_time: {
sum: { field: 'Total Time'}
}
},
'size': 0
}), {headers: this.headers})
.toPromise()
.then(res => res.aggregations.sum_time.value as number)
.catch(error => this.handleError(error, 'getTime()'));
}
getSize(): Promise<number> {
return this.http
.post<any>(this.tsUrl + TsService.SONG_INDEX_NAME + TsService.ACTION_SEARCH,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
aggs: {
sum_time: {
sum: { field: 'Size' }
}
},
'size': 0
}), {headers: this.headers})
.toPromise()
.then(res => res.aggregations.sum_time.value as number)
.catch(error => this.handleError(error, 'getSize()'));
}
getCountSong(): Promise<number> {
return this.http
.post<any>(this.tsUrl + TsService.SONG_INDEX_NAME + TsService.ACTION_COUNT,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
}
}), {headers: this.headers})
.toPromise()
.then(res => res.count as number)
.catch(error => this.handleError(error, 'getCountSong()'));
}
getCountNeverListenSong(): Promise<number> {
return this.http
.post<any>(this.tsUrl + TsService.SONG_INDEX_NAME + TsService.ACTION_COUNT,
JSON.stringify({
'query': {
'bool': {
'must_not': [
{
'exists': { 'field': 'Play Count'}
}, {
term: {
"Location.tree": "/F:/Musique"
} }
]
}
}
}), {headers: this.headers})
.toPromise()
.then(res => res.count as number)
.catch(error => this.handleError(error, 'getCountNeverListenSong()'));
}
getNbAlbums(): Promise<number> {
return this.http
.post<any>(this.tsUrl + TsService.ALBUM_INDEX_NAME + TsService.ACTION_SEARCH,
JSON.stringify({
'query': {
'bool': {
'must_not': [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
size: 0,
"aggs": {
"album_count": {
"cardinality": {
"field": "Album.raw"
}
}
}
}), {headers: this.headers})
.toPromise()
.then(res => res.aggregations.album_count.value as number )
.catch(error => this.handleError(error, 'getNbAlbums()'));
}
getAlbums(): Observable<Album[]> {
return this.http
.post(this.tsUrl + TsService.ALBUM_INDEX_NAME + TsService.ACTION_SEARCH,
JSON.stringify({
query: {
bool: {
must_not: [
{
term: {
"Location.tree": "/F:/Musique"
}
}
]
}
},
'size': 550,
"sort": [
{ "Play Count": "desc"}
]
}), {headers: this.headers})
.pipe(
map(res => this.responseToAlbums(res)),
catchError(error => this.handleError(error, 'getAlbums'))
);
}
}

View File

@@ -0,0 +1,456 @@
import { HttpClient, HttpHeaders, HttpParams } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { catchError, map } from "rxjs/operators";
import { Album } from "../model/album";
import { Artist } from "../model/artist";
import { Song } from "../model/song";
import { Suggested } from "../model/suggested";
import { TsBucket } from "../model/tsBucket";
@Injectable()
export class TsService {
public static readonly DEFAULT_SIZE: number = 20;
public static readonly SONG_INDEX_NAME = "/songs";
public static readonly ARTIST_INDEX_NAME = "/artists";
public static readonly ALBUM_INDEX_NAME = "/albums";
public static readonly SUGGEST_INDEX_NAME = "/suggest";
protected static readonly ACTION_SEARCH = "/search";
protected static readonly ACTION_COUNT = "/_count";
protected tsUrl = "http://localhost:8108/collections";
protected tsUrlPure = "http://localhost:8108/";
protected headers = new HttpHeaders({
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": "toto",
});
protected defaultLocation = "/F:/Musique"; // TODO Use conf
constructor(protected http: HttpClient) {}
getTime(): Promise<number> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append("limit", "0");
queryParams = queryParams.append(
"facet_by",
"Total Time(Range:[0,99999999999999999])"
);
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.toPromise()
.then((res) => res.facet_counts[0].stats.sum as number)
.catch((error) => this.handleError(error, "getTime()"));
}
getSize(): Promise<number> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append("limit", "0");
queryParams = queryParams.append(
"facet_by",
"Size(Range:[0,99999999999999999])"
);
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.toPromise()
.then((res) => res.facet_counts[0].stats.sum as number)
.catch((error) => this.handleError(error, "getSize()"));
}
getCountSong(index: string): Promise<number> {
return this.http
.get<any>(this.tsUrl + TsService.SONG_INDEX_NAME, {
headers: this.headers,
})
.toPromise()
.then((res) => res.num_documents as number)
.catch((error) => this.handleError(error, "getCountSong(" + index + ")"));
}
getCountNeverListenSong(): Promise<number> {
// TODO Impossible sans valeur par defaut dans Play Count
return new Promise((resolve) => {
resolve(0);
});
}
getMostPlayedTrack(): Observable<Song[]> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append("sort_by", "Play Count:desc");
queryParams = queryParams.append("limit", 5);
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToSongs(res)),
catchError((error) => this.handleError(error, "getMostPlayedTrack()"))
);
}
getMostPlayedArtist(): Observable<Artist[]> {
return this.http
.post(
this.tsUrl + TsService.ARTIST_INDEX_NAME + TsService.ACTION_SEARCH,
JSON.stringify({
sort: [
{
_script: {
type: "number",
script: {
inline: "doc['Play Count'].value / doc['Track Count'].value",
},
order: "desc",
},
},
],
size: 100,
}),
{ headers: this.headers }
)
.pipe(
map((res) => this.responseToArtists(res)),
catchError((error) => this.handleError(error, "getMostPlayedArtist()"))
);
}
/**
* A basic get of albums ordered by 'Play Count' field.
*/
getMostPlayedAlbumNaive(): Promise<Album[]> {
return this.http
.get(
this.tsUrl +
TsService.ALBUM_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH +
"?sort_by=Play%20Count%3Adesc,Track%20Count%3Adesc&limit=20&q=*",
{ headers: this.headers }
)
.toPromise()
.then((res) => this.responseToAlbums(res))
.catch((error) => this.handleError(error, "getMostPlayedAlbumNaive"));
// TODO Excluse 'Divers' + compilation
}
getMostPlayedArtistNaive(): Promise<Artist[]> {
return this.http
.get(
this.tsUrl +
TsService.ARTIST_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH +
"?sort_by=Play%20Count%3Adesc&limit=20&q=*",
{ headers: this.headers }
)
.toPromise()
.then((res) => this.responseToAlbums(res))
.catch((error) => this.handleError(error, "getMostPlayedArtistNaive"));
// TODO Excluse 'Divers' + compilation
}
getGenreSongs(genreName: string, from: number = 0): Observable<Song[]> {
console.info(
"getGenreSongs- Genre name: " + genreName + " - from: " + from
);
let queryParams = new HttpParams();
queryParams = queryParams.append("q", genreName);
queryParams = queryParams.append("query_by", "Genre");
queryParams = queryParams.append("per_page", TsService.DEFAULT_SIZE);
queryParams = queryParams.append("offset", from);
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseToSongs(res)),
catchError((error) =>
this.handleError(
error,
"getGenreSongs(" + genreName + "," + from + ")"
)
)
);
}
getGenres(ordering: string = "desc"): Observable<TsBucket[]> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append("facet_by", "Genre");
queryParams = queryParams.append("max_facet_values", "5");
queryParams = queryParams.append("limit", "0");
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseAggregationToBucket(res)),
catchError((error) =>
this.handleError(error, "getGenres(" + ordering + ")")
)
);
}
getGenreCount(ordering: string = "desc"): Observable<number> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append("facet_by", "Genre");
queryParams = queryParams.append("max_facet_values", "0");
queryParams = queryParams.append("limit", "0");
return this.http
.get<any>(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => res.facet_counts[0].stats.total_values as number),
catchError((error) =>
this.handleError(error, "getGenres(" + ordering + ")")
)
);
}
getLastAddedAlbums(month: number): Observable<TsBucket[]> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", "*");
queryParams = queryParams.append("sort_by", "Track ID:desc");
queryParams = queryParams.append("group_by", "Album");
// TODO Deal with mounth?
return this.http
.get(
this.tsUrl +
TsService.SONG_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => this.responseSubAggregationToBucket(res)),
catchError((error) =>
this.handleError(error, "getLastAddedAlbums(" + month + ")")
)
);
}
getArtistFromAlbumName(albumname: string): Observable<Album[]> {
let queryParams = new HttpParams();
queryParams = queryParams.append("q", albumname);
queryParams = queryParams.append("query_by", "Name");
return this.http
.get<any>(
this.tsUrl +
TsService.ALBUM_INDEX_NAME +
"/documents" +
TsService.ACTION_SEARCH,
{ headers: this.headers, params: queryParams }
)
.pipe(
map((res) => res.hits),
map((hits: Array<any>) => {
const result: Array<Album> = [];
hits.forEach((hit) => {
result.push(hit.document);
});
return result;
}),
catchError((error) =>
this.handleError(error, "getArtistFromAlbumName(" + albumname + ")")
)
);
}
getSuggest(text: string): Observable<Suggested[]> {
let queryParameters = new HttpParams();
queryParameters = queryParameters.append("query_by", "Name");
queryParameters = queryParameters.append(
"sort_by",
"_text_match:desc,Play Count:desc"
);
queryParameters = queryParameters.append("limit", 5);
console.log("search sugget: " + text);
return this.http
.post<any>(
this.tsUrlPure + "multi_search",
JSON.stringify({
searches: [
{
collection: "albums",
q: text,
},
{
collection: "artists",
q: text,
},
],
}),
{ headers: this.headers, params: queryParameters }
)
.pipe(
map((res) => this.responseSuggesterToSuggested(res)),
catchError((error) =>
this.handleError(error, "getSuggest(" + text + ")")
)
);
}
/** Process a result to return just one result.
* Used to get an album or an artist.
* Take a name to put in console output if no result or more than one result.
*
* @param res Response to process
* @param name The searched name - for console output
*/
protected responseToOneTypedResult<T>(res: any, name: string): T {
const hits = res.hits;
if (hits.length < 1) {
console.info('No result found for name: "' + name);
return undefined;
}
if (hits.length > 1) {
// TODO Cumul results (for album)
console.error(
'More than one result for name: "' +
name +
'". Found (' +
hits.length +
"), return the first."
);
}
return hits[0].document;
}
/** Process a response to a array of songs.
*
* @param res Response to process
*/
protected responseToSongs(res: any): Song[] {
const result: Array<Song> = [];
res.hits.forEach((hit) => {
result.push(hit.document);
});
return result;
}
/** Process a response to a array of songs.
*
* @param res Response to process
*/
private responseToArtists(res: any): Artist[] {
const result: Array<Artist> = [];
res.hits.hits.forEach((hit) => {
result.push(hit._source);
});
return result;
}
/** Process an aggregation response to an array of Bucket.
*
* @param res Response to process
* @param name Name of aggregation
*/
protected responseAggregationToBucket(res: any): TsBucket[] {
const result: Array<TsBucket> = [];
res.facet_counts[0].counts.forEach((bucket) => {
result.push(bucket);
});
return result;
}
private responseSubAggregationToBucket(res: any): TsBucket[] {
const result: Array<TsBucket> = [];
res.grouped_hits.forEach((tmp) => {
result.push(tmp);
});
return result;
}
protected responseSuggesterToSuggested(res: any): Suggested[] {
const suggesteds: Array<Suggested> = [];
res.results.forEach((result) => {
let type = result.request_params.collection_name;
type = type.slice(0, type.length - 1);
result.hits.forEach((hit) => {
let suggested = new Suggested();
suggested.type = type;
suggested.name = hit.document.Name;
suggesteds.push(suggested);
});
});
return suggesteds;
}
protected handleError(error: any, origin: string): Promise<any> {
console.error("An error occurred!");
console.error("Origin function: ", origin);
console.error("An error occurred!", error); // for demo purposes only
console.error(error); // for demo purposes only
return Promise.reject(error.message || error);
}
protected addSortFilterToQuery(query) {
query.query.bool.must_not.push({
term: {
"Location.tree": this.defaultLocation,
},
});
return query;
}
/** Process a response to a array of songs.
*
* @param res Response to process
*/
protected responseToAlbums(res: any): Album[] {
const result: Array<Album> = [];
res.hits.forEach((hit) => {
result.push(hit.document);
});
return result;
}
}

View File

@@ -13,4 +13,4 @@ export const environment = {
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.

View File

@@ -22,16 +22,6 @@ import '@angular/localize/init';
* BROWSER POLYFILLS
*/
/** IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
@@ -59,7 +49,7 @@ import '@angular/localize/init';
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
import 'zone.js'; // Included with Angular CLI.
/***************************************************************************************************

View File

@@ -1,25 +1,16 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
}
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -10,11 +10,15 @@
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"target": "ES2022",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
],
"useDefineForClassFields": false
},
"angularCompilerOptions": {
"strictTemplates": true
}
}

View File

@@ -192,7 +192,8 @@ class ITunesParser:
'Avg Bit Rate': track['Bit Rate'],
'Min Bit Rate': track['Bit Rate'],
# 'Album Artist': '',
'Total Time': 0
'Total Time': 0,
'Location': ''
}
# Compute information
@@ -207,6 +208,8 @@ class ITunesParser:
self._albums[akey]['Play Count'] += play_count
self._albums[akey]['Total Time'] += total_time
self._albums[akey]['Location'] = os.path.dirname(track['Location'])
if self._albums[akey]['Min Bit Rate'] > track['Bit Rate']:
self._albums[akey]['Min Bit Rate'] = track['Bit Rate']

View File

@@ -1,4 +1,28 @@
{
"settings": {
"analysis": {
"analyzer": {
"custom_path_tree": {
"tokenizer": "custom_hierarchy"
},
"custom_path_tree_reversed": {
"tokenizer": "custom_hierarchy_reversed"
}
},
"tokenizer": {
"custom_hierarchy": {
"type": "path_hierarchy",
"delimiter": "/",
"skip": 3
},
"custom_hierarchy_reversed": {
"type": "path_hierarchy",
"delimiter": "/",
"reverse": "true"
}
}
}
},
"mappings" : {
"properties": {
"Artist": {
@@ -21,6 +45,19 @@
},
"Genre": {
"type": "keyword"
},
"Location": {
"type": "text",
"fields": {
"tree": {
"type": "text",
"analyzer": "custom_path_tree"
},
"tree_reversed": {
"type": "text",
"analyzer": "custom_path_tree_reversed"
}
}
}
}
}

View File

@@ -1,70 +1,556 @@
{
"settings": {
"analysis": {
"analyzer": {
"custom_path_tree": {
"tokenizer": "custom_hierarchy"
"name": "songs",
"token_separators": [":", "/", "."],
"fields": [
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Album",
"optional": true,
"sort": false,
"type": "string"
},
"custom_path_tree_reversed": {
"tokenizer": "custom_hierarchy_reversed"
}
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Album Rating",
"optional": true,
"sort": true,
"type": "int64"
},
"tokenizer": {
"custom_hierarchy": {
"type": "path_hierarchy",
"delimiter": "/",
"skip": 3
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Album Rating Computed",
"optional": true,
"sort": true,
"type": "bool"
},
"custom_hierarchy_reversed": {
"type": "path_hierarchy",
"delimiter": "/",
"reverse": "true"
}
}
}
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Artist",
"optional": true,
"sort": false,
"type": "string"
},
"mappings" : {
"properties": {
"Artist": {
"type": "text",
"fields": {
"raw": {"type": "keyword"}
}
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Artwork Count",
"optional": true,
"sort": true,
"type": "int64"
},
"Album Artist": {
"type": "text",
"fields": {
"raw": {"type": "keyword"}
}
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Bit Rate",
"optional": true,
"sort": true,
"type": "int64"
},
"Album": {
"type": "text",
"fields": {
"raw": {"type": "keyword"}
}
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Date Added",
"optional": true,
"sort": false,
"type": "string"
},
"Bit Rate": {
"type": "integer"
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Date Modified",
"optional": true,
"sort": false,
"type": "string"
},
"Genre": {
"type": "keyword"
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "File Folder Count",
"optional": true,
"sort": true,
"type": "int64"
},
"Kind": {
"type": "keyword"
{
"facet": true,
"index": true,
"infix": false,
"locale": "",
"name": "Genre",
"optional": true,
"sort": false,
"type": "string"
},
"Location": {
"type": "text",
"fields": {
"tree": {
"type": "text",
"analyzer": "custom_path_tree"
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Kind",
"optional": true,
"sort": false,
"type": "string"
},
"tree_reversed": {
"type": "text",
"analyzer": "custom_path_tree_reversed"
}
}
}
}
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Library Folder Count",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Location",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Name",
"optional": false,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Persistent ID",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Play Count",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Play Date",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Play Date UTC",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Rating",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Rating Computed",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Sample Rate",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": true,
"index": true,
"infix": false,
"locale": "",
"name": "Size",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Skip Count",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Skip Date",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": true,
"index": true,
"infix": false,
"locale": "",
"name": "Total Time",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Track ID",
"optional": false,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Track Number",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Track Type",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Year",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Composer",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Disabled",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Disc Count",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Disc Number",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Album Artist",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Sort Name",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Sort Album",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Comments",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Sort Artist",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Sort Composer",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Loved",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Volume Adjustment",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Compilation",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Part Of Gapless Album",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Track Count",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Sort Album Artist",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Album Loved",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "BPM",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Grouping",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Series",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Purchased",
"optional": true,
"sort": true,
"type": "bool"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "Release Date",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Movement Count",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Movement Name",
"optional": true,
"sort": false,
"type": "string"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Movement Number",
"optional": true,
"sort": true,
"type": "int64"
},
{
"facet": false,
"index": false,
"infix": false,
"locale": "",
"name": "Work",
"optional": true,
"sort": false,
"type": "string"
}
]
}