Skip to content

Commit

Permalink
Share Lizzy playlist implementation
Browse files Browse the repository at this point in the history
Remove all internal marshalling and unmarshalling of playlists, use Lizzy module instead.
Update to dependency `io.github.borewit:lizzy` to version 2.0.0
  • Loading branch information
Borewit committed Mar 24, 2023
1 parent 4508962 commit 3a188f2
Show file tree
Hide file tree
Showing 77 changed files with 943 additions and 116,822 deletions.
4 changes: 4 additions & 0 deletions .lift.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build = "gradle"
jdkVersion = "15"

ignoreRules = ["PATH_TRAVERSAL_IN", "YodaCondition"]
22 changes: 7 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ plugins {
// https://github.com/openjfx/javafx-gradle-plugin
id 'org.openjfx.javafxplugin' version '0.0.13'

// Generate Java code from XSD
id 'org.unbroken-dome.xjc' version '2.0.0'

id 'checkstyle'

// https://github.com/qoomon/gradle-git-versioning-plugin
Expand Down Expand Up @@ -90,16 +87,16 @@ repositories {
maven {
url "https://repo1.maven.org/maven2/"
}
mavenLocal()
// mavenLocal()
// Staging repository
maven { url 'https://s01.oss.sonatype.org/content/groups/staging/' }
// maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}

dependencies {

// Provides christophedelory.playlist.*
implementation 'io.github.borewit:lizzy:1.2.0'
implementation 'io.github.borewit:lizzy:2.0.0'

// https://mvnrepository.com/artifact/com.jgoodies/jgoodies-common
implementation 'com.jgoodies:jgoodies-common:1.8.1'
Expand All @@ -110,16 +107,15 @@ dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:31.1-jre'

// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
implementation 'javax.xml.bind:jaxb-api:2.3.1'

// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'

// Apache SLF4J to Log4j2 Adapter (bridge)
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0'

implementation 'jakarta.activation:jakarta.activation-api:2.1.1';

// Required for log4j yaml configuration files
// https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2'
Expand Down Expand Up @@ -163,7 +159,7 @@ def generatedImages = "$generatedResources/images"
sourceSets {
main {
java {
srcDirs = ['src/main/java', "$generatedSources/xjc/java/main"]
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources', generatedResources]
Expand All @@ -179,7 +175,7 @@ task fatJar(type: Jar) {
setDuplicatesStrategy(DuplicatesStrategy.WARN)
archiveBaseName = 'listFix'
archiveClassifier = 'all'
from { configurations.compileClasspath.filter { it.exists() }.collect { it.isDirectory() ? it : zipTree(it) } }
from { configurations.runtimeClasspath.filter { it.exists() }.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}

Expand Down Expand Up @@ -218,10 +214,6 @@ task makeIcon (type: Svg2IcoTask) {
destination = file('website/favicon.ico')
}

tasks.withType(JavaCompile).configureEach {
compileTask -> compileTask.dependsOn xjcGenerate
}

tasks.withType(Checkstyle).configureEach {
exclude 'listfix/model/playlists/winamp/generated/**.java'
}
Expand Down
2 changes: 1 addition & 1 deletion simplelog.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Uncomment this line if you want to log the reports of the content metadata providers when connecting to the individual media files/URLs.
#org.apache.commons.logging.simplelog.log.christophedelory.content.ContentMetadataCenter=debug

#org.apache.commons.logging.simplelog.log.christophedelory.lizzy.FetchContentMetadata=debug
#org.apache.commons.logging.simplelog.log.io.github.borewit.lizzy.FetchContentMetadata=debug

#org.apache.commons.logging.simplelog.log.christophedelory.playlist.Playlist=debug

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/listfix/io/FileTreeNodeGenerator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package listfix.io;

import listfix.comparators.DirectoryThenFileThenAlphabeticalPathComparator;
import listfix.model.playlists.Playlist;
import listfix.io.playlists.LizzyPlaylistUtil;
import listfix.view.support.PlaylistTreeNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -33,7 +33,7 @@ public static PlaylistTreeNode addNodes(PlaylistTreeNode curTop, Stream<Path> fi
{
PlaylistTreeNode currentNode = curTop == null ? new PlaylistTreeNode(Path.of("#___root___")) : curTop;
files
.filter(file -> Files.isDirectory(file) || Playlist.isPlaylist(file))
.filter(file -> Files.isDirectory(file) || LizzyPlaylistUtil.isPlaylist(file))
.sorted(new DirectoryThenFileThenAlphabeticalPathComparator())
.map(PlaylistTreeNode::new)
.forEach(node -> {
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/listfix/io/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package listfix.io;

import listfix.model.playlists.Playlist;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class FileUtils
{
public static final Set<String> mediaExtensions = Stream.of("mp3", "wma", "flac", "ogg", "wav", "midi", "cda", "mpg", "mpeg", "m2v", "avi", "m4v", "flv", "mid", "mp2", "mp1", "aac", "asx", "m4a", "mp4", "m4v", "nsv", "aiff", "au", "wmv", "asf", "mpc")
.collect(Collectors.toCollection(HashSet::new));

public static File findDeepestPathToExist(File file)
{
if (file == null || file.exists())
Expand All @@ -37,11 +42,21 @@ public static boolean isMediaFile(String filename)
String extension = getFileExtension(filename);
if (extension != null)
{
return Playlist.mediaExtensions.contains(extension.toLowerCase());
return mediaExtensions.contains(extension.toLowerCase());
}
return false;
}

public static Optional<String> getExtension(String name)
{
int ix = name.lastIndexOf('.');
if (ix >= 0 && ix < name.length() - 1)
{
return Optional.of(name.substring(ix + 1));
}
return Optional.empty();
}

public static boolean isURL(String trackText)
{
try
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/listfix/io/PlaylistScanner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package listfix.io;

import listfix.model.playlists.Playlist;
import listfix.io.playlists.LizzyPlaylistUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -35,7 +35,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
{
if (Playlist.isPlaylist(file))
if (LizzyPlaylistUtil.isPlaylist(file))
{
result.add(file);
}
Expand Down
124 changes: 0 additions & 124 deletions src/main/java/listfix/io/WinampHelper.java

This file was deleted.

23 changes: 13 additions & 10 deletions src/main/java/listfix/io/datatransfer/PlaylistTransferObject.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package listfix.io.datatransfer;

import christophedelory.playlist.SpecificPlaylist;
import listfix.io.playlists.LizzyPlaylistConversion;
import io.github.borewit.lizzy.playlist.Playlist;
import io.github.borewit.lizzy.playlist.PlaylistFormat;
import io.github.borewit.lizzy.playlist.SpecificPlaylist;
import listfix.io.playlists.LizzyPlaylistUtil;

import java.awt.datatransfer.DataFlavor;
import java.io.*;
import java.util.List;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
* Used to serialize / deserialize playlist to memory from drag and drop
Expand All @@ -14,11 +17,11 @@ public class PlaylistTransferObject
{
public static DataFlavor M3uPlaylistDataFlavor = new DataFlavor("audio/mpegurl", "M3U Playlist");

private static final String playlistType = ".m3u"; // ToDo: use MIME
private static final PlaylistFormat playlistFormat = PlaylistFormat.m3u;

public static void serialize(List<String> entryList, OutputStream outputStream) throws IOException
public static void serialize(Playlist playlist, OutputStream outputStream) throws IOException
{
SpecificPlaylist specificPlaylist = LizzyPlaylistConversion.toPlaylist(playlistType, entryList);
SpecificPlaylist specificPlaylist = LizzyPlaylistUtil.toPlaylist(playlistFormat, playlist);
try
{
specificPlaylist.writeTo(outputStream, null);
Expand All @@ -29,9 +32,9 @@ public static void serialize(List<String> entryList, OutputStream outputStream)
}
}

public static List<String> deserialize(InputStream input)
public static Playlist deserialize(InputStream input)
{
SpecificPlaylist playlist = LizzyPlaylistConversion.readPlaylistFromInputStream(".m3u", input); // ToDo: use MIME
return LizzyPlaylistConversion.toListOfFiles(playlist.toPlaylist());
SpecificPlaylist playlist = LizzyPlaylistUtil.readPlaylistFromInputStream(playlistFormat, input);
return playlist.toPlaylist();
}
}
36 changes: 36 additions & 0 deletions src/main/java/listfix/io/filters/AllPlaylistFileFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package listfix.io.filters;

import listfix.io.playlists.LizzyPlaylistUtil;

import java.io.File;
import java.io.FileFilter;

/**
* A FileFilter that accepts our currently supported playlist types, and directories.
*/
public class AllPlaylistFileFilter extends FileExtensionFilterBase implements FileFilter
{
public AllPlaylistFileFilter()
{
super("All Playlists", LizzyPlaylistUtil.playlistExtensions);
}

@Override
public String getDescription()
{
return "Playlists";
}

@Override
public boolean accept(File file)
{
return file.isDirectory() || super.accept(file);
}

@Override
public String toString()
{
return getDescription();
}
}

Loading

0 comments on commit 3a188f2

Please sign in to comment.