Skip to content

Commit

Permalink
Minor improvments to rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottRFrost committed Sep 26, 2016
1 parent 5870e1a commit bd48f20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/SimpleSFTPSyncCore/Rename.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ static string Clean(this string filename)
// Strip things we know we don't want
return (
filename
.ToLowerInvariant()
.Replace("1080p", string.Empty).Replace("720p", string.Empty).Replace("x264", string.Empty).Replace("h264", string.Empty).Replace("ac3", string.Empty).Replace("dts", string.Empty)
.Replace("blurayrip", string.Empty).Replace("bluray", string.Empty).Replace("dvdrip", string.Empty).Replace("HDTV", string.Empty).Replace("Webrip", string.Empty)
.Replace(".", " ").Replace(" ", " ").Replace(" ", " ")
Expand Down Expand Up @@ -132,7 +131,8 @@ public static string Movie(string filename)
}

// Attempt OMDBAPI Check
var title = filename.Substring(0, idx - 1).Trim();
var title = filename.Substring(0, idx - 1).Trim(); // Strip garbage after year
title = title.Substring(title.LastIndexOf("\\", StringComparison.Ordinal) + 1); // Strip Folder
var httpClient = new ProHttpClient();
dynamic omdbapi = JObject.Parse(httpClient.DownloadString("http://www.omdbapi.com/?type=movie&t=" + title + "&y=" + year.ToString(CultureInfo.InvariantCulture)).Result);
if (omdbapi.Response == "False")
Expand All @@ -157,7 +157,7 @@ public static string Movie(string filename)
else if (genres.Contains("Adventure")) { genre = "Adventure"; }
return (genre +"\\" + (string)omdbapi.Title + " (" + year.ToString(CultureInfo.InvariantCulture) + ").mkv").CleanFilePath();
}
return filename.CleanFilePath();
return filename.Substring(filename.LastIndexOf("\\", StringComparison.Ordinal) + 1).CleanFilePath();
}

/// <summary>
Expand All @@ -180,21 +180,22 @@ public static string TV(string filename)
if (idx > 0)
{
// Attempt OMDBAPI Check
var title = filename.Substring(0, idx - 1).Trim();
var title = filename.Substring(0, idx - 1).Trim(); // Strip S01E01 and trailing garbage
title = title.Substring(title.LastIndexOf("\\", StringComparison.Ordinal) + 1); // Strip Folder
var httpClient = new ProHttpClient();
dynamic omdbapi = JObject.Parse(httpClient.DownloadString("http://www.omdbapi.com/?type=series&t=" + title).Result);
if (omdbapi.Response == "False")
{
// Didn't find it, return a best guess
return (title + "\\Season " + season.ToString(CultureInfo.InvariantCulture) + "\\" + title + " - " + episodeNumber.ToUpperInvariant() + ".mkv").CleanFilePath();
return (title.CleanFilePath() + "\\Season " + season.ToString(CultureInfo.InvariantCulture) + "\\" + title.CleanFilePath() + " - " + episodeNumber.ToUpperInvariant() + ".mkv");
}
// Found it, use the corrected title
title = (string)omdbapi.Title;
return (title + "\\Season " + season.ToString(CultureInfo.InvariantCulture) + "\\" + title + " - " + episodeNumber.ToUpperInvariant() + ".mkv").CleanFilePath();
return (title.CleanFilePath() + "\\Season " + season.ToString(CultureInfo.InvariantCulture) + "\\" + title.CleanFilePath() + " - " + episodeNumber.ToUpperInvariant() + ".mkv").CleanFilePath();
}
}
}
return filename.CleanFilePath();
return filename.Substring(filename.LastIndexOf("\\", StringComparison.Ordinal) + 1).CleanFilePath();
}
}
}
5 changes: 3 additions & 2 deletions src/SimpleSFTPSyncCore/SimpleSFTPSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void MoveFiles(List<string> mkvs)
if (Rename.IsTV(mkv))
{
var filename = Rename.TV(mkv);
Log("Moving TV " + mkv + " --> " + tvDir + '\\' + filename);
Log("Moving TV " + mkv + " -->\r\n " + tvDir + '\\' + filename);
Directory.CreateDirectory(tvDir + '\\' + filename.Substring(0, filename.LastIndexOf("\\", StringComparison.Ordinal)));
var shouldMove = true;
if (File.Exists(tvDir + '\\' + filename))
Expand Down Expand Up @@ -266,7 +266,7 @@ public void MoveFiles(List<string> mkvs)
else
{
var filename = Rename.Movie(mkv);
Log("Moving Movie " + mkv + " --> " + movieDir + '\\' + filename);
Log("Moving Movie " + mkv + " -->\r\n " + movieDir + '\\' + filename);
Directory.CreateDirectory(movieDir + '\\' + filename.Substring(0, filename.LastIndexOf("\\", StringComparison.Ordinal)));
var shouldMove = true;
if (File.Exists(movieDir + '\\' + filename))
Expand Down Expand Up @@ -297,6 +297,7 @@ public void MoveFiles(List<string> mkvs)
Log("!!ERROR!! during move of " + mkv + " - " + ex);
}
}
log.Flush();
}

/// <summary>
Expand Down

0 comments on commit bd48f20

Please sign in to comment.