Skip to content

Commit

Permalink
Bugfix for issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
JnRMnT committed Feb 16, 2023
1 parent f271ff1 commit f31dce1
Show file tree
Hide file tree
Showing 208 changed files with 4,617 additions and 1,776 deletions.
35 changes: 32 additions & 3 deletions JMovies.IMDb.Common/Extensions/TimeSpanExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using JMovies.IMDb.Common.Constants;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

/// <summary>
/// Class responsible for providing Extenions for TimeSpans
Expand Down Expand Up @@ -59,4 +56,36 @@ public static TimeSpan ToHtmlTimeSpan(this string dateTimeString)
return timeSpan;
}
}

/// <summary>
/// Extension that converts human readable duration string into C# TimeSpan
/// </summary>
/// <param name="humanReadableDuration">The human readable string</param>
/// <returns>C# TimeSpan equivalent</returns>
public static TimeSpan HumanReadableToTimeSpan(this string humanReadableDuration)
{
Dictionary<string, int> units = new Dictionary<string, int>()
{
{@"(\d+)\s*(ms|mili[|s]|milisecon[|s])", 1 },
{@"(\d+)\s*(s|sec|second[|s])", 1000 },
{@"(\d+)\s*(m|min[|s])", 60000 },
{@"(\d+)\s*(h|hour[|s])", 3600000 },
{@"(\d+)\s*(d|day[|s])", 86400000 },
{@"(\d+)\s*(w|week[|s])", 604800000 },
};

var timespan = new TimeSpan();

foreach (var x in units)
{
var matches = Regex.Matches(humanReadableDuration, x.Key);
foreach (Match match in matches)
{
var amount = System.Convert.ToInt32(match.Groups[1].Value);
timespan = timespan.Add(TimeSpan.FromMilliseconds(x.Value * amount));
}
}

return timespan;
}
}
7 changes: 7 additions & 0 deletions JMovies.IMDb.Common/JMovies.IMDb.Common.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JMovies.IMDb.Entities/JMovies.IMDb.Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Company>JnRMnT</Company>
<Copyright>JnRMnT</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.8.0</Version>
<Version>1.8.1</Version>
<Description>JMovies IMDb Entities Library - A .Net Standart class library that provides class definitions for IMDb.</Description>
<RepositoryUrl>https://github.com/JnRMnT/JMovies.IMDb</RepositoryUrl>
<PackageTags>scraper,movies,movie,imdb,actor,scraping,screenscrapping,api,imdb-scraper</PackageTags>
Expand Down
75 changes: 75 additions & 0 deletions JMovies.IMDb.Entities/JMovies.IMDb.Entities.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions JMovies.IMDb.Entities/Movies/LDJson/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Text.Json.Serialization;

namespace JMovies.IMDb.Entities.Movies.LDJson
{
/// <summary>
/// Class representing a basic info linked to the production
/// </summary>
public class Info
{
/// <summary>
/// Property representing the info type
/// </summary>
[JsonPropertyName("@type")]
public string InfoType { get; set; }

/// <summary>
/// Property representing name related to the info
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// Property representing URL related to the info
/// </summary>
[JsonPropertyName("url")]
public string URL { get; set; }
}
}
74 changes: 74 additions & 0 deletions JMovies.IMDb.Entities/Movies/LDJson/Metadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Text.Json.Serialization;

