-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Start from tinyMediaManager/scraperaddonsample
- Loading branch information
0 parents
commit 8fff13e
Showing
19 changed files
with
629 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
javacore* | ||
jitdump* | ||
Snap* | ||
|
||
#Maven | ||
target | ||
release.properties | ||
pom.xml.* | ||
|
||
#IntelliJ IDEA | ||
.idea/ | ||
*.iml | ||
|
||
#Eclipse | ||
/bin | ||
|
||
#Vim | ||
*.swp |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>scraperaddonsample</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 | ||
org.eclipse.jdt.core.compiler.compliance=11 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=11 |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Scraper-Addon Sample | ||
This project is a sample/template for a scraper addon which can be loaded in tinyMediaManager | ||
|
||
## i18n | ||
tinyMediaManager can read localized scraper option names from the custom scraper via an own `ResourceBundle` (v4.3.9+). | ||
|
||
To use a custom `ResourceBundle` you need to | ||
|
||
1. Create your own properties files containing the literals/translated contents (see `src/main/java/org/tinymediamanager/scraper/spisample/messages.properties`) | ||
2. Register your `ResourceBundle` in the `MediaProviderInfo` | ||
```java | ||
// the ResourceBundle to offer i18n support for scraper options | ||
providerInfo.setResourceBundle(ResourceBundle.getBundle("org.tinymediamanager.scraper.spisample.messages")); | ||
``` | ||
3. Add a text for every option in the following form to the properties file | ||
``` | ||
#scraper.<scraper id>.<option name>=<text> | ||
scraper.spi-sample.text=Text field | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.tinymediamanager</groupId> | ||
<artifactId>scraper-addon-sample</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<repositories> | ||
<repository> | ||
<id>gitlab-maven</id> | ||
<url>https://gitlab.com/api/v4/projects/9945251/packages/maven</url> | ||
</repository> | ||
</repositories> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.tinymediamanager</groupId> | ||
<artifactId>tinyMediaManager</artifactId> | ||
<version>4.3.9</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/tinymediamanager/scraper/spisample/SampleAddonProvider.java
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2012 - 2020 Manuel Laggner | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.tinymediamanager.scraper.spisample; | ||
|
||
import org.tinymediamanager.scraper.interfaces.IMediaProvider; | ||
import org.tinymediamanager.scraper.spi.IAddonProvider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SampleAddonProvider implements IAddonProvider { | ||
|
||
@Override | ||
public List<Class<? extends IMediaProvider>> getAddonClasses() { | ||
List<Class<? extends IMediaProvider>> addons = new ArrayList<>(); | ||
|
||
// this is the detailed example | ||
addons.add(SampleMovieMetadataProvider.class); | ||
|
||
// these are just empty classes to show how multiple sub-scrapers can be passed to tmm | ||
addons.add(SampleMovieArtworkProvider.class); | ||
addons.add(SampleMovieTrailerProvider.class); | ||
addons.add(SampleMovieSubtitleProvider.class); | ||
addons.add(SampleTvShowMetadataProvider.class); | ||
addons.add(SampleTvShowArtworkProvider.class); | ||
addons.add(SampleTvShowTrailerProvider.class); | ||
addons.add(SampleTvShowSubtitleProvider.class); | ||
|
||
return addons; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/tinymediamanager/scraper/spisample/SampleMovieArtworkProvider.java
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.tinymediamanager.scraper.spisample; | ||
|
||
import org.tinymediamanager.scraper.ArtworkSearchAndScrapeOptions; | ||
import org.tinymediamanager.scraper.MediaProviderInfo; | ||
import org.tinymediamanager.scraper.entities.MediaArtwork; | ||
import org.tinymediamanager.scraper.exceptions.MissingIdException; | ||
import org.tinymediamanager.scraper.exceptions.ScrapeException; | ||
import org.tinymediamanager.scraper.interfaces.IMovieArtworkProvider; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class SampleMovieArtworkProvider implements IMovieArtworkProvider { | ||
|
||
private final MediaProviderInfo providerInfo; | ||
|
||
public SampleMovieArtworkProvider() { | ||
providerInfo = createProviderInfo(); | ||
} | ||
|
||
private MediaProviderInfo createProviderInfo() { | ||
return new MediaProviderInfo("spi-sample", "movie", "SPI Sample", "A sample for a dynamic movie artwork scraper"); | ||
} | ||
|
||
@Override | ||
public MediaProviderInfo getProviderInfo() { | ||
return providerInfo; | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<MediaArtwork> getArtwork(ArtworkSearchAndScrapeOptions artworkSearchAndScrapeOptions) throws ScrapeException, MissingIdException { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
101 changes: 101 additions & 0 deletions
101
src/main/java/org/tinymediamanager/scraper/spisample/SampleMovieMetadataProvider.java
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.tinymediamanager.scraper.spisample; | ||
|
||
import org.joda.time.DateTime; | ||
import org.tinymediamanager.core.entities.MediaRating; | ||
import org.tinymediamanager.core.movie.MovieSearchAndScrapeOptions; | ||
import org.tinymediamanager.scraper.MediaMetadata; | ||
import org.tinymediamanager.scraper.MediaProviderInfo; | ||
import org.tinymediamanager.scraper.MediaSearchResult; | ||
import org.tinymediamanager.scraper.entities.MediaCertification; | ||
import org.tinymediamanager.scraper.entities.MediaType; | ||
import org.tinymediamanager.scraper.exceptions.ScrapeException; | ||
import org.tinymediamanager.scraper.interfaces.IMovieMetadataProvider; | ||
|
||
import java.util.ResourceBundle; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
public class SampleMovieMetadataProvider implements IMovieMetadataProvider { | ||
|
||
private final MediaProviderInfo providerInfo; | ||
|
||
public SampleMovieMetadataProvider() { | ||
providerInfo = createProviderInfo(); | ||
} | ||
|
||
private MediaProviderInfo createProviderInfo() { | ||
MediaProviderInfo info = new MediaProviderInfo("spi-sample", "movie", "SPI Sample", "A sample for a dynamic movie metadata scraper", SampleMovieMetadataProvider.class.getResource("/org/tinymediamanager/scraper/spisample/tmm_logo.svg")); | ||
// the ResourceBundle to offer i18n support for scraper options | ||
info.setResourceBundle(ResourceBundle.getBundle("org.tinymediamanager.scraper.spisample.messages")); | ||
|
||
// create configuration properties | ||
info.getConfig().addText("text", "", false); | ||
info.getConfig().addBoolean("boolean", true); | ||
info.getConfig().addInteger("integer", 10); | ||
info.getConfig().addSelect("select", new String[]{"A", "B", "C"}, "A"); | ||
|
||
// load any existing values from the storage | ||
info.getConfig().load(); | ||
|
||
return info; | ||
} | ||
|
||
@Override | ||
public MediaProviderInfo getProviderInfo() { | ||
return providerInfo; | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public SortedSet<MediaSearchResult> search(MovieSearchAndScrapeOptions movieSearchAndScrapeOptions) throws ScrapeException { | ||
SortedSet<MediaSearchResult> results = new TreeSet<>(); | ||
MediaSearchResult result = new MediaSearchResult(getId(), MediaType.MOVIE); | ||
|
||
// set the values of the search result. | ||
// id, title, year and score is needed | ||
result.setId(getId()); | ||
result.setTitle("This is a result"); | ||
result.setYear(2021); | ||
|
||
// set the search score. should be calculated from the search query | ||
// you can use the helper either | ||
result.calculateScore(movieSearchAndScrapeOptions); | ||
// or set the score directly (0...1) | ||
result.setScore(1.0f); | ||
|
||
results.add(result); | ||
|
||
// more detailed example can be found in the tmm repo: | ||
// https://gitlab.com/tinyMediaManager/tinyMediaManager/-/tree/devel/src/main/java/org/tinymediamanager/scraper | ||
|
||
return results; | ||
} | ||
|
||
@Override | ||
public MediaMetadata getMetadata(MovieSearchAndScrapeOptions movieSearchAndScrapeOptions) throws ScrapeException { | ||
MediaMetadata mediaMetadata = new MediaMetadata(getId()); | ||
|
||
// here you may set all available data | ||
mediaMetadata.setTitle("title"); | ||
mediaMetadata.setOriginalTitle("original title"); | ||
mediaMetadata.setPlot("the plot of the movie"); | ||
mediaMetadata.setYear(2021); | ||
mediaMetadata.setReleaseDate(DateTime.parse("2010-06-30")); | ||
mediaMetadata.setId(getId(), 1234); | ||
mediaMetadata.setId(MediaMetadata.IMDB, "tt123456"); | ||
mediaMetadata.addRating(new MediaRating(getId(), 5.5f, 200, 10)); | ||
mediaMetadata.addRating(new MediaRating(MediaMetadata.IMDB, 7.8f, 20000)); | ||
mediaMetadata.addCertification(MediaCertification.US_G); | ||
mediaMetadata.addCertification(MediaCertification.DE_FSK12); | ||
|
||
// more detailed example can be found in the tmm repo: | ||
// https://gitlab.com/tinyMediaManager/tinyMediaManager/-/tree/devel/src/main/java/org/tinymediamanager/scraper | ||
|
||
return mediaMetadata; | ||
} | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
src/main/java/org/tinymediamanager/scraper/spisample/SampleMovieSubtitleProvider.java
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.tinymediamanager.scraper.spisample; | ||
|
||
import org.tinymediamanager.scraper.MediaProviderInfo; | ||
import org.tinymediamanager.scraper.SubtitleSearchAndScrapeOptions; | ||
import org.tinymediamanager.scraper.SubtitleSearchResult; | ||
import org.tinymediamanager.scraper.exceptions.MissingIdException; | ||
import org.tinymediamanager.scraper.exceptions.ScrapeException; | ||
import org.tinymediamanager.scraper.interfaces.IMovieSubtitleProvider; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class SampleMovieSubtitleProvider implements IMovieSubtitleProvider { | ||
|
||
private final MediaProviderInfo providerInfo; | ||
|
||
public SampleMovieSubtitleProvider() { | ||
providerInfo = createProviderInfo(); | ||
} | ||
|
||
private MediaProviderInfo createProviderInfo() { | ||
return new MediaProviderInfo("spi-sample", "movie_subtitle", "SPI Sample", "A sample for a dynamic movie subtitle scraper"); | ||
} | ||
|
||
@Override | ||
public MediaProviderInfo getProviderInfo() { | ||
return providerInfo; | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public List<SubtitleSearchResult> search(SubtitleSearchAndScrapeOptions subtitleSearchAndScrapeOptions) throws ScrapeException, MissingIdException { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
Oops, something went wrong.