Skip to content

Commit

Permalink
General package update + fixes for rad, son, read
Browse files Browse the repository at this point in the history
  • Loading branch information
petersem committed Feb 2, 2023
1 parent e053703 commit 38b0341
Show file tree
Hide file tree
Showing 6 changed files with 1,934 additions and 3,643 deletions.
5 changes: 3 additions & 2 deletions classes/arr/radarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Radarr {
async GetComingSoonRawData(startDate, endDate) {
let response;
try {
//console.log(this.radarrUrl + "/api/v3/calendar?unmonitored=false&apikey=" + this.radarrToken + "&start=" + startDate + "&end=" + endDate);
response = await axios
.get(
this.radarrUrl +
Expand Down Expand Up @@ -78,7 +79,7 @@ class Radarr {
releaseDate = digitalRelease.toISOString().split("T")[0];
}
else {
releaseDate = "No release date";
releaseDate = "No digital release date";
}
medCard.tagLine =
md.title + " (" + releaseDate + ")";
Expand Down Expand Up @@ -194,7 +195,7 @@ class Radarr {
// }

// add media card to array, only if not released yet (caters to old movies being released digitally)
if (md.hasFile == false && md.status != "released" && !await util.isEmpty(md.digitalRelease) ) {
if (md.hasFile == false && md.status != "released"){ //&& !await util.isEmpty(md.digitalRelease) ) {
csrCards.push(medCard);
}

Expand Down
54 changes: 48 additions & 6 deletions classes/arr/readarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Readarr {
* @returns {Promise<object>} json results - results of search
*/
async GetComingSoonRawData(startDate, endDate) {
console.log(this.readarrUrl + "/api/v1/calendar?unmonitored=false&apikey=" + this.readarrToken + "&start=" + startDate + "&end=" + endDate);
let response;
try {
response = await axios
Expand All @@ -101,6 +102,34 @@ class Readarr {
return response;
}

/**
* @desc Gets book info
* @param {integer} bookId - The ID of the book in readarr
* @returns {Promise<object>} json results - results of search
*/
async GetBookRawData(bookId) {
console.log(this.readarrUrl + "/api/v1/book/" + bookId + "?apikey=" + this.readarrToken);
let response;
try {
response = await axios
.get(
this.readarrUrl +
"/api/v1/book/" +
bookId +
"?apikey=" +
this.readarrToken
)
.catch((err) => {
throw err;
});
} catch (err) {
let d = new Date();
console.log(d.toLocaleString() + " *Readarr - Get book data:", err.message);
throw err;
}
return response;
}

/**
* @desc Get books coming soon data and formats into mediaCard array
* @param {string} startDate - in yyyy-mm-dd format - Generally todays date
Expand All @@ -127,6 +156,18 @@ class Readarr {
await raw.data.reduce(async (memo, md) => {
await memo;
const medCard = new mediaCard();

// get book info
let rawBook;
try {
rawBook = await this.GetBookRawData(md.id);
}
catch (err) {
let d = new Date();
console.log(d.toLocaleString() + " *Readarr - Get book Data: " + err);
throw err;
}

let bookReleaseDate;
if (!await util.isEmpty(md.releaseDate)) {
let releaseDate = new Date(md.releaseDate);
Expand All @@ -135,9 +176,9 @@ class Readarr {
else {
bookReleaseDate = "No release date";
}
let series = ""
let series = "";
if (md.seriesTitle !== null && md.seriesTitle.length > 0) {
series = ", " + md.seriesTitle
series = ", " + md.seriesTitle;
}
medCard.tagLine =
md.title + series + " (" + bookReleaseDate + ")";
Expand All @@ -148,14 +189,14 @@ class Readarr {
medCard.summary = await util.emptyIfNull(md.overview);
medCard.mediaType = "ebook";
medCard.cardType = cType.CardTypeEnum.EBook;
medCard.studio = md.author.authorName;
medCard.studio = rawBook.data.author.authorName;
if (Math.round(md.ratings.value * 20) !== 0) medCard.rating = Math.round(md.ratings.value * 20) + "%";
medCard.theme = "";
medCard.pageCount = md.pageCount;

// try to get book cover
let cover = 'none';
if(md.editions[0].images[0] !== undefined){
if(md.images[0] !== undefined && md.images[0].url.includes('lastWrite')==true ){
cover = this.readarrUrl + "/api/v1/mediacover/book/" + md.id + "/cover.jpg?apikey=" + this.readarrToken;
}
else{
Expand All @@ -171,10 +212,11 @@ class Readarr {
// cache poster image
let fileName = md.foreignBookId + ".jpg";
let url = cover;
await core.CacheImage(url, fileName);
let dlResult;
dlResult = await core.CacheImage(url, fileName);
medCard.posterURL = "/imagecache/" + fileName;
}
if(hasArt='true') medCard.posterArtURL = "/images/german.png";
if(hasArt=='true') medCard.posterArtURL = "/images/german.png";
medCard.posterAR = 1.47;

if (md.grabbed == false && !await util.isEmpty(md.releaseDate)) {
Expand Down
90 changes: 67 additions & 23 deletions classes/arr/sonarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ class Sonarr {
try {
response = await axios
.get(
this.sonarrUrl +
"/api/calendar?apikey=" +
this.sonarrToken +
"&start=" +
startDate +
"&end=" +
endDate
this.sonarrUrl +
"/api/v3/calendar?apikey=" +
this.sonarrToken +
"&start=" +
startDate +
"&end=" + endDate
)
.catch((err) => {
throw err;
Expand All @@ -49,8 +48,40 @@ class Sonarr {
);
throw err;
}
return await response;
}

/**
* @desc Gets the tv titles that fall within the range specified
* @param {object} calendarEpisode - calendar instance of episode
* @returns {Promise<object>} json results - results of search
*/
async GetSeriesRawData(seriesID) {
let response;

return response;
// call sonarr API and return results
try {
response = await axios
.get(
this.sonarrUrl +
"/api/v3/series/" +
seriesID +
"?apikey=" +
this.sonarrToken
)
.catch((err) => {
throw err;
});
} catch (err) {
// displpay error if call failed
let d = new Date();
console.log(
d.toLocaleString() + " *Sonarr - Get episode data:",
err.message
);
throw err;
}
return await response;
}

/**
Expand All @@ -76,6 +107,19 @@ class Sonarr {
// move through results and populate media cards
await raw.data.reduce(async (memo, md) => {
await memo;

// get series raw data
let rawSeries;
try {
rawSeries = await this.GetSeriesRawData(md.seriesId);
} catch (err) {
let d = new Date();
console.log(d.toLocaleString() + " *Sonarr - Get series raw data: " + err);
throw err;
}


// populate cards
const medCard = new mediaCard();

medCard.tagLine =
Expand All @@ -89,14 +133,14 @@ class Sonarr {
md.airDate +
")";
medCard.title = md.title;
medCard.DBID = md.series.tvdbId;
medCard.year = md.series.year;
medCard.runTime = md.series.runtime;
medCard.genre = md.series.genres;
medCard.summary = await util.emptyIfNull(md.overview);
medCard.DBID = rawSeries.data.tvdbId;
medCard.year = md.airDate;
medCard.runTime = rawSeries.data.runtime;
medCard.genre = rawSeries.data.genres;
medCard.summary = await util.emptyIfNull(rawSeries.data.overview);
medCard.mediaType = "episode";
medCard.cardType = cType.CardTypeEnum.ComingSoon;
medCard.network = md.series.network;
medCard.network = rawSeries.data.network;

let fileName;
// dont bother to download if only looking for premiers
Expand All @@ -106,18 +150,18 @@ class Sonarr {
// only downlad mp3 if playThemes enabled
if (playThemes == "true") {
// cache mp3 file
let mp3 = md.series.tvdbId + ".mp3";
let mp3 = rawSeries.data.tvdbId + ".mp3";
await core.CacheMP3(mp3);
medCard.theme = "/mp3cache/" + mp3;
}

let url;
// cache poster
fileName = md.series.tvdbId + ".jpg";
fileName = rawSeries.data.tvdbId + ".jpg";
// check art exists
md.series.images.forEach(i => {
rawSeries.data.images.forEach(i => {
if(i.coverType == "poster"){
url = i.url;
url = i.remoteUrl;
}
});
if (url !== undefined) {
Expand All @@ -129,11 +173,11 @@ class Sonarr {

// cache art image
if(hasArt=='true'){
fileName = md.series.tvdbId + "-art.jpg";
fileName = rawSeries.data.tvdbId + "-art.jpg";
// check art exists
md.series.images.forEach(i => {
rawSeries.data.images.forEach(i => {
if(i.coverType == "fanart"){
url = i.url;
url = i.remoteUrl;
}
});
if (url !== undefined) {
Expand All @@ -145,8 +189,8 @@ class Sonarr {

// content rating and colour
let contentRating = "NR";
if (!(await util.isEmpty(md.series.certification))) {
contentRating = md.series.certification;
if (!(await util.isEmpty(rawSeries.data.certification))) {
contentRating = rawSeries.data.certification;
}
medCard.contentRating = contentRating;

Expand Down
3 changes: 2 additions & 1 deletion classes/core/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Cache {
*/
static async CacheImage(url, fileName) {
const savePath = "./saved/imagecache/" + fileName;
const result = await this.download(url, savePath, fileName)
const result = await this.download(url, savePath, fileName);
return result;
}

Expand Down Expand Up @@ -62,6 +62,7 @@ class Cache {
const download = (url, savePath, callback) => {
// request.head(url, (err, res, body) => {
request(url, function (err, res, body) {
//console.log(res.rawHeaders[1]);
// check to see if no content, then if mp3, throw exception
// var size = parseInt(res.headers["content-length"], 10);
// // console.log("file size: " + size);
Expand Down
Loading

0 comments on commit 38b0341

Please sign in to comment.