Skip to content

Commit

Permalink
Refactored: Simplified title mapping and improved stream check
Browse files Browse the repository at this point in the history
- **Title Mapping**: Condensed `map` function for title formatting (line 143).
- **Year Parameter Check**: Added braces for clarity in `year` assignment (lines 263-265).
- **Streamable Check**: Enhanced logic to include series type condition (lines 471-475).
- **Formatting**: Adjusted long string concatenation for readability (lines 673-678).

Signed-off-by: Md. Sazzad Hossain Sharkar <md@szd.sh>
  • Loading branch information
SHSharkar committed Dec 24, 2024
1 parent 38dfbf1 commit 599c489
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ module.exports = function (config) {
(part) => !knownPatterns.some((regex) => regex.test(part)),
);
title = parts
.map(
(word) =>
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
)
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
.join(" ");
const displayName = year ? `${title} (${year})` : title;
return { title: displayName, searchTitle: title, year };
Expand Down Expand Up @@ -263,7 +260,9 @@ module.exports = function (config) {
t: searchTitle,
type: type === "movie" ? "movie" : "series",
};
if (year) params.y = year;
if (year) {
params.y = year;
}
const response = await axios.get("https://www.omdbapi.com/", {
params,
});
Expand Down Expand Up @@ -470,14 +469,15 @@ module.exports = function (config) {
let filteredDownloads = downloads.filter((d) => {
if (!d.filename) return false;
const ext = path.extname(d.filename).toLowerCase();
const isStreamable = d.streamable === 1;
const isSeriesDownload = isSeries(d.filename);
const seriesFlag = isSeries(d.filename);
const isStreamable =
d.streamable === 1 || (type === "series" && seriesFlag);
return (
VIDEO_EXTENSIONS.includes(ext) &&
!SAMPLE_FILE_REGEX.test(d.filename) &&
isStreamable &&
((type === "movie" && !isSeriesDownload) ||
(type === "series" && isSeriesDownload))
((type === "movie" && !seriesFlag) ||
(type === "series" && seriesFlag))
);
});
if (extra && extra.search) {
Expand Down Expand Up @@ -672,8 +672,12 @@ module.exports = function (config) {
}
}
const hostInfo = `File downloaded from: ${torrentInfo.host}`;
const fileSize = `File size: ${formatFileSize(torrentInfo.bytes)}`;
const addedDate = `Downloaded on: ${formatDate(torrentInfo.added)}`;
const fileSize = `File size: ${formatFileSize(
torrentInfo.bytes,
)}`;
const addedDate = `Downloaded on: ${formatDate(
torrentInfo.added,
)}`;
metaItem.description = [
metaItem.description,
hostInfo,
Expand Down

0 comments on commit 599c489

Please sign in to comment.