Skip to content

Commit

Permalink
Add removal text pattern from tracks name in scrobbling operations
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Jul 1, 2024
1 parent 79eaf62 commit b24ad47
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"scrobbleSelected": "Scrobble selected",
"findAlbumCopy": "Enter an album or artist name",
"customTimestamp": "Custom timestamp",
"albumTimestampLogicDescription": "Scrobbling tracks \"now\" will scrobble the last track at the current time, backdating the previous ones accordingly (as if you had just finished listening). The \"custom timestamp\" will define the timestamp of the first track and add time to the following tracks from there (i.e. you specify the time you started listening to this album)",
"albumTimestampLogicDescription": "Scrobbling tracks \"now\" will scrobble the last track at the current time, backdating the previous ones accordingly (as if you had just finished listening). The \"custom timestamp\" will define the timestamp of the first track and add time to the following tracks from there (i.e. you specify the time you started listening to this album).",
"albumArtist": "Album artist",
"albumRemovalPattern": "Removable text pattern from every track name",
"albumRemovalPatternDescription": "Some albums tracks are displayed with some repeated text (i.e. Demo, Live, Remastered, ...). These are patterns that could be considered annoying to scrobble, for some users. Set the full pattern (including paranthesis, dashes, ...) that you would like to be removed, from the track names.",
"history": "History",
"yourProfile": "Your profile",
"yourHistory": "Your history",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"customTimestamp": "Timestamp personalizzato",
"albumTimestampLogicDescription": "Scrobblando le canzoni \"adesso\" scrobblerà l'ultima canzone in questo momento, anticipando relativamente le precedenti (come se avessi appena finito di ascoltarle). Il \"timestamp personalizzato\" definirà il timestamp di ascolto della prima traccia ed agginguerà il relativo tempo alle canzoni successive (come se avessi iniziato ad ascoltare l'album nel timestamp selezionato)",
"albumArtist": "Artista di un Album",
"albumRemovalPattern": "Pattern removibile da ogni nome di canzone",
"albumRemovalPatternDescription": "Alcune canzoni di album sono visualizzate con un certo testo ripetuto (ad esempio Demo, Live, Remastered, ...). Questi sono pattern che potrebbero risultare fastidiosi da scrobblare, per alcuni utenti. Imposta il pattern completo (incluse parentesi, trattini, ...) che desideri venga rimosso dai nomi delle canzoni.",
"history": "Storico",
"yourProfile": "Tuo profilo",
"yourHistory": "Tuo storico",
Expand Down
3 changes: 3 additions & 0 deletions src/components/ScrobbleItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useSettings } from 'hooks/useSettings';

interface ScrobbleItemProps {
scrobble: Scrobble;
scrobbleRemovalPattern?: string;
compact?: boolean;
hideArtist?: boolean;
muteArtist?: boolean;
Expand All @@ -48,6 +49,7 @@ interface ScrobbleItemProps {

export default function ScrobbleItem({
scrobble,
scrobbleRemovalPattern = '',
compact = false,
hideArtist = false,
muteArtist = false,
Expand Down Expand Up @@ -86,6 +88,7 @@ export default function ScrobbleItem({
enqueueScrobble(dispatch)([
{
...scrobble,
title: scrobbleRemovalPattern !== '' ? scrobble.title.replaceAll(scrobbleRemovalPattern, '').trim() : scrobble.title,
timestamp: useOriginalTimestamp ? scrobble.timestamp : new Date(),
},
]);
Expand Down
3 changes: 3 additions & 0 deletions src/components/ScrobbleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface ScrobbleListProps {
onSelect?: (scrobble: any) => void;
selected?: Set<string>;
scrobbles?: any[];
scrobblesRemovalPattern?: string;
}

export default function ScrobbleList({
Expand All @@ -28,6 +29,7 @@ export default function ScrobbleList({
onSelect,
selected,
scrobbles = [],
scrobblesRemovalPattern,
}: ScrobbleListProps) {
const { cloneFn, setCloneFn } = useContext(ScrobbleCloneContext);
let albumHasVariousArtists = !isAlbum;
Expand All @@ -52,6 +54,7 @@ export default function ScrobbleList({
return (
<ScrobbleItem
scrobble={scrobble}
scrobbleRemovalPattern={scrobblesRemovalPattern}
analyticsEvent={analyticsEventForScrobbles}
cloneScrobbleTo={setCloneFn ? cloneFn : undefined}
compact={compact}
Expand Down
47 changes: 47 additions & 0 deletions src/domains/scrobbleAlbum/partials/Tracklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ export default function Tracklist({ albumInfo, tracks }: { albumInfo: Album | nu
const { t } = useTranslation();

const [showTimestampCopy, setShowTimestampCopy] = useState(false);
const [showRemovalPatternCopy, setShowRemovalPatternCopy] = useState(false);
const amznLink = useMemo<string>(() => getAmznLink(albumInfo?.artist, albumInfo?.name), [albumInfo]);
const [canScrobble, setCanScrobble] = useState(true);
// ToDo: simplify customTimestamp + useCustomTimestamp
const [customTimestamp, setCustomTimestamp] = useState(new Date());
const [useCustomTimestamp, setUseCustomTimestamp] = useState(false);
const [useRemovalPattern, setUseRemovalPattern] = useState('');
const [selectedTracks, setSelectedTracks] = useState<Set<string>>(new Set());
const [totalDuration, setTotalDuration] = useState(0);
const albumHasTracks = tracks && tracks.length > 0;
Expand Down Expand Up @@ -89,11 +91,19 @@ export default function Tracklist({ albumInfo, tracks }: { albumInfo: Album | nu
setSelectedTracks(newSet);
};

const toggleRemovalPatternCopy = () => {
setShowRemovalPatternCopy(!showRemovalPatternCopy);
};

const handleTimestampChange = (newTimestamp) => {
setCustomTimestamp(newTimestamp);
setCanScrobble(true);
};

const handleRemovalPatternChange = (event) => {
setUseRemovalPattern(event.target.value);
};

const scrobbleSelectedTracks = () => {
const userHasNotSelectedTracks = selectedTracks.size < 1;
const timestampCalculationSubstractsTime = !useCustomTimestamp;
Expand All @@ -112,6 +122,7 @@ export default function Tracklist({ albumInfo, tracks }: { albumInfo: Album | nu
.reduce((result, track) => {
const newTrack = {
...track,
title: useRemovalPattern !== '' ? track.title.replaceAll(useRemovalPattern, '').trim() : track.title,
album: albumInfo?.name || '',
albumArtist: albumInfo?.artist || '',
timestamp: rollingTimestamp,
Expand Down Expand Up @@ -247,11 +258,47 @@ export default function Tracklist({ albumInfo, tracks }: { albumInfo: Album | nu
noMenu
analyticsEventForScrobbles="Scrobble individual album song"
scrobbles={tracks || []}
scrobblesRemovalPattern={useRemovalPattern}
onSelect={toggleSelectedTrack}
selected={selectedTracks}
>
<EmptyDiscMessage />
</ScrobbleList>

<div className="d-flex flex-column mt-4 album-removal-pattern">
<FormGroup>
<div className="col-12">
<label htmlFor="albumRemovalPattern" className="mb-2">
<Trans i18nKey="albumRemovalPattern" />:
</label>
<FontAwesomeIcon
id="removalPatternInfoIcon"
className="px-3"
icon={faQuestionCircle}
color="var(--bs-gray)"
onClick={toggleRemovalPatternCopy}
/>
</div>
<div className="col-6">
<Input
className="form-control-sm form-control"
id="albumRemovalPattern"
onChange={handleRemovalPatternChange}
/>
</div>
<div className="col-12">
<Alert
color="dark"
isOpen={showRemovalPatternCopy}
toggle={toggleRemovalPatternCopy}
className="text-justify mt-3"
fade={false}
>
<Trans i18nKey="albumRemovalPatternDescription" />
</Alert>
</div>
</FormGroup>
</div>
</>
);
}

0 comments on commit b24ad47

Please sign in to comment.