Skip to content

Commit

Permalink
fixed: crash while scanning if season or episode number can't be dete…
Browse files Browse the repository at this point in the history
…rmined

also fixed some default values for season entries (changed "-1" to "-2"
since "-1" is reserved for the "* All Seasons" entry)
  • Loading branch information
DanCooper committed Aug 10, 2017
1 parent 93462b6 commit af9d3de
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
41 changes: 32 additions & 9 deletions EmberAPI/clsAPIScanner.vb
Expand Up @@ -1142,18 +1142,38 @@ Public Class Scanner
'no season specified -> assume defaultSeason
eItem.Season = defaultSeason
Dim Episode As Match = Regex.Match(tEpisode, "(\d*)(.*)")
eItem.Episode = CInt(Episode.Groups(1).Value)
Dim iEpisode As Integer = 0
If Integer.TryParse(Episode.Groups(1).Value, iEpisode) Then
eItem.Episode = iEpisode
Else
Return False
End If
If Not String.IsNullOrEmpty(Episode.Groups(2).Value) Then endPattern = Episode.Groups(2).Value
ElseIf Not String.IsNullOrEmpty(tSeason) AndAlso String.IsNullOrEmpty(tEpisode) Then
'no episode specification -> assume defaultSeason
'no episode specification -> assume defaultSeason and use the "season" group as episode number
eItem.Season = defaultSeason
eItem.Episode = CInt(tSeason)
Dim iEpisode As Integer = 0
If Integer.TryParse(tSeason, iEpisode) Then
eItem.Episode = iEpisode
Else
Return False
End If
Else
'season and episode specified
eItem.Season = CInt(tSeason)
Dim Episode As Match = Regex.Match(tEpisode, "(\d*)(.*)")
eItem.Episode = CInt(Episode.Groups(1).Value)
If Not String.IsNullOrEmpty(Episode.Groups(2).Value) Then endPattern = Episode.Groups(2).Value
Dim iSeason As Integer = 0
If Integer.TryParse(tSeason, iSeason) Then
eItem.Season = iSeason
Dim Episode As Match = Regex.Match(tEpisode, "(\d*)(.*)")
Dim iEpisode As Integer = 0
If Integer.TryParse(Episode.Groups(1).Value, iEpisode) Then
eItem.Episode = iEpisode
If Not String.IsNullOrEmpty(Episode.Groups(2).Value) Then endPattern = Episode.Groups(2).Value
Else
Return False
End If
Else
Return False
End If
End If
eItem.byDate = False

Expand Down Expand Up @@ -1196,7 +1216,10 @@ Public Class Scanner
retEpisodeItemsList.Add(eItem)
logger.Info(String.Format("[Scanner] [RegexGetTVEpisode] Found date based match {0} ({1}) [{2}]", sPath, eItem.Aired, rShow.Regexp))
Else
If Not RegexGetSeasonAndEpisodeNumber(sMatch, eItem, defaultSeason) Then Continue For
If Not RegexGetSeasonAndEpisodeNumber(sMatch, eItem, defaultSeason) Then
logger.Warn(String.Format("[Scanner] [RegexGetTVEpisode] Can't get a proper season and episode number for file {0} [{1}]", sPath, rShow.Regexp))
Continue For
End If
retEpisodeItemsList.Add(eItem)
logger.Info(String.Format("[Scanner] [RegexGetTVEpisode] Found episode match {0} (s{1}e{2}{3}) [{4}]", sPath, eItem.Season, eItem.Episode, If(Not eItem.SubEpisode = -1, String.Concat(".", eItem.SubEpisode), String.Empty), rShow.Regexp))
End If
Expand Down Expand Up @@ -1934,7 +1957,7 @@ Public Class Scanner
_bydate = False
_episode = -1
_idepisode = -1
_season = -1
_season = -2
_subepisode = -1
End Sub

Expand Down
12 changes: 6 additions & 6 deletions EmberAPI/clsAPISettings.vb
Expand Up @@ -7584,12 +7584,12 @@ Public Class Settings

