Package: DefaultCddbMetadataProvider
DefaultCddbMetadataProvider
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultCddbMetadataProvider() |
|
|
|
|
|
||||||||||||||||||||
findCddbAlbum(MediaItem.Metadata) |
|
|
|
|
|
||||||||||||||||||||
findCddbAlbum(MediaItem.Metadata.Cddb) |
|
|
|
|
|
||||||||||||||||||||
getHost() |
|
|
|
|
|
||||||||||||||||||||
setHost(String) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.metadata.cddb.impl;
28:
29: import javax.annotation.Nonnull;
30: import java.io.IOException;
31: import org.springframework.http.ResponseEntity;
32: import it.tidalwave.bluemarine2.model.MediaItem.Metadata;
33: import it.tidalwave.bluemarine2.metadata.cddb.CddbAlbum;
34: import it.tidalwave.bluemarine2.metadata.cddb.CddbMetadataProvider;
35: import it.tidalwave.bluemarine2.rest.CachingRestClientSupport;
36: import it.tidalwave.bluemarine2.rest.RestResponse;
37: import lombok.Getter;
38: import lombok.Setter;
39: import lombok.extern.slf4j.Slf4j;
40: import static it.tidalwave.util.FunctionalCheckedExceptionWrappers.*;
41: import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.*;
42:
43: /***********************************************************************************************************************
44: *
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @Slf4j
49: public class DefaultCddbMetadataProvider extends CachingRestClientSupport implements CddbMetadataProvider
50: {
51: private static final String FREEDB_URL_TEMPLATE = "http://%s/~cddb/cddb.cgi?cmd=cddb read rock %s&proto=6";
52:
53: @Getter @Setter
54: private String host = "freedb.musicbrainz.org";
55:
56: /*******************************************************************************************************************
57: *
58: * {@inheritDoc}
59: *
60: ******************************************************************************************************************/
61: @Override @Nonnull
62: public RestResponse<CddbAlbum> findCddbAlbum (@Nonnull final Metadata metadata)
63: throws IOException, InterruptedException
64: {
65: return metadata.get(CDDB).map(_f(this::findCddbAlbum)).orElse(CddbResponse.empty());
66: }
67:
68: /*******************************************************************************************************************
69: *
70: ******************************************************************************************************************/
71: @Nonnull
72: private RestResponse<CddbAlbum> findCddbAlbum (@Nonnull final Cddb cddb)
73: throws IOException, InterruptedException
74: {
75: final String discId = cddb.getDiscId();
76: final ResponseEntity<String> response = request(String.format(FREEDB_URL_TEMPLATE, host, discId));
77: return CddbResponse.of(response, CddbAlbum::of);
78: }
79: }