-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cover-art): Download 500x500 cover art for tracks by default.
Also reduced the timeout for cover art download to 20s.
- Loading branch information
Showing
5 changed files
with
132 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
import {ID3MetadataService} from '@src/download/metadata/id3-metadata-service'; | ||
import {ITrackMetadata} from '@src/download/metadata/track-metadata'; | ||
import {TrackMetadataFactory} from '@src/download/metadata/track-metadata-factory'; | ||
import {ITrackDownloadInfo} from '@src/download/track-download-info'; | ||
import {XhrService} from '@src/util/xhr-service'; | ||
import {Observable, of} from 'rxjs'; | ||
import {flatMap, map} from 'rxjs/operators'; | ||
|
||
export const MetadataAdapter = { | ||
addMetadata$(downloadInfo: ITrackDownloadInfo): Observable<ITrackDownloadInfo> { | ||
switch (downloadInfo.downloadOptions.filename.split('.').pop()) { | ||
const fileExtension = downloadInfo.downloadOptions.filename.split('.').pop(); | ||
const metadata$ = of(TrackMetadataFactory.create(downloadInfo.trackInfo)).pipe( | ||
flatMap(withUpdatedCoverArtUrl$) | ||
); | ||
|
||
switch (fileExtension) { | ||
case 'mp3': | ||
const metadata = TrackMetadataFactory.create(downloadInfo.trackInfo); | ||
return ID3MetadataService.addID3V2Metadata$(metadata, downloadInfo); | ||
return metadata$.pipe( | ||
flatMap((metadata: ITrackMetadata) => ID3MetadataService.addID3V2Metadata$(metadata, downloadInfo)) | ||
); | ||
default: | ||
return of(downloadInfo); | ||
} | ||
} | ||
}; | ||
|
||
function withUpdatedCoverArtUrl$(metadata: ITrackMetadata): Observable<ITrackMetadata> { | ||
const origUrl = metadata.cover_url; | ||
const highResUrl = getCoverArtUrlForResolution(origUrl, 500); | ||
return XhrService.ping$(highResUrl).pipe( | ||
map((status: number) => (status === 200) ? highResUrl : origUrl), | ||
map((url: string) => ({...metadata, cover_url: url})) | ||
); | ||
} | ||
|
||
function getCoverArtUrlForResolution(url: string, resolution: number): string { | ||
return url.replace(/^(.*)-large(\..*)$/, `$1-t${resolution}x${resolution}$2`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters