🐛 Fix trakt scraper when season is missing
This commit is contained in:
parent
788efc9e90
commit
28bad45970
1 changed files with 19 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
|||
// ==UserScript==
|
||||
// @name Trakt Scraper
|
||||
// @namespace danielrayjones
|
||||
// @version 0.0.3
|
||||
// @version 0.0.4
|
||||
// @description Scrape lists of shows/movies from Trakt and download a JSON file
|
||||
// @author Dan Jones
|
||||
// @match https://trakt.tv/*
|
||||
|
|
@ -24,8 +24,9 @@
|
|||
|
||||
String.prototype.lpad = function(padString, length) {
|
||||
let str = this;
|
||||
while (str.length < length)
|
||||
while (str.length < length) {
|
||||
str = padString + str;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
|
|
@ -42,7 +43,6 @@
|
|||
|
||||
let series = $ep.data('show-id');
|
||||
let ep = $ep.data('episode-id');
|
||||
//let url = $ep.data('url');
|
||||
let url = $ep.children('[itemprop="url"]').attr('content');
|
||||
|
||||
let series_title = $series.children('[itemprop="name"]').attr('content');
|
||||
|
|
@ -60,8 +60,22 @@
|
|||
let ep_title = $ep_title.attr('content');
|
||||
let ep_number = $ep.find('[itemprop="episodeNumber"]').attr('content');
|
||||
let season_number = $ep.data('season-number');
|
||||
//let title = $ep.data('title');
|
||||
let title = series_title + " " + season_number + "x" + String(ep_number).lpad("0", 2) + ' "' + ep_title + '"';
|
||||
|
||||
if (!season_number) {
|
||||
let $title_ep = $ep.find('.main-title-sxe');
|
||||
if ($title_ep.length && $title_ep.text()) {
|
||||
let match = /([0-9+])x[0-9]+/.exec($title_ep.text());
|
||||
if (match) {
|
||||
season_number = match[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!season_number) {
|
||||
season_number = 0;
|
||||
}
|
||||
|
||||
let title = series_title + " " + String(season_number) + "x" + String(ep_number).lpad("0", 2) + ' "' + ep_title + '"';
|
||||
|
||||
let watched = watched_shows[series] ? watched_shows[series].e[ep] : null;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue