Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ember.Plugins: Implement movie image scraper.

Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
  • Loading branch information...
commit 8fa5450de3a279a51395f4ef2740dedd94abe2d0 1 parent f93081f
@fyfe fyfe authored
View
18 Ember.Plugins/Dummy/DummyPlugin.cs
@@ -37,6 +37,8 @@ public override void InitPlugin(PluginManager manager)
manager.MovieScraper.PreMovieInfoScrape += PreMovieInfoScraperAction;
manager.MovieScraper.PostMovieInfoScrape += PostMovieInfoScraperAction;
+ manager.MovieScraper.PreMovieImageScrape += PreMovieImageScraperAction;
+ manager.MovieScraper.PostMovieImageScrape += PostMovieImageScraperAction;
}
#endregion Methods
@@ -62,6 +64,22 @@ public override void InitPlugin(PluginManager manager)
return result;
}
+ private MovieImageScraperActionContext PreMovieImageScraperAction(
+ MovieImageScraperActionContext context)
+ {
+ if (log.IsDebugEnabled)
+ log.Debug("PreMovieImageScraperAction[Dummy]");
+ return context;
+ }
+
+ private PluginActionResult PostMovieImageScraperAction(
+ PluginActionResult result)
+ {
+ if (log.IsDebugEnabled)
+ log.Debug("PostMovieImageScraperAction[Dummy]");
+ return result;
+ }
+
#endregion EventHandlers
}
View
1  Ember.Plugins/Ember.Plugins.csproj
@@ -69,6 +69,7 @@
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Scraper\Exceptions.cs" />
+ <Compile Include="Scraper\ImageScrapeActionContext.cs" />
<Compile Include="Scraper\IMovieImageScraper.cs" />
<Compile Include="Scraper\IMovieInfoScraper.cs" />
<Compile Include="Scraper\ITVImageScraper.cs" />
View
16 Ember.Plugins/Events/MovieScraper.cs
@@ -19,4 +19,20 @@ public delegate MovieInfoScraperActionContext
public delegate PluginActionResult
PostMovieInfoScraperActionHandler(PluginActionResult result);
+ /// <summary>
+ /// Delegate for PreMovieImageScraperAction.
+ /// </summary>
+ /// <param name="context">The context.</param>
+ /// <returns></returns>
+ public delegate MovieImageScraperActionContext
+ PreMovieImageScraperActionHandler(MovieImageScraperActionContext context);
+
+ /// <summary>
+ /// Delegate for PostMovieImageScraperAction.
+ /// </summary>
+ /// <param name="result">The result.</param>
+ /// <returns></returns>
+ public delegate PluginActionResult
+ PostMovieImageScraperActionHandler(PluginActionResult result);
+
}
View
61 Ember.Plugins/Scraper/IMovieImageScraper.cs
@@ -1,9 +1,68 @@
-namespace Ember.Plugins.Scraper
+using EmberAPI;
+
+namespace Ember.Plugins.Scraper
{
/// <summary>
/// Defines a movie image scraper.
/// </summary>
public interface IMovieImageScraper
{
+
+ /// <summary>
+ /// Scrapes the movie posters.
+ /// </summary>
+ /// <param name="context">The context.</param>
+ /// <returns></returns>
+ PluginActionResult ScrapeMovieImage(MovieImageScraperActionContext context);
+
+ }
+
+ /// <summary>
+ /// Context for a movie image scraper action.
+ /// </summary>
+ public class MovieImageScraperActionContext
+ : ImageScrapeActionContext
+ {
+
+ #region Fields
+
+ private Structures.DBMovie dbMovie;
+
+ #endregion Fields
+
+
+ #region Properties
+
+ /// <summary>
+ /// Gets the movie.
+ /// </summary>
+ public Structures.DBMovie DBMovie
+ {
+ get { return dbMovie; }
+ }
+
+ #endregion Properties
+
+
+ #region Constructor
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MovieImageScraperActionContext"/> class.
+ /// </summary>
+ /// <param name="dbMovie">The movie.</param>
+ /// <param name="scrapeType">The type of scrape to perform.</param>
+ /// <param name="askIfMultipleResults">if set to <c>true</c> ask the user to select a movie if multiple results are found.</param>
+ public MovieImageScraperActionContext(
+ Structures.DBMovie dbMovie,
+ ImageScrapeType imageScrapeType,
+ ScrapeType scrapeType,
+ bool askIfMultipleResults)
+ : base(imageScrapeType, scrapeType, askIfMultipleResults)
+ {
+ this.dbMovie = dbMovie;
+ }
+
+ #endregion Constructor
+
}
}
View
72 Ember.Plugins/Scraper/ImageScrapeActionContext.cs
@@ -0,0 +1,72 @@
+namespace Ember.Plugins.Scraper
+{
+
+ /// <summary>
+ /// The type of image scrape to perform.
+ /// </summary>
+ public enum ImageScrapeType
+ {
+ /// <summary>
+ /// Scrape a poster.
+ /// </summary>
+ Poster,
+
+ /// <summary>
+ /// Scrape fanart.
+ /// </summary>
+ Fanart,
+ }
+
+
+ /// <summary>
+ /// Context for image scraper actions.
+ /// </summary>
+ public class ImageScrapeActionContext
+ : ScraperActionContext
+ {
+
+ #region Fields
+
+ private ImageScrapeType imageScrapeType;
+
+ #endregion Fields
+
+
+ #region Properties
+
+ /// <summary>
+ /// Gets the type of image scrape to perform.
+ /// </summary>
+ /// <value>
+ /// The type of image scrape to perform.
+ /// </value>
+ public ImageScrapeType ImageScrapeType
+ {
+ get { return imageScrapeType; }
+ }
+
+ #endregion Properties
+
+
+ #region Constructor
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ImageScrapeActionContext"/> class.
+ /// </summary>
+ /// <param name="imageScrapeType">Type of the image scrape.</param>
+ /// <param name="scrapeType">Type of the scrape.</param>
+ /// <param name="askIfMultipleResults">if set to <c>true</c> [ask if multiple results].</param>
+ public ImageScrapeActionContext(
+ ImageScrapeType imageScrapeType,
+ ScrapeType scrapeType,
+ bool askIfMultipleResults)
+ : base(scrapeType, askIfMultipleResults)
+ {
+ this.imageScrapeType = imageScrapeType;
+ }
+
+ #endregion Constructor
+
+ }
+
+}
View
61 Ember.Plugins/Scraper/MovieScraperManager.cs
@@ -12,16 +12,31 @@ public class MovieScraperManager
: IDisposable, IMovieInfoScraper, IMovieImageScraper
{
+ #region Events
+
/// <summary>
- /// Occurs before a movie is scraped.
+ /// Occurs before movie information is scraped.
/// </summary>
public event Events.PreMovieInfoScraperActionHandler PreMovieInfoScrape;
/// <summary>
- /// Occurs after a movie is scraped.
+ /// Occurs after movie information is scraped.
/// </summary>
public event Events.PostMovieInfoScraperActionHandler PostMovieInfoScrape;
+ /// <summary>
+ /// Occurs before movie poster is scraped.
+ /// </summary>
+ public event Events.PreMovieImageScraperActionHandler PreMovieImageScrape;
+
+ /// <summary>
+ /// Occurs after movie poster is scraped.
+ /// </summary>
+ public event Events.PostMovieImageScraperActionHandler PostMovieImageScrape;
+
+ #endregion Events
+
+
#region Fields
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
@@ -62,7 +77,7 @@ public PluginActionResult ScrapeMovieInfo(MovieInfoScraperActionContext context)
PluginActionResult result = null;
foreach (IMovieInfoScraper plugin in manager.Plugins
- .Where(p => p.Enabled && p is IMovieInfoScraper)
+ .Where(p => p.Enabled && p.Plugin is IMovieInfoScraper)
.OrderBy(p => p.Order)
.Select(p => p.Plugin))
{
@@ -82,6 +97,46 @@ public PluginActionResult ScrapeMovieInfo(MovieInfoScraperActionContext context)
#endregion IMovieInfoScraper
+ #region IMovieImageScraper
+
+ /// <summary>
+ /// Scrapes the movie posters.
+ /// </summary>
+ /// <param name="context">The context.</param>
+ /// <returns></returns>
+ public PluginActionResult ScrapeMovieImage(MovieImageScraperActionContext context)
+ {
+ if (context == null)
+ throw new ArgumentNullException("context");
+ if (manager.Plugins.Count == 0)
+ return new PluginActionResult();
+
+ if (PreMovieImageScrape != null)
+ context = PreMovieImageScrape(context);
+
+ PluginActionResult result = null;
+
+ foreach (IMovieImageScraper plugin in manager.Plugins
+ .Where(p => p.Enabled && p.Plugin is IMovieImageScraper)
+ .OrderBy(p => p.Order)
+ .Select(p => p.Plugin))
+ {
+ result = plugin.ScrapeMovieImage(context);
+ if (result != null && result.BreakChain) break;
+ }
+
+ if (result == null)
+ result = new PluginActionResult();
+
+ if (PostMovieImageScrape != null)
+ result = PostMovieImageScrape(result);
+
+ return result;
+ }
+
+ #endregion IMovieImageScraper
+
+
#region IDisposable
#region Fields
Please sign in to comment.
Something went wrong with that request. Please try again.