If (Type = Enums.DefaultType.All OrElse Type = Enums.DefaultType.TVShowMatching) AndAlso (Force OrElse Master.eSettings.TVShowMatching.Count <= 0) Then
Master.eSettings.TVShowMatching.Clear()
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 0, .byDate = False, .defaultSeason = -1, .Regexp = "s([0-9]+)[ ._-]*e([0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?)([^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 0, .byDate = False, .defaultSeason = -2, .Regexp = "s([0-9]+)[ ._-]*e([0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?)([^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 1, .byDate = False, .defaultSeason = 1, .Regexp = "[\\._ -]()e(?:p[ ._-]?)?([0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?)([^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 2, .byDate = True, .defaultSeason = -1, .Regexp = "([0-9]{4})[.-]([0-9]{2})[.-]([0-9]{2})"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 3, .byDate = True, .defaultSeason = -1, .Regexp = "([0-9]{2})[.-]([0-9]{2})[.-]([0-9]{4})"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 4, .byDate = False, .defaultSeason = -1, .Regexp = "[\\\/._ \[\(-]([0-9]+)x([0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?)([^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 5, .byDate = False, .defaultSeason = -1, .Regexp = "[\\\/._ -]([0-9]+)([0-9][0-9](?:(?:[a-i]|\.[1-9])(?![0-9]))?)([._ -][^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 2, .byDate = True, .defaultSeason = -2, .Regexp = "([0-9]{4})[.-]([0-9]{2})[.-]([0-9]{2})"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 3, .byDate = True, .defaultSeason = -2, .Regexp = "([0-9]{2})[.-]([0-9]{2})[.-]([0-9]{4})"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 4, .byDate = False, .defaultSeason = -2, .Regexp = "[\\\/._ \[\(-]([0-9]+)x([0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?)([^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 5, .byDate = False, .defaultSeason = -2, .Regexp = "[\\\/._ -]([0-9]+)([0-9][0-9](?:(?:[a-i]|\.[1-9])(?![0-9]))?)([._ -][^\\\/]*)$"})
Master.eSettings.TVShowMatching.Add(New regexp With {.ID = 6, .byDate = False, .defaultSeason = 1, .Regexp = "[\\\/._ -]p(?:ar)?t[_. -]()([ivx]+|[0-9]+)([._ -][^\\\/]*)$"})
End If

Expand Down Expand Up @@ -8152,7 +8152,7 @@ Public Class Settings

Public Sub Clear()
_bydate = False
_defaultSeason = -1
_defaultSeason = -2 '-1 is reserved for "* All Seasons" entry
_id = -1
_regexp = String.Empty
End Sub
Expand Down
19 changes: 11 additions & 8 deletions EmberMediaManager/dlgSettings.vb
Expand Up @@ -727,15 +727,16 @@ Public Class dlgSettings
Private Sub btnTVSourcesRegexTVShowMatchingAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnTVSourcesRegexTVShowMatchingAdd.Click
If String.IsNullOrEmpty(btnTVSourcesRegexTVShowMatchingAdd.Tag.ToString) Then
Dim lID = (From lRegex As Settings.regexp In TVShowMatching Select lRegex.ID).Max
TVShowMatching.Add(New Settings.regexp With {.ID = Convert.ToInt32(lID) + 1,
.Regexp = txtTVSourcesRegexTVShowMatchingRegex.Text,
.defaultSeason = If(String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text) OrElse Not Integer.TryParse(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text, 0), -1, CInt(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text)),
.byDate = chkTVSourcesRegexTVShowMatchingByDate.Checked})
TVShowMatching.Add(New Settings.regexp With {
.ID = Convert.ToInt32(lID) + 1,
.Regexp = txtTVSourcesRegexTVShowMatchingRegex.Text,
.defaultSeason = If(String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text) OrElse Not Integer.TryParse(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text, 0), -2, CInt(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text)),
.byDate = chkTVSourcesRegexTVShowMatchingByDate.Checked})
Else
Dim selRex = From lRegex As Settings.regexp In TVShowMatching Where lRegex.ID = Convert.ToInt32(btnTVSourcesRegexTVShowMatchingAdd.Tag)
If selRex.Count > 0 Then
selRex(0).Regexp = txtTVSourcesRegexTVShowMatchingRegex.Text
selRex(0).defaultSeason = CInt(If(String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text), "-1", txtTVSourcesRegexTVShowMatchingDefaultSeason.Text))
selRex(0).defaultSeason = CInt(If(String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text), "-2", txtTVSourcesRegexTVShowMatchingDefaultSeason.Text))
selRex(0).byDate = chkTVSourcesRegexTVShowMatchingByDate.Checked
End If
End If
Expand Down Expand Up @@ -2731,7 +2732,7 @@ Public Class dlgSettings
btnTVSourcesRegexTVShowMatchingAdd.Tag = lItem.Text

txtTVSourcesRegexTVShowMatchingRegex.Text = lItem.SubItems(1).Text.ToString
txtTVSourcesRegexTVShowMatchingDefaultSeason.Text = If(Not lItem.SubItems(2).Text = "-1", lItem.SubItems(2).Text, String.Empty)
txtTVSourcesRegexTVShowMatchingDefaultSeason.Text = If(Not lItem.SubItems(2).Text = "-2", lItem.SubItems(2).Text, String.Empty)

Select Case lItem.SubItems(3).Text
Case "Yes"
Expand Down Expand Up @@ -4043,7 +4044,7 @@ Public Class dlgSettings
For Each rShow As Settings.regexp In TVShowMatching
lvItem = New ListViewItem(rShow.ID.ToString)
lvItem.SubItems.Add(rShow.Regexp)
lvItem.SubItems.Add(If(Not rShow.defaultSeason.ToString = "-1", rShow.defaultSeason.ToString, String.Empty))
lvItem.SubItems.Add(If(Not rShow.defaultSeason.ToString = "-2", rShow.defaultSeason.ToString, String.Empty))
lvItem.SubItems.Add(If(rShow.byDate, "Yes", "No"))
lvTVSourcesRegexTVShowMatching.Items.Add(lvItem)
Next
Expand Down Expand Up @@ -7246,7 +7247,9 @@ Public Class dlgSettings
End Sub

Private Sub ValidateTVShowMatching()
If Not String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingRegex.Text) AndAlso (String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text) OrElse Integer.TryParse(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text, 0)) Then
If Not String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingRegex.Text) AndAlso
(String.IsNullOrEmpty(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text.Trim) OrElse Integer.TryParse(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text, 0) AndAlso
CInt(txtTVSourcesRegexTVShowMatchingDefaultSeason.Text.Trim) >= 0) Then
btnTVSourcesRegexTVShowMatchingAdd.Enabled = True
Else
btnTVSourcesRegexTVShowMatchingAdd.Enabled = False
Expand Down

0 comments on commit af9d3de

Please sign in to comment.