namespace JMovies.IMDb.Entities.Movies.LDJson
{
/// <summary>
/// Class representing the metadata linked to the page
/// </summary>
public class Metadata
{
/// <summary>
/// Property representing the production's type
/// </summary>
[JsonPropertyName("@type")]
public string ProductionType { get; set; }

/// <summary>
/// Property representing the production's description
/// </summary>
[JsonPropertyName("description")]
public string Description { get; set; }


/// <summary>
/// Property representing the production's URL
/// </summary>
[JsonPropertyName("url")]
public string URL { get; set; }


/// <summary>
/// Property representing the actor list of the production
/// </summary>
[JsonPropertyName("actor")]
public Info[] Actors { get; set; }

/// <summary>
/// Property representing the creator list of the production
/// </summary>
[JsonPropertyName("creator")]
public Info[] Creators { get; set; }

/// <summary>
/// Property representing the release date of the production
/// </summary>
[JsonPropertyName("datePublished")]
public string ReleaseDate { get; set; }

/// <summary>
/// Property representing the genre list of the production
/// </summary>
[JsonPropertyName("genre")]
public string[] Genres { get; set; }


/// <summary>
/// Property representing the name of the production
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// Property representing the keywords related to the production
/// </summary>
[JsonPropertyName("keywords")]
public string Keywords { get; set; }

/// <summary>
/// Property representing the main image related to the production
/// </summary>
[JsonPropertyName("image")]
public string Image { get; set; }

}
}
22 changes: 21 additions & 1 deletion JMovies.IMDb.Tests/JMovies.IMDb.Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JMovies.IMDb.Tests/Production/AKATests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace JMovies.IMDb.Tests.Production
{ /// <summary>
/// Test class that contains the tests which are targeted for scraping culture related tests
/// Test class that contains the tests which are targeted for scraping AKAs related tests
/// </summary>
[TestClass]
public class AKATests
Expand Down
31 changes: 31 additions & 0 deletions JMovies.IMDb.Tests/Production/GenreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using JMovies.IMDb.Entities.Interfaces;
using JMovies.IMDb.Entities.Settings;
using JMovies.IMDb.Entities.Settings.Presets;
using JMovies.IMDb.Providers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace JMovies.IMDb.Tests.Production
{
/// <summary>
/// Test class that contains the tests which are targeted for scraping runtime info related tests
/// </summary>
[TestClass]
public class GenreTests
{
/// <summary>
/// Test Method that tests genre info of the TV Series "Hunters"
/// </summary>
[TestMethod]
public void TestGenreOfHunters()
{
IIMDbDataProvider imdbDataProvider = new IMDbScraperDataProvider();
ProductionDataFetchSettings settings = new BasicProductionDataFetchSettings();
Entities.Movies.TVSeries tvSeries = imdbDataProvider.GetTvSeries(7456722, settings); // https://www.imdb.com/title/tt7456722/
Assert.IsNotNull(tvSeries);
Assert.IsNotNull(tvSeries.Genres);
Assert.AreNotEqual(0, tvSeries.Genres.Count);
Assert.IsTrue(Enumerable.SequenceEqual(new string[] { "Crime", "Drama", "Mystery" }, tvSeries.Genres.Select(e => e.Value).ToArray()));
}
}
}
30 changes: 30 additions & 0 deletions JMovies.IMDb.Tests/Production/RuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using JMovies.IMDb.Entities.Interfaces;
using JMovies.IMDb.Entities.Settings;
using JMovies.IMDb.Entities.Settings.Presets;
using JMovies.IMDb.Providers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace JMovies.IMDb.Tests.Production
{
/// <summary>
/// Test class that contains the tests which are targeted for scraping runtime info related tests
/// </summary>
[TestClass]
public class RuntimeTests
{
/// <summary>
/// Test Method that tests runtime info of the TV Series "Hunters"
/// </summary>
[TestMethod]
public void RuntimeOfHunters()
{
IIMDbDataProvider imdbDataProvider = new IMDbScraperDataProvider();
ProductionDataFetchSettings settings = new BasicProductionDataFetchSettings();
Entities.Movies.TVSeries tvSeries = imdbDataProvider.GetTvSeries(7456722, settings); // https://www.imdb.com/title/tt7456722/
Assert.IsNotNull(tvSeries);
Assert.AreNotEqual(default, tvSeries.Runtime);
Assert.AreEqual(TimeSpan.FromMinutes(60), tvSeries.Runtime);
}
}
}
Loading

0 comments on commit f31dce1

Please sign in to comment.