Compare commits
6 Commits
dev
...
928efb659e
| Author | SHA1 | Date | |
|---|---|---|---|
| 928efb659e | |||
| 88025347ec | |||
| 67e1f8bd0c | |||
| 042c2558ae | |||
| ad0487943a | |||
| 56050d0a49 |
21
README.md
21
README.md
@@ -1,21 +0,0 @@
|
||||
# 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
|
||||
```
|
||||
1
dashboard/.gitignore
vendored
1
dashboard/.gitignore
vendored
@@ -25,7 +25,6 @@
|
||||
!.vscode/extensions.json
|
||||
|
||||
# misc
|
||||
/.angular/cache
|
||||
/.sass-cache
|
||||
/connect.lock
|
||||
/coverage
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
v18.12.1
|
||||
@@ -68,18 +68,18 @@
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"options": {
|
||||
"buildTarget": "dashboard:build"
|
||||
"browserTarget": "dashboard:build"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "dashboard:build:production"
|
||||
"browserTarget": "dashboard:build:production"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "dashboard:build"
|
||||
"browserTarget": "dashboard:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
@@ -100,6 +100,19 @@
|
||||
"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": {
|
||||
@@ -114,5 +127,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultProject": "dashboard"
|
||||
}
|
||||
|
||||
33838
dashboard/package-lock.json
generated
33838
dashboard/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,38 +11,39 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@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"
|
||||
"@angular/animations": "~12.2.2",
|
||||
"@angular/common": "~12.2.2",
|
||||
"@angular/compiler": "~12.2.2",
|
||||
"@angular/core": "~12.2.2",
|
||||
"@angular/forms": "~12.2.2",
|
||||
"@angular/localize": "~12.2.2",
|
||||
"@angular/platform-browser": "~12.2.2",
|
||||
"@angular/platform-browser-dynamic": "~12.2.2",
|
||||
"@angular/router": "~12.2.2",
|
||||
"@ng-bootstrap/ng-bootstrap": "^10.0.0",
|
||||
"bootstrap": "^3.3.7",
|
||||
"rxjs": "~6.6.0",
|
||||
"tslib": "^2.0.0",
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@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",
|
||||
"@angular-devkit/build-angular": "~12.2.2",
|
||||
"@angular/cli": "~12.2.2",
|
||||
"@angular/compiler-cli": "~12.2.2",
|
||||
"@angular/localize": "^12.2.2",
|
||||
"@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": "~6.3.4",
|
||||
"karma-chrome-launcher": "~3.1.0",
|
||||
"karma-coverage": "~2.0.3",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
"karma-jasmine-html-reporter": "^1.5.0",
|
||||
"protractor": "~7.0.0",
|
||||
"ts-node": "~10.9.2",
|
||||
"ts-node": "~8.3.0",
|
||||
"tslint": "~6.1.0",
|
||||
"typescript": "~5.3.3"
|
||||
"typescript": "~4.3.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,8 @@
|
||||
<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">
|
||||
<img class="images" src="data:image/png;base64, {{album.Cover}}" height="500"/>
|
||||
<h3>Debug Zone</h3>
|
||||
ID: {{album.id}}<br />
|
||||
Returned song: {{songs.length}}<br />
|
||||
Theorical number song: {{ album ? album['Track Count'] : "" }}
|
||||
<span *ngIf="album && (songs.length == album['Track Count'])" class="glyphicon glyphicon-ok" style="color:green"></span>
|
||||
@@ -27,7 +20,7 @@
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!album"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="album">{{album['Album Rating']}}/100</h3>
|
||||
<h3 *ngIf="album">{{album.Rating}}/100</h3>
|
||||
</div>
|
||||
<div><br>Rating</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
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',
|
||||
@@ -20,24 +19,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 tsAlbumService: TsAlbumService,
|
||||
private route: ActivatedRoute
|
||||
private elsService: ElsService,
|
||||
private route: ActivatedRoute,
|
||||
private location: Location
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.params.subscribe((params: Params) => this.albumName = params['name']);
|
||||
this.route.queryParams.subscribe(params => { this.sortFilter = params.tosort ?? false; });
|
||||
this.route.params
|
||||
.subscribe((params: Params) => this.albumName = params['name']);
|
||||
|
||||
this.loadSongs();
|
||||
|
||||
this.tsAlbumService.getAlbum(this.albumName).subscribe(data => this.album = data);
|
||||
this.elsService.getAlbum(this.albumName).subscribe(data => this.album = data);
|
||||
}
|
||||
|
||||
loadSongs(): void {
|
||||
@@ -51,9 +50,9 @@ export class AlbumComponent implements OnInit {
|
||||
}
|
||||
|
||||
this.lockLoadData = true;
|
||||
this.tsAlbumService.getAlbumSongs(this.albumName, this.songs.length, this.sortFilter).subscribe(
|
||||
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe(
|
||||
data => {
|
||||
this.moreDataAvailable = data.length === TsService.DEFAULT_SIZE;
|
||||
this.moreDataAvailable = data.length === ElsService.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
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ElsAlbumService } from '../els-album.service';
|
||||
|
||||
import { Album } from "../model/album";
|
||||
import { Album } from '../model/album';
|
||||
|
||||
import { Utils } from "../utils";
|
||||
|
||||
import { TsAlbumService } from "../ts-service/ts-album.service";
|
||||
import { Utils } from '../utils';
|
||||
|
||||
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; // For star representation
|
||||
numberToArray = Utils.numberToArray;
|
||||
albums: Album[] = [];
|
||||
filterParams = TsAlbumService.GET_ALBUMS_DEFAULT_PARAMS();
|
||||
queryEdited = false; // Show reset button if true
|
||||
filterQuery = Object.assign({}, ElsAlbumService.GET_ALBUMS_DEFAULT_QUERY);
|
||||
queryEdited = false;
|
||||
|
||||
constructor(private tsService: TsAlbumService) {}
|
||||
constructor(private elsService : ElsAlbumService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadData();
|
||||
@@ -31,47 +30,42 @@ export class AlbumsComponent implements OnInit {
|
||||
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 (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] + "`"
|
||||
);
|
||||
// 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.select) {
|
||||
this.filterParams = this.filterParams
|
||||
.delete("q")
|
||||
.append("q", value[field])
|
||||
.delete("query_by")
|
||||
.append("query_by", field);
|
||||
}
|
||||
|
||||
this.filterQuery['query']['bool'][type].push({
|
||||
'match_phrase': {
|
||||
[field]: value[field]
|
||||
}
|
||||
})
|
||||
|
||||
this.queryEdited = true;
|
||||
}
|
||||
|
||||
exlude(field: string, value: Album): void {
|
||||
this.editQuery(field, value, query_edit_type.exclude);
|
||||
this.loadData();
|
||||
this.editQuery(field, value, query_edit_type.exclude)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
select(field: string, value: Album): void {
|
||||
this.editQuery(field, value, query_edit_type.select);
|
||||
this.loadData();
|
||||
this.editQuery(field, value, query_edit_type.select)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
resetQuery(): void {
|
||||
this.filterParams = TsAlbumService.GET_ALBUMS_DEFAULT_PARAMS();
|
||||
this.filterQuery = Object.assign({}, ElsAlbumService.GET_ALBUMS_DEFAULT_QUERY);
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
loadData(): void {
|
||||
console.log(this.filterParams.toString());
|
||||
this.tsService
|
||||
.getAlbums(this.filterParams)
|
||||
.subscribe((data) => (this.albums = data));
|
||||
// console.log(JSON.stringify(this.filterQuery))
|
||||
this.elsService.getAlbums(this.filterQuery).subscribe(data => this.albums = data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,8 @@ import { GenreComponent } from './genre/genre.component';
|
||||
import { SongTableComponent } from './song-table/song-table.component';
|
||||
import { TopPlayedComponent } from './top-played/top-played.component';
|
||||
|
||||
import { TsService } from './ts-service/ts.service';
|
||||
import { TsAlbumService } from './ts-service/ts-album.service';
|
||||
import { TsArtistService } from './ts-service/ts-artist.service';
|
||||
import { ElsService } from './els.service';
|
||||
import { ElsAlbumService } from './els-album.service';
|
||||
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
||||
@@ -52,9 +51,8 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
|
||||
ToSortComponent
|
||||
],
|
||||
providers: [
|
||||
TsService,
|
||||
TsAlbumService,
|
||||
TsArtistService
|
||||
ElsService,
|
||||
ElsAlbumService
|
||||
],
|
||||
bootstrap: [ AppComponent ]
|
||||
})
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
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',
|
||||
@@ -26,26 +25,19 @@ export class ArtistComponent implements OnInit {
|
||||
artist: Artist = new Artist();
|
||||
lockLoadData = false;
|
||||
countSong: number;
|
||||
toSortFilter: boolean = false; // Show only song to sort
|
||||
|
||||
constructor(
|
||||
private elsService: TsArtistService,
|
||||
private elsService: ElsService,
|
||||
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, 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.elsService.getCountArtistSong(this.artistName).subscribe(data => this.countSong = data);
|
||||
|
||||
this.loadSongs();
|
||||
}
|
||||
@@ -62,11 +54,9 @@ export class ArtistComponent implements OnInit {
|
||||
}
|
||||
|
||||
this.lockLoadData = true;
|
||||
this.elsService.getArtistSongs(this.artistName, this.songs.length, this.toSortFilter).subscribe(
|
||||
this.elsService.getArtistSongs(this.artistName, this.songs.length).subscribe(
|
||||
data => {
|
||||
this.moreDataAvailable = data.length === TsService.DEFAULT_SIZE;
|
||||
console.log(data.length)
|
||||
console.log(this.moreDataAvailable)
|
||||
this.moreDataAvailable = data.length === ElsService.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
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<span *ngIf="r.type == 'artist'" class="glyphicon glyphicon-user"></span>
|
||||
<span *ngIf="r.type == 'album'" class="glyphicon glyphicon-cd"></span>
|
||||
<ngb-highlight [result]="r.name" [term]="t"></ngb-highlight>
|
||||
</ng-template>
|
||||
</ng-template>
|
||||
|
||||
|
||||
<form class="navbar-form">
|
||||
@@ -112,9 +112,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let album of lastAddedAlbums">
|
||||
<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>
|
||||
<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>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -156,8 +156,8 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let genre of topGenres">
|
||||
<td><a [routerLink]="['/genre', genre.value]">{{genre.value}}</a></td>
|
||||
<td>{{genre.count}}</td>
|
||||
<td><a [routerLink]="['/genre', genre.key]">{{genre.key}}</a></td>
|
||||
<td>{{genre.doc_count}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -173,8 +173,8 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let genre of bottomGenres">
|
||||
<td><a [routerLink]="['/genre', genre.value]">{{genre.value}}</a></td>
|
||||
<td>{{genre.count}}</td>
|
||||
<td><a [routerLink]="['/genre', genre.key]">{{genre.key}}</a></td>
|
||||
<td>{{genre.doc_count}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { ElsService } from '../els-service/els.service';
|
||||
import { ElsService } from './../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',
|
||||
@@ -26,42 +24,48 @@ export class DashboardComponent implements OnInit {
|
||||
|
||||
albumArtistCount = 0;
|
||||
|
||||
topGenres: TsBucket[] = [];
|
||||
bottomGenres: TsBucket[] = [];
|
||||
topGenres: Bucket[] = [];
|
||||
bottomGenres: Bucket[] = [];
|
||||
|
||||
mostPlayedSongs: Song[] = [];
|
||||
|
||||
lastAddedAlbums: TsBucket[] = [];
|
||||
lastAddedAlbums: Bucket[] = [];
|
||||
albumArtists = [];
|
||||
|
||||
searchTerm = ''
|
||||
suggested : Suggested[] = []
|
||||
|
||||
constructor(private tsService: TsService, private route: Router) { }
|
||||
constructor(private elsService: ElsService, private route: Router) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.tsService.getTime().then(result => {
|
||||
this.elsService.getTime().then(result => {
|
||||
this.totalTime = result;
|
||||
});
|
||||
|
||||
this.tsService.getSize().then(result => this.totalSize = result);
|
||||
this.elsService.getSize().then(result => this.totalSize = result);
|
||||
|
||||
this.tsService.getCountSong(ElsService.SONG_INDEX_NAME)
|
||||
this.elsService.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.tsService.getCountNeverListenSong()
|
||||
this.elsService.getCountNeverListenSong()
|
||||
.then(result => this.neverListenSong = result);
|
||||
|
||||
this.tsService.getMostPlayedTrack().subscribe(
|
||||
this.elsService.getMostPlayedTrack().subscribe(
|
||||
data => this.mostPlayedSongs = 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));
|
||||
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));
|
||||
|
||||
const lastAddedAlbumsTemp: TsBucket[] = [];
|
||||
this.tsService.getLastAddedAlbums(6).subscribe(buckets => {
|
||||
const lastAddedAlbumsTemp: Bucket[] = [];
|
||||
const BreakException = {};
|
||||
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
|
||||
buckets.forEach(bucket => {
|
||||
// console.log(bucket);
|
||||
|
||||
@@ -70,8 +74,8 @@ export class DashboardComponent implements OnInit {
|
||||
} else {
|
||||
let found = false;
|
||||
lastAddedAlbumsTemp.forEach(element => {
|
||||
if (element.group_key === bucket.group_key) {
|
||||
element.found += bucket.found;
|
||||
if (element.key === bucket.key) {
|
||||
element.doc_count += bucket.doc_count;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
@@ -80,22 +84,24 @@ export class DashboardComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
});
|
||||
// console.log("alors");
|
||||
// console.log(lastAddedAlbumsTemp);
|
||||
|
||||
this.lastAddedAlbums = lastAddedAlbumsTemp;
|
||||
this.lastAddedAlbums.forEach(bucket => this.getArtistName(bucket));
|
||||
});
|
||||
}
|
||||
|
||||
private getArtistName(albumBucket: TsBucket) {
|
||||
private getArtistName(albumBucket: Bucket) {
|
||||
// For each bucket.key (album name), search artist.
|
||||
// Use track count to compare
|
||||
this.tsService.getArtistFromAlbumName(albumBucket.group_key[0]).subscribe(albums => {
|
||||
this.elsService.getArtistFromAlbumName(albumBucket.key).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.found) {
|
||||
if (album['Track Count'] === albumBucket.doc_count) {
|
||||
goodAlbum = album;
|
||||
}
|
||||
});
|
||||
@@ -126,7 +132,7 @@ export class DashboardComponent implements OnInit {
|
||||
distinctUntilChanged(),
|
||||
tap(() => this.searching = true),
|
||||
switchMap(term =>
|
||||
this.tsService.getSuggest(term).pipe(
|
||||
this.elsService.getSuggest(term).pipe(
|
||||
tap(() => this.searchFailed = false),
|
||||
catchError(() => {
|
||||
this.searchFailed = true;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { HttpClient, HttpHeaders } 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()
|
||||
@@ -1,16 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -1,121 +0,0 @@
|
||||
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 + ")")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
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';
|
||||
import { Album } from './model/album';
|
||||
import { Bucket } from './model/bucket';
|
||||
import { Song } from './model/song';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -112,38 +113,9 @@ export class ElsSortService extends ElsService {
|
||||
.catch(error => this.handleError(error, 'getCountNeverListenSong()'));
|
||||
}
|
||||
|
||||
getNbAlbums(): Promise<number> {
|
||||
getAlbums(): Observable<Bucket[]> {
|
||||
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,
|
||||
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
@@ -156,13 +128,19 @@ export class ElsSortService extends ElsService {
|
||||
]
|
||||
}
|
||||
},
|
||||
'size': 550,
|
||||
"sort": [
|
||||
{ "Play Count": "desc"}
|
||||
]
|
||||
'size': 0,
|
||||
'aggs': {
|
||||
'albums' : {
|
||||
'terms': {
|
||||
'field' : 'Album.raw',
|
||||
'order': { '_term': 'asc' },
|
||||
'size': 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.pipe(
|
||||
map(res => this.responseToAlbums(res)),
|
||||
map(res => this.responseAggregationToBucket(res, "albums")),
|
||||
catchError(error => this.handleError(error, 'getAlbums'))
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { 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,9 +21,8 @@ export class ElsService {
|
||||
protected static readonly ACTION_SEARCH = '/_search';
|
||||
protected static readonly ACTION_COUNT = '/_count';
|
||||
|
||||
protected elsUrl = 'http://192.168.1.20:9200';
|
||||
protected elsUrl = 'http://localhost:9200';
|
||||
protected headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||
protected defaultLocation = "/F:/Musique"; // TODO Use conf
|
||||
|
||||
constructor(protected http: HttpClient) { }
|
||||
|
||||
@@ -173,48 +172,20 @@ export class ElsService {
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
],
|
||||
must_not: [],
|
||||
},
|
||||
},
|
||||
size: ElsService.DEFAULT_SIZE,
|
||||
from: from,
|
||||
};
|
||||
|
||||
if (toSortFilter) {
|
||||
console.log("getAlbumSongs- TO SORT filter enabled");
|
||||
query = this.addSortFilterToQuery(query)
|
||||
}
|
||||
|
||||
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),
|
||||
{ headers: this.headers }
|
||||
)
|
||||
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase': { 'Album': albumName }
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE,
|
||||
'from': from
|
||||
}), {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 + ')'))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -232,11 +203,31 @@ export class ElsService {
|
||||
}), {headers: this.headers})
|
||||
.pipe(
|
||||
map(res => this.responseToSongs(res)),
|
||||
catchError(error => this.handleError(error, 'getGenreSongs(' + genreName + ',' + from + ')'))
|
||||
catchError(error => this.handleError(error, 'getAlbumSongs(' + 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?
|
||||
@@ -255,6 +246,21 @@ 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,
|
||||
@@ -277,6 +283,25 @@ 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,
|
||||
@@ -294,7 +319,7 @@ export class ElsService {
|
||||
'date' : {
|
||||
'terms': {
|
||||
'field' : 'Date Added',
|
||||
'order': { '_key': 'desc' },
|
||||
'order': { '_term': 'desc' },
|
||||
'size': 20
|
||||
},
|
||||
'aggs': {
|
||||
@@ -338,6 +363,26 @@ 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
|
||||
@@ -373,7 +418,7 @@ export class ElsService {
|
||||
* @param res Response to process
|
||||
* @param name The searched name - for console output
|
||||
*/
|
||||
protected responseToOneTypedResult<T>(res: any, name: string): T {
|
||||
private responseToOneTypedResult<T>(res: any, name: string): T {
|
||||
const hits = res.hits.hits;
|
||||
|
||||
if (hits.length < 1) {
|
||||
@@ -468,13 +513,4 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
|
||||
import { TsService } from '../ts-service/ts.service';
|
||||
import { ElsService } from '../els.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 tsService: TsService,
|
||||
private elsService: ElsService,
|
||||
private route: ActivatedRoute
|
||||
) { }
|
||||
|
||||
@@ -29,7 +29,7 @@ export class GenreComponent implements OnInit {
|
||||
}
|
||||
|
||||
loadSongs(): any {
|
||||
this.tsService.getGenreSongs(this.genreName, this.songs.length).subscribe(
|
||||
this.elsService.getGenreSongs(this.genreName, this.songs.length).subscribe(
|
||||
data => {
|
||||
// this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
export class Album {
|
||||
id: number;
|
||||
Name: string;
|
||||
Cover: string;
|
||||
Album: string;
|
||||
Artist: Array<string>;
|
||||
Rating: number;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export class TsBucket {
|
||||
value: string;
|
||||
count: number;
|
||||
group_key: string[];
|
||||
found: number;
|
||||
}
|
||||
@@ -4,78 +4,76 @@
|
||||
<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 class="panel panel-blue">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-time stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!totalTime"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="totalTime">{{totalTime | convertMs}}</h3>
|
||||
</div>
|
||||
<div><br>Total time ({{totalTime | convertMoreExact}})</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 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-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 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}}</h3>
|
||||
</div>
|
||||
<div><br>Total Songs</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 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>
|
||||
|
||||
@@ -91,22 +89,22 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let album of albums">
|
||||
<tr *ngFor="let album of toSortAlbum">
|
||||
<td>
|
||||
<a [routerLink]="['/album', album.Name]" [queryParams]="{tosort: true}">{{album.Name}}</a>
|
||||
<a [routerLink]="['/album', album.key]">{{album.key}}</a>
|
||||
</td>
|
||||
|
||||
<td>{{album['Track Count']}}</td>
|
||||
<td>{{albums[album.key]['Track Count']}}</td>
|
||||
|
||||
<ng-template [ngIf]="album['Album Artist']" [ngIfElse]="artistSection">
|
||||
<ng-template [ngIf]="albums[album.key]['Album Artist']" [ngIfElse]="artistSection">
|
||||
<td>
|
||||
<a [routerLink]="['/artist', album['Album Artist']]" [queryParams]="{tosort: true}">{{album['Album Artist']}}</a>
|
||||
<a [routerLink]="['/artist', albums[album.key]['Album Artist']]">{{albums[album.key]['Album Artist']}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #artistSection>
|
||||
<td>
|
||||
<a [routerLink]="['/artist', album.Artist[0]]">{{album.Artist}}</a>
|
||||
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
@@ -117,12 +115,12 @@
|
||||
</ng-template>
|
||||
|
||||
<td>
|
||||
{{album['Play Count']}} ({{album['Play Count']/album['Track Count'] | number:'1.0-0'}}/songs)
|
||||
{{albums[album.key]['Play Count']}} ({{albums[album.key]['Play Count']/albums[album.key]['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>
|
||||
<td class="star" [title]="(albums[album.key]['Album Rating Computed']?'Computed Rating: ':'Rating: ') + albums[album.key]['Album Rating']">
|
||||
<span *ngFor="let item of numberToArray(albums[album.key]['Album Rating'], 20)">
|
||||
<span class="glyphicon" [ngClass]="albums[album.key]['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ElsSortService } from '../els-service/els-sort.service';
|
||||
import { ElsSortService } from '../els-sort.service';
|
||||
import { Album } from '../model/album';
|
||||
import { Bucket } from '../model/bucket';
|
||||
import { Song } from '../model/song';
|
||||
|
||||
import { Utils } from '../utils';
|
||||
|
||||
@@ -16,7 +18,6 @@ export class ToSortComponent implements OnInit {
|
||||
totalSize = 0;
|
||||
trackCountSong = 0;
|
||||
neverListenSong = 0;
|
||||
nbAlbums = 0;
|
||||
|
||||
// Global var
|
||||
toSortAlbum: Bucket[] = [];
|
||||
@@ -30,9 +31,59 @@ export class ToSortComponent implements OnInit {
|
||||
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)
|
||||
// **** GET ALBUMS ****//
|
||||
const tmpToSortAlbums: Bucket[] = [];
|
||||
this.elsService.getAlbums().subscribe(buckets => {
|
||||
buckets.forEach(bucket => {
|
||||
if (tmpToSortAlbums.length === 0) {
|
||||
tmpToSortAlbums.push(bucket);
|
||||
} else {
|
||||
let found = false;
|
||||
tmpToSortAlbums.forEach(element => {
|
||||
if (element.key === bucket.key) {
|
||||
element.doc_count += bucket.doc_count;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (!found) {
|
||||
tmpToSortAlbums.push(bucket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.toSortAlbum = tmpToSortAlbums;
|
||||
this.toSortAlbum.forEach(bucket => this.getAlbum(bucket));
|
||||
// console.log(this.toSortAlbum)
|
||||
// console.log(this.albums)
|
||||
});
|
||||
}
|
||||
|
||||
private getAlbum(albumBucket: Bucket) {
|
||||
// For each bucket.key (album name), get Album document
|
||||
// Use track count to compare
|
||||
this.elsService.getArtistFromAlbumName(albumBucket.key).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) {
|
||||
goodAlbum = album;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Just one result for album name
|
||||
goodAlbum = albums[0];
|
||||
}
|
||||
|
||||
// TODO Crap security if no good album found
|
||||
if (goodAlbum == undefined) {
|
||||
goodAlbum = albums[0]
|
||||
}
|
||||
|
||||
this.albums[albumBucket.key] = goodAlbum;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
import { TsService } from '../ts-service/ts.service';
|
||||
import { ElsService } from '../els.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 tsService: TsService) { }
|
||||
constructor(private elsService: ElsService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.tsService.getMostPlayedAlbumNaive()
|
||||
this.elsService.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.tsService.getMostPlayedArtistNaive()
|
||||
this.elsService.getMostPlayedArtistNaive()
|
||||
.then(result => {
|
||||
this.mostPlayedArtistsNaive = result;
|
||||
|
||||
this.mostPlayedArtistsNaive.sort((a: any, b: any) => this.sortByAveragePlay(a, b)).splice(10);
|
||||
});
|
||||
|
||||
// this.tsService.getMostPlayedArtist().subscribe(result => {
|
||||
// result.forEach(artist => {
|
||||
// if (artist['Track Count'] > 10) {
|
||||
// this.mostPlayedArtists.push(artist);
|
||||
// }
|
||||
// });
|
||||
this.elsService.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) {
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
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"))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
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 + ")")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
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'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,456 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,16 @@ 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
|
||||
|
||||
@@ -7,10 +7,19 @@ import {
|
||||
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(), {
|
||||
teardown: { destroyAfterEach: false }
|
||||
}
|
||||
platformBrowserDynamicTesting()
|
||||
);
|
||||
// Then we find all the tests.
|
||||
const context = require.context('./', true, /\.spec\.ts$/);
|
||||
// And load the modules.
|
||||
context.keys().map(context);
|
||||
|
||||
@@ -10,13 +10,12 @@
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"target": "ES2022",
|
||||
"target": "es2015",
|
||||
"module": "es2020",
|
||||
"lib": [
|
||||
"es2018",
|
||||
"dom"
|
||||
],
|
||||
"useDefineForClassFields": false
|
||||
]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"strictTemplates": true
|
||||
|
||||
@@ -147,7 +147,8 @@ class ITunesParser:
|
||||
'Play Count': 0,
|
||||
'Rating': 0,
|
||||
'Genre': set(),
|
||||
'Album': set()
|
||||
'Album': set(),
|
||||
'Album Artist': set()
|
||||
}
|
||||
|
||||
# Compute information
|
||||
@@ -168,6 +169,9 @@ class ITunesParser:
|
||||
if 'Album' in track:
|
||||
self._artists[akey]['Album'].add(track['Album'])
|
||||
|
||||
if 'Album Artist' in track:
|
||||
self._artists[akey]['Album Artist'].add(track['Artist'])
|
||||
|
||||
def _process_album(self, track):
|
||||
"""
|
||||
Process albums in the track part of library and return a JSON formated for a bulk ELS request
|
||||
@@ -192,8 +196,7 @@ class ITunesParser:
|
||||
'Avg Bit Rate': track['Bit Rate'],
|
||||
'Min Bit Rate': track['Bit Rate'],
|
||||
# 'Album Artist': '',
|
||||
'Total Time': 0,
|
||||
'Location': ''
|
||||
'Total Time': 0
|
||||
}
|
||||
|
||||
# Compute information
|
||||
@@ -208,8 +211,6 @@ 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']
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
import base64
|
||||
import os
|
||||
from typing import List, Optional
|
||||
import requests
|
||||
import json
|
||||
import re
|
||||
|
||||
from urllib import parse
|
||||
|
||||
|
||||
TYPESENSE_URL = "http://localhost:8108"
|
||||
COLLECTION = "albums"
|
||||
HEADERS = {"X-TYPESENSE-API-KEY": "toto", "Content-Type": "application/json"}
|
||||
|
||||
def get_albums(offset = 0) -> List[tuple[str, str, str]]:
|
||||
params = {"q": "*", "per_page": 250, "offset": offset}
|
||||
q_url = f"{TYPESENSE_URL}/collections/{COLLECTION}/documents/search"
|
||||
# print(q_url)
|
||||
req = requests.get(q_url, params=params, headers=HEADERS)
|
||||
|
||||
ret = [ (hit['document']['id'], hit['document']['Album'], hit['document']['Artist']) for hit in req.json()['hits']]
|
||||
return ret
|
||||
|
||||
def get_album_location(id: int) -> str:
|
||||
q_url = f"{TYPESENSE_URL}/collections/{COLLECTION}/documents/{id}"
|
||||
# print(q_url)
|
||||
req = requests.get(q_url, headers=HEADERS)
|
||||
|
||||
if "Cover" in req.json():
|
||||
return
|
||||
|
||||
return req.json()["Location"]
|
||||
|
||||
|
||||
def patch_album(id: int, cover: bytes) -> bool:
|
||||
q_url = f"{TYPESENSE_URL}/collections/{COLLECTION}/documents/{id}"
|
||||
# print(q_url)
|
||||
payload = {"Cover": cover.decode()}
|
||||
payload = json.dumps(payload)
|
||||
req = requests.patch(q_url, headers=HEADERS, data=payload)
|
||||
|
||||
return req.status_code == 200
|
||||
|
||||
|
||||
def sanitize_location(location: str) -> Optional[str]:
|
||||
result = parse.unquote(location, encoding='utf-8', errors='replace')
|
||||
result = result.replace("file://localhost/", "")
|
||||
result = result.replace(":", "")
|
||||
result = re.sub("^([A-Z])", lambda m: m.group(0).lower(), result)
|
||||
result = result.replace("%20", " ")
|
||||
result = "/mnt/" + result
|
||||
result = re.sub('/Disc [0-9]*$', "", result)
|
||||
|
||||
for file in ["/Pochette.jpg", "/cover.jpg", "/Pochette.png"]:
|
||||
if os.path.isfile(result + file):
|
||||
result = result + file
|
||||
return result
|
||||
return None
|
||||
|
||||
|
||||
def get_base64(location: str) -> bytes:
|
||||
with open(location, "rb") as image_file:
|
||||
encoded_cover = base64.b64encode(image_file.read())
|
||||
return encoded_cover
|
||||
|
||||
def process_one_album(id: int) -> bool:
|
||||
raw_loc = get_album_location(id)
|
||||
if not raw_loc:
|
||||
return False
|
||||
loc = sanitize_location(raw_loc)
|
||||
if not loc:
|
||||
return False
|
||||
cover = get_base64(loc)
|
||||
if patch_album(id, cover):
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
# process_one_album(2151)
|
||||
elements = get_albums()
|
||||
processed = 0
|
||||
while len(elements) == 250:
|
||||
for id, name, artist in elements:
|
||||
processed += 1
|
||||
raw_loc = get_album_location(id)
|
||||
if not raw_loc:
|
||||
continue
|
||||
loc = sanitize_location(raw_loc)
|
||||
if not loc:
|
||||
continue
|
||||
print(f"Try {id} - {name} ({artist})")
|
||||
cover = get_base64(loc)
|
||||
if patch_album(id, cover):
|
||||
print(f"Album {id} - {name} ({artist}) patched successfully")
|
||||
elements = get_albums(offset = processed)
|
||||
@@ -1,28 +1,4 @@
|
||||
{
|
||||
"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": {
|
||||
@@ -45,19 +21,6 @@
|
||||
},
|
||||
"Genre": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"Location": {
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"tree": {
|
||||
"type": "text",
|
||||
"analyzer": "custom_path_tree"
|
||||
},
|
||||
"tree_reversed": {
|
||||
"type": "text",
|
||||
"analyzer": "custom_path_tree_reversed"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,556 +1,70 @@
|
||||
{
|
||||
"name": "songs",
|
||||
"token_separators": [":", "/", "."],
|
||||
"fields": [
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Album",
|
||||
"optional": true,
|
||||
"sort": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Album Rating",
|
||||
"optional": true,
|
||||
"sort": true,
|
||||
"type": "int64"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Album Rating Computed",
|
||||
"optional": true,
|
||||
"sort": true,
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Artist",
|
||||
"optional": true,
|
||||
"sort": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Artwork Count",
|
||||
"optional": true,
|
||||
"sort": true,
|
||||
"type": "int64"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Bit Rate",
|
||||
"optional": true,
|
||||
"sort": true,
|
||||
"type": "int64"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Date Added",
|
||||
"optional": true,
|
||||
"sort": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Date Modified",
|
||||
"optional": true,
|
||||
"sort": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "File Folder Count",
|
||||
"optional": true,
|
||||
"sort": true,
|
||||
"type": "int64"
|
||||
},
|
||||
{
|
||||
"facet": true,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Genre",
|
||||
"optional": true,
|
||||
"sort": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"facet": false,
|
||||
"index": true,
|
||||
"infix": false,
|
||||
"locale": "",
|
||||
"name": "Kind",
|
||||
"optional": true,
|
||||
"sort": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
"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": {
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"raw": {"type": "keyword"}
|
||||
}
|
||||
},
|
||||
"Album Artist": {
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"raw": {"type": "keyword"}
|
||||
}
|
||||
},
|
||||
"Album": {
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"raw": {"type": "keyword"}
|
||||
}
|
||||
},
|
||||
"Bit Rate": {
|
||||
"type": "integer"
|
||||
},
|
||||
"Genre": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"Kind": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"Location": {
|
||||
"type": "text",
|
||||
"fields": {
|
||||
"tree": {
|
||||
"type": "text",
|
||||
"analyzer": "custom_path_tree"
|
||||
},
|
||||
"tree_reversed": {
|
||||
"type": "text",
|
||||
"analyzer": "custom_path_tree_reversed"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
mapping.suggest.json
Normal file
48
mapping.suggest.json
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"settings": {
|
||||
"index": {
|
||||
"number_of_replicas": 0
|
||||
},
|
||||
"analysis": {
|
||||
"filter": {
|
||||
"french_stop": {
|
||||
"type": "stop",
|
||||
"stopwords": "_french_"
|
||||
},
|
||||
"english_stop": {
|
||||
"type": "stop",
|
||||
"stopwords": "_english_"
|
||||
}
|
||||
},
|
||||
"analyzer": {
|
||||
"names": {
|
||||
"tokenizer": "standard",
|
||||
"filter": [
|
||||
"lowercase",
|
||||
"asciifolding",
|
||||
"french_stop",
|
||||
"english_stop"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"artist_suggest": {
|
||||
"type": "completion",
|
||||
"search_analyzer": "names"
|
||||
},
|
||||
"artist": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"album_suggest": {
|
||||
"type": "completion",
|
||||
"search_analyzer": "names"
|
||||
},
|
||||
"album": {
|
||||
"type": "keyword"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
send_data.py
30
send_data.py
@@ -10,6 +10,8 @@ import json
|
||||
import time
|
||||
import requests
|
||||
|
||||
from suggester import process_file
|
||||
|
||||
class bcolors:
|
||||
HEADER = '\033[95m'
|
||||
OKBLUE = '\033[94m'
|
||||
@@ -28,10 +30,12 @@ DEFAULT_ARTIST_FILE = 'es-artists.json'
|
||||
DEFAULT_MAPPING_SONGS_FILE = 'mapping.songs.json'
|
||||
DEFAULT_MAPPING_ARTISTS_FILE = 'mapping.artists.json'
|
||||
DEFAULT_MAPPING_ALBUMS_FILE = 'mapping.albums.json'
|
||||
DEFAULT_MAPPING_SUGGEST_FILE = 'mapping.suggest.json'
|
||||
|
||||
SONG_INDEX = 'itunes-songs'
|
||||
ALBUM_INDEX = 'itunes-albums'
|
||||
ARTIST_INDEX = 'itunes-artists'
|
||||
SUGGEST_INDEX = 'itunes-suggest'
|
||||
# TODO Put variables in a config files or in a python library
|
||||
|
||||
# Global values / set as default values
|
||||
@@ -145,6 +149,22 @@ def main():
|
||||
else:
|
||||
print('Album sent')
|
||||
|
||||
if args.ALL or args.no_suggest:
|
||||
print("Process suggestion:")
|
||||
if args.DELETE: # TODO Do a method?
|
||||
mapping_suggest = load_file(args.mapping_suggest, DEFAULT_MAPPING_SUGGEST_FILE)
|
||||
if not args.quiet:
|
||||
print("Mapping of suggest index file: '{}'".format(mapping_suggest.name))
|
||||
|
||||
delete_index(SUGGEST_INDEX, args.quiet)
|
||||
put_mapping(SUGGEST_INDEX, mapping_suggest, args.quiet)
|
||||
|
||||
suggs_docs = 0
|
||||
suggs_docs += process_file('/home/budd/workspace/iTunes/es-albums.json', 'Album')
|
||||
print('Created documents: ' + str(suggs_docs))
|
||||
suggs_docs += process_file('/home/budd/workspace/iTunes/es-artists.json', 'Artist', 'Album Artist')
|
||||
print('Created documents: ' + str(suggs_docs))
|
||||
|
||||
print("I'm done!")
|
||||
if check_is_ok.count(False) > 0:
|
||||
print('Some problems occurs')
|
||||
@@ -199,6 +219,8 @@ def create_args_parser():
|
||||
.format(DEFAULT_ARTIST_FILE))
|
||||
song_group.add_argument('-s', '--song', action='store_false',
|
||||
help='Disable sending song data')
|
||||
song_group.add_argument('--no-suggest', action='store_false',
|
||||
help='Disable sending suggest data')
|
||||
|
||||
# Mode
|
||||
mode_group = parser.add_argument_group('Mode')
|
||||
@@ -211,12 +233,14 @@ def create_args_parser():
|
||||
|
||||
# Mapping
|
||||
mapping_group = parser.add_argument_group('Mapping files')
|
||||
mode_group.add_argument('-ms', '--mapping-song', type=argparse.FileType('r'), const=DEFAULT_MAPPING_SONGS_FILE, nargs='?',
|
||||
mapping_group.add_argument('-ms', '--mapping-song', type=argparse.FileType('r'), const=DEFAULT_MAPPING_SONGS_FILE, nargs='?',
|
||||
help='Mapping file for songs (default: \'{}\')'.format(DEFAULT_MAPPING_SONGS_FILE))
|
||||
mode_group.add_argument('-mr', '--mapping-artist', type=argparse.FileType('r'), const=DEFAULT_ARTIST_FILE, nargs='?',
|
||||
mapping_group.add_argument('-mr', '--mapping-artist', type=argparse.FileType('r'), const=DEFAULT_ARTIST_FILE, nargs='?',
|
||||
help='Mapping file for artists (default: \'{}\')'.format(DEFAULT_MAPPING_ARTISTS_FILE))
|
||||
mode_group.add_argument('-ml', '--mapping-album', type=argparse.FileType('r'), const=DEFAULT_MAPPING_ALBUMS_FILE, nargs='?',
|
||||
mapping_group.add_argument('-ml', '--mapping-album', type=argparse.FileType('r'), const=DEFAULT_MAPPING_ALBUMS_FILE, nargs='?',
|
||||
help='Mapping file for albums (default: \'{}\')'.format(DEFAULT_MAPPING_ALBUMS_FILE))
|
||||
mapping_group.add_argument('-mg', '--mapping-suggest', type=argparse.FileType('r'), const=DEFAULT_MAPPING_SUGGEST_FILE, nargs='?',
|
||||
help='Mapping file for suggest (default: \'{}\')'.format(DEFAULT_MAPPING_SUGGEST_FILE))
|
||||
|
||||
# Global Settings
|
||||
g_settings_group = parser.add_argument_group('Global Settings')
|
||||
|
||||
56
suggester.es
56
suggester.es
@@ -1,51 +1,7 @@
|
||||
DELETE itunes-suggest
|
||||
|
||||
PUT /itunes-suggest
|
||||
{
|
||||
"settings": {
|
||||
"analysis": {
|
||||
"filter": {
|
||||
"french_stop": {
|
||||
"type": "stop",
|
||||
"stopwords": "_french_"
|
||||
},
|
||||
"english_stop": {
|
||||
"type": "stop",
|
||||
"stopwords": "_english_"
|
||||
}
|
||||
},
|
||||
"analyzer": {
|
||||
"names": {
|
||||
"tokenizer": "standard",
|
||||
"filter": [
|
||||
"lowercase",
|
||||
"asciifolding",
|
||||
"french_stop",
|
||||
"english_stop"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"artist_suggest": {
|
||||
"type": "completion",
|
||||
"search_analyzer": "names"
|
||||
},
|
||||
"artist": {
|
||||
"type": "keyword"
|
||||
},
|
||||
"album_suggest": {
|
||||
"type": "completion",
|
||||
"search_analyzer": "names"
|
||||
},
|
||||
"album": {
|
||||
"type": "keyword"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
!./mapping.suggest.json
|
||||
|
||||
// Also possible to specify analyze for ingesting => https://stackoverflow.com/questions/48304499/elasticsearch-completion-suggester-not-working-with-whitespace-analyzer
|
||||
|
||||
@@ -59,7 +15,7 @@ GET itunes-suggest/_analyze
|
||||
|
||||
GET itunes-suggest/_search
|
||||
|
||||
POST itunes-suggest/_search
|
||||
GET itunes-suggest/_search
|
||||
{
|
||||
"_source" : "artist",
|
||||
"suggest": {
|
||||
@@ -72,7 +28,7 @@ POST itunes-suggest/_search
|
||||
}
|
||||
}
|
||||
|
||||
POST itunes-suggest/_search
|
||||
GET itunes-suggest/_search
|
||||
{
|
||||
"_source" : "album",
|
||||
"suggest": {
|
||||
@@ -86,7 +42,7 @@ POST itunes-suggest/_search
|
||||
}
|
||||
}
|
||||
|
||||
POST itunes-suggest/_search
|
||||
GET itunes-suggest/_search
|
||||
{
|
||||
"_source": ["album", "artist"],
|
||||
"suggest": {
|
||||
@@ -105,7 +61,7 @@ POST itunes-suggest/_search
|
||||
}
|
||||
}
|
||||
|
||||
POST itunes-suggest/_search
|
||||
GET itunes-suggest/_search
|
||||
{
|
||||
"_source": ["album", "artist"],
|
||||
"suggest": {
|
||||
@@ -124,7 +80,7 @@ POST itunes-suggest/_search
|
||||
}
|
||||
}
|
||||
|
||||
POST itunes-suggest/_search
|
||||
GET itunes-suggest/_search
|
||||
{
|
||||
"suggest": {
|
||||
"ar-suggest": {
|
||||
|
||||
115
suggester.py
115
suggester.py
@@ -1,37 +1,77 @@
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
"""
|
||||
Process files generated by iTunesParser to fill a suggester index.
|
||||
Suggester index in ELS must be created before use.
|
||||
|
||||
ELS_URL ='http://localhost:9200'
|
||||
Found suggester.es query to create index.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
ELS_URL = 'http://localhost:9200'
|
||||
INDEX = 'itunes-suggest'
|
||||
|
||||
class NoGoodDataException(Exception):
|
||||
def __init__(self, message):
|
||||
super().__init__(message)
|
||||
""" Raise when data can't be correctly analyzed """
|
||||
|
||||
def get_tokens(data: str) -> list:
|
||||
"""
|
||||
Query Elasticsearch to get token for a string with a specific analyzer.
|
||||
Throw an exception if no token found in ELS response.
|
||||
Parameters
|
||||
----------
|
||||
data: string
|
||||
String to be analysed to obtain the tokens
|
||||
Returns
|
||||
-------
|
||||
list
|
||||
A list of token
|
||||
Raises
|
||||
------
|
||||
NoGoodDataException
|
||||
If no tokens are found in the ELS responses, consider that the data is not correct for analysis.
|
||||
"""
|
||||
if not data:
|
||||
return []
|
||||
query = {
|
||||
"analyzer": "names",
|
||||
"analyzer": "names", # TODO Parameterize analyzer ?
|
||||
"text" : data
|
||||
}
|
||||
|
||||
url = '{}/{}/_analyze'.format(ELS_URL, INDEX)
|
||||
r = requests.get(url, json=query)
|
||||
req = requests.get(url, json=query)
|
||||
|
||||
if not 'tokens' in r.json():
|
||||
if not 'tokens' in req.json():
|
||||
print('ERROR: Not tokens in result')
|
||||
print('Input: ' + str(data))
|
||||
print('Request: ' + str(r.json()))
|
||||
print('Request: ' + str(req.json()))
|
||||
raise NoGoodDataException('Data is not correct to get tokens')
|
||||
return [t['token'] for t in r.json()['tokens']]
|
||||
return [t['token'] for t in req.json()['tokens']]
|
||||
|
||||
def post_document(name: str, input: list, field_name: str) -> bool:
|
||||
suggest_name = field_name + '_suggest'
|
||||
def post_document(main_field_value: str, input_terms: list, main_field_name: str) -> str:
|
||||
"""
|
||||
Create suggestion document in Elasticsearch.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
main_field_value : str
|
||||
Value to put in the main field named by `main_field_name`
|
||||
input_terms : list
|
||||
List of suggestion term to put in document
|
||||
main_field_name : str
|
||||
Name of the main field, to fill with `main_field_value`
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Success: ID of created document
|
||||
Fail (ret. status <> 201): None
|
||||
"""
|
||||
suggest_name = main_field_name + '_suggest'
|
||||
element = {
|
||||
field_name: name,
|
||||
suggest_name: input
|
||||
main_field_name: main_field_value,
|
||||
suggest_name: input_terms
|
||||
}
|
||||
|
||||
# Filter empty keys
|
||||
@@ -43,16 +83,29 @@ def post_document(name: str, input: list, field_name: str) -> bool:
|
||||
print('ELS Response KO')
|
||||
print(resp.status_code)
|
||||
print(resp.text)
|
||||
return
|
||||
return None
|
||||
|
||||
el_id = resp.json()['_id']
|
||||
# print('Post_element - Element created: ' + el_id)
|
||||
return el_id
|
||||
|
||||
def process_file(file_name: str, field_name: str) -> int:
|
||||
def process_file(file_name: str, field_name: str, array_file: str = None) -> int:
|
||||
"""
|
||||
Process a JSON file with data
|
||||
|
||||
Parameters
|
||||
----------
|
||||
file_name: string
|
||||
Path and name of file to analyze
|
||||
field_name: string
|
||||
Name of the field where to find the data to create the suggestion entries
|
||||
array_file: string, Default: None
|
||||
Name of an array field to analyze to create more suggestion entries.
|
||||
Nothing if None
|
||||
"""
|
||||
print('Process file: ' + file_name)
|
||||
with open(file_name, 'r') as o_file:
|
||||
lines = o_file.readlines()
|
||||
lines = o_file.readlines()
|
||||
|
||||
count = 0
|
||||
i = 0
|
||||
@@ -62,22 +115,28 @@ def process_file(file_name: str, field_name: str) -> int:
|
||||
sys.stdout.flush()
|
||||
sys.stdout.write("\b" * (40+1)) # return to start of line, after '['
|
||||
data = json.loads(line)
|
||||
if "Artist" in data:
|
||||
try :
|
||||
input = get_tokens(data[field_name])
|
||||
post_document(name=data[field_name], input=input, field_name=field_name.lower())
|
||||
if not "index" in data: # Exclude index line
|
||||
try:
|
||||
suggests_entries = get_tokens(data[field_name])
|
||||
|
||||
if array_file and array_file in data and data[array_file]:
|
||||
for key in data[array_file]:
|
||||
suggests_entries.extend(get_tokens(key))
|
||||
|
||||
# TODO Input have the same value several times ==> use to process a score
|
||||
post_document(main_field_value=data[field_name], input_terms=suggests_entries, main_field_name=field_name.lower())
|
||||
count += 1
|
||||
except NoGoodDataException:
|
||||
print('ERROR WITH DATA')
|
||||
print(str(data))
|
||||
print('File processed\n')
|
||||
|
||||
return count
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Using readlines()
|
||||
count = 0
|
||||
count += process_file('/home/budd/workspace/iTunes/es-albums.json', 'Album')
|
||||
count += process_file('/home/budd/workspace/iTunes/es-artists.json', 'Artist')
|
||||
print('Created documents: ' + str(count))
|
||||
created_docs = 0
|
||||
created_docs += process_file('/home/budd/workspace/iTunes/es-albums.json', 'Album')
|
||||
print('Created documents: ' + str(created_docs))
|
||||
created_docs += process_file('/home/budd/workspace/iTunes/es-artists.json', 'Artist', 'Album Artist')
|
||||
print('Created documents: ' + str(created_docs))
|
||||
# TODO Created doc <> nb doc in ELS
|
||||
|
||||
Reference in New Issue
Block a user