Skip to content

Commit 6f29d78

Browse files
authored
Spotify module support (#308)
1 parent b7ccd47 commit 6f29d78

File tree

14 files changed

+411
-0
lines changed

14 files changed

+411
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.Channel;
4+
import com.apptasticsoftware.rssreader.module.itunes.ItunesChannel;
5+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssChannel;
6+
import com.apptasticsoftware.rssreader.module.psc.PscChannel;
7+
8+
public interface SpotifyChannel extends Channel, SpotifyChannelData, ItunesChannel, MediaRssChannel, PscChannel {
9+
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
public interface SpotifyChannelData {
7+
8+
SpotifyChannelData getSpotifyChannelData();
9+
10+
default Optional<Integer> getSpotifyLimitRecentCount() {
11+
return getSpotifyChannelData().getSpotifyLimitRecentCount();
12+
}
13+
14+
default void setSpotifyLimitRecentCount(Integer spotifyLimitRecentCount) {
15+
getSpotifyChannelData().setSpotifyLimitRecentCount(spotifyLimitRecentCount);
16+
}
17+
18+
default Optional<String> getSpotifyCountryOfOrigin() {
19+
return getSpotifyChannelData().getSpotifyCountryOfOrigin();
20+
}
21+
22+
default List<String> getSpotifyCountryOfOriginAsList() {
23+
return getSpotifyChannelData().getSpotifyCountryOfOriginAsList();
24+
}
25+
26+
default void setSpotifyCountryOfOrigin(String spotifyCountryOfOrigin) {
27+
getSpotifyChannelData().setSpotifyCountryOfOrigin(spotifyCountryOfOrigin);
28+
}
29+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.util.Util;
4+
5+
import java.util.*;
6+
7+
public class SpotifyChannelDataImpl implements SpotifyChannelData {
8+
private Integer spotifyLimitRecentCount;
9+
private String spotifyCountryOfOrigin;
10+
11+
@Override
12+
public SpotifyChannelData getSpotifyChannelData() {
13+
return this;
14+
}
15+
16+
@Override
17+
public Optional<Integer> getSpotifyLimitRecentCount() {
18+
return Optional.ofNullable(spotifyLimitRecentCount);
19+
}
20+
21+
@Override
22+
public void setSpotifyLimitRecentCount(Integer spotifyLimitRecentCount) {
23+
this.spotifyLimitRecentCount = spotifyLimitRecentCount;
24+
}
25+
26+
@Override
27+
public Optional<String> getSpotifyCountryOfOrigin() {
28+
return Optional.ofNullable(spotifyCountryOfOrigin);
29+
}
30+
31+
@Override
32+
public List<String> getSpotifyCountryOfOriginAsList() {
33+
if (Util.isBlank(spotifyCountryOfOrigin)) {
34+
return Collections.emptyList();
35+
}
36+
return Arrays.asList(spotifyCountryOfOrigin.trim().split("\\s+"));
37+
}
38+
39+
@Override
40+
public void setSpotifyCountryOfOrigin(String spotifyCountryOfOrigin) {
41+
this.spotifyCountryOfOrigin = spotifyCountryOfOrigin;
42+
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (o == null || getClass() != o.getClass()) return false;
47+
SpotifyChannelDataImpl that = (SpotifyChannelDataImpl) o;
48+
return Objects.equals(getSpotifyLimitRecentCount(), that.getSpotifyLimitRecentCount()) && Objects.equals(getSpotifyCountryOfOrigin(), that.getSpotifyCountryOfOrigin());
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hash(getSpotifyLimitRecentCount(), getSpotifyCountryOfOrigin());
54+
}
55+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.ChannelImpl;
4+
import com.apptasticsoftware.rssreader.DateTimeParser;
5+
import com.apptasticsoftware.rssreader.module.itunes.ItunesChannelData;
6+
import com.apptasticsoftware.rssreader.module.itunes.ItunesChannelDataImpl;
7+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssChannelData;
8+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssChannelDataImpl;
9+
10+
import java.util.Objects;
11+
12+
public class SpotifyChannelImpl extends ChannelImpl implements SpotifyChannel {
13+
private final SpotifyChannelData spotifyData = new SpotifyChannelDataImpl();
14+
private final ItunesChannelData itunesData = new ItunesChannelDataImpl();
15+
private final MediaRssChannelData mediaRssData = new MediaRssChannelDataImpl();
16+
17+
public SpotifyChannelImpl(DateTimeParser dateTimeParser) {
18+
super(dateTimeParser);
19+
}
20+
21+
@Override
22+
public SpotifyChannelData getSpotifyChannelData() {
23+
return spotifyData;
24+
}
25+
26+
@Override
27+
public ItunesChannelData getItunesChannelData() {
28+
return itunesData;
29+
}
30+
31+
@Override
32+
public MediaRssChannelData getMediaRssChannelData() {
33+
return mediaRssData;
34+
}
35+
36+
@Override
37+
public boolean equals(Object o) {
38+
if (o == null || getClass() != o.getClass()) return false;
39+
if (!super.equals(o)) return false;
40+
SpotifyChannelImpl that = (SpotifyChannelImpl) o;
41+
return Objects.equals(getSpotifyChannelData(), that.getSpotifyChannelData()) && Objects.equals(getItunesChannelData(), that.getItunesChannelData()) && Objects.equals(getMediaRssChannelData(), that.getMediaRssChannelData());
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
return Objects.hash(super.hashCode(), getSpotifyChannelData(), getItunesChannelData(), getMediaRssChannelData());
47+
}
48+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.FeedExtensionRegistry;
4+
5+
import static com.apptasticsoftware.rssreader.util.Mapper.mapInteger;
6+
7+
public class SpotifyExtensions {
8+
9+
private SpotifyExtensions() {
10+
11+
}
12+
13+
public static void register(FeedExtensionRegistry<? extends SpotifyChannel, ? extends SpotifyItem> registry) {
14+
channelTagExtensions(registry);
15+
channelAttributeExtensions(registry);
16+
}
17+
18+
private static void channelTagExtensions(FeedExtensionRegistry<? extends SpotifyChannel, ? extends SpotifyItem> registry) {
19+
registry.addChannelExtension("spotify:countryOfOrigin", SpotifyChannelData::setSpotifyCountryOfOrigin);
20+
}
21+
22+
private static void channelAttributeExtensions(FeedExtensionRegistry<? extends SpotifyChannel, ? extends SpotifyItem> registry) {
23+
registry.addChannelExtension("spotify:limit", "recentCount", (c, v) -> mapInteger(v, c::setSpotifyLimitRecentCount));
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.Item;
4+
import com.apptasticsoftware.rssreader.module.itunes.ItunesItem;
5+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssItem;
6+
import com.apptasticsoftware.rssreader.module.psc.PscItem;
7+
8+
public interface SpotifyItem extends Item, SpotifyItemData, ItunesItem, MediaRssItem, PscItem {
9+
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
public interface SpotifyItemData {
4+
5+
SpotifyItemData getSpotifyItemData();
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
public class SpotifyItemDataImpl implements SpotifyItemData {
4+
5+
@Override
6+
public SpotifyItemData getSpotifyItemData() {
7+
return this;
8+
}
9+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.DateTimeParser;
4+
import com.apptasticsoftware.rssreader.ItemImpl;
5+
import com.apptasticsoftware.rssreader.module.itunes.ItunesItemData;
6+
import com.apptasticsoftware.rssreader.module.itunes.ItunesItemDataImpl;
7+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssItemData;
8+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssItemDataImpl;
9+
import com.apptasticsoftware.rssreader.module.psc.PscItemData;
10+
import com.apptasticsoftware.rssreader.module.psc.PscItemDataImpl;
11+
12+
import java.util.Objects;
13+
14+
public class SpotifyItemImpl extends ItemImpl implements SpotifyItem {
15+
private final SpotifyItemData spotifyData = new SpotifyItemDataImpl();
16+
private final ItunesItemData itunesData = new ItunesItemDataImpl();
17+
private final MediaRssItemData mediaRssData = new MediaRssItemDataImpl();
18+
private final PscItemData pscData = new PscItemDataImpl();
19+
20+
public SpotifyItemImpl(DateTimeParser dateTimeParser) {
21+
super(dateTimeParser);
22+
}
23+
24+
@Override
25+
public SpotifyItemData getSpotifyItemData() {
26+
return spotifyData;
27+
}
28+
29+
@Override
30+
public ItunesItemData getItunesItemData() {
31+
return itunesData;
32+
}
33+
34+
@Override
35+
public MediaRssItemData getMediaRssItemData() {
36+
return mediaRssData;
37+
}
38+
39+
@Override
40+
public PscItemData getPscItemData() {
41+
return pscData;
42+
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (o == null || getClass() != o.getClass()) return false;
47+
if (!super.equals(o)) return false;
48+
SpotifyItemImpl that = (SpotifyItemImpl) o;
49+
return Objects.equals(getSpotifyItemData(), that.getSpotifyItemData()) && Objects.equals(getItunesItemData(), that.getItunesItemData()) && Objects.equals(getMediaRssItemData(), that.getMediaRssItemData()) && Objects.equals(getPscItemData(), that.getPscItemData());
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
return Objects.hash(super.hashCode(), getSpotifyItemData(), getItunesItemData(), getMediaRssItemData(), getPscItemData());
55+
}
56+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.apptasticsoftware.rssreader.module.spotify;
2+
3+
import com.apptasticsoftware.rssreader.AbstractRssReader;
4+
import com.apptasticsoftware.rssreader.DateTimeParser;
5+
import com.apptasticsoftware.rssreader.module.itunes.ItunesExtensions;
6+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssExtensions;
7+
import com.apptasticsoftware.rssreader.module.psc.PscExtensions;
8+
9+
public class SpotifyRssReader extends AbstractRssReader<SpotifyChannel, SpotifyItem> {
10+
11+
@Override
12+
protected SpotifyChannel createChannel(DateTimeParser dateTimeParser) {
13+
return new SpotifyChannelImpl(dateTimeParser);
14+
}
15+
16+
@Override
17+
protected SpotifyItem createItem(DateTimeParser dateTimeParser) {
18+
return new SpotifyItemImpl(dateTimeParser);
19+
}
20+
21+
@Override
22+
protected void registerChannelTags() {
23+
super.registerChannelTags();
24+
var registry = getFeedExtensionRegistry();
25+
ItunesExtensions.register(registry);
26+
MediaRssExtensions.register(registry);
27+
PscExtensions.register(registry);
28+
SpotifyExtensions.register(registry);
29+
}
30+
}

0 commit comments

Comments
 (0)