From 28bad459705159b5a6d2ad4d4c86a6a472fdba2a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 10 Feb 2020 15:57:46 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20trakt=20scraper=20when=20s?= =?UTF-8?q?eason=20is=20missing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trakt.scraper.user.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/trakt.scraper.user.js b/trakt.scraper.user.js index a2d78dc..56e3714 100644 --- a/trakt.scraper.user.js +++ b/trakt.scraper.user.js @@ -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;