Skip to content

Commit

Permalink
feat(movies): Allow multiple TV show link fields
Browse files Browse the repository at this point in the history
In a previous commit, we added the `<showlink>` field.
This commit adds support for multiple such fields.
  • Loading branch information
bugwelle committed Jun 22, 2024
1 parent fa2a9ed commit 3e3ccc5
Show file tree
Hide file tree
Showing 39 changed files with 228 additions and 726 deletions.
2 changes: 1 addition & 1 deletion src/cli/info/ScraperFeatureTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MovieScraperFeatureTable
{MovieScraperInfo::CdArt, "CdArt"},
{MovieScraperInfo::ClearArt, "ClearArt"},
{MovieScraperInfo::Banner, "Banner"},
{MovieScraperInfo::TvShowLink, "TV Show Link"},
{MovieScraperInfo::TvShowLinks, "TV Show Links"},
{MovieScraperInfo::Thumb, "Thumb"}};
};

Expand Down
16 changes: 8 additions & 8 deletions src/data/movie/Movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Movie::clear()
<< MovieScraperInfo::Banner //
<< MovieScraperInfo::Thumb //
<< MovieScraperInfo::ClearArt //
<< MovieScraperInfo::TvShowLink;
<< MovieScraperInfo::TvShowLinks;
clear(infos);
m_nfoContent.clear();
}
Expand Down Expand Up @@ -135,8 +135,8 @@ void Movie::clear(QSet<MovieScraperInfo> infos)
if (infos.contains(MovieScraperInfo::Trailer)) {
m_trailer.clear();
}
if (infos.contains(MovieScraperInfo::TvShowLink)) {
m_tvShowLink.clear();
if (infos.contains(MovieScraperInfo::TvShowLinks)) {
m_tvShowLinks.clear();
}
if (infos.contains(MovieScraperInfo::Certification)) {
m_certification = Certification::NoCertification;
Expand Down Expand Up @@ -190,7 +190,7 @@ void Movie::exportTo(Movie::Exporter& exporter) const
exporter.exportCountries(m_countries);
exporter.exportStudios(m_studios);
exporter.exportTrailer(m_trailer);
exporter.exportTvShowLink(m_tvShowLink);
exporter.exportTvShowLinks(m_tvShowLinks);
exporter.exportPlaycount(m_playcount);
exporter.exportLastPlayed(m_lastPlayed);
exporter.exportDateAdded(m_dateAdded);
Expand Down Expand Up @@ -388,9 +388,9 @@ QUrl Movie::trailer() const
return m_trailer;
}

QString Movie::tvShowLink() const
QStringList Movie::tvShowLinks() const
{
return m_tvShowLink;
return m_tvShowLinks;
}

const Actors& Movie::actors() const
Expand Down Expand Up @@ -718,9 +718,9 @@ void Movie::setTrailer(QUrl trailer)
setChanged(true);
}

void Movie::setTvShowLink(QString tvShowLink)
void Movie::setTvShowLinks(QStringList tvShowLinks)
{
m_tvShowLink = std::move(tvShowLink);
m_tvShowLinks = std::move(tvShowLinks);
setChanged(true);
}

Expand Down
8 changes: 4 additions & 4 deletions src/data/movie/Movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Movie : public QObject
QStringList tags() const;
QVector<QString*> studiosPointer();
QUrl trailer() const;
QString tvShowLink() const;
QStringList tvShowLinks() const;

const Actors& actors() const;
Actors& actors();
Expand Down Expand Up @@ -120,7 +120,7 @@ class Movie : public QObject
void addStudio(QString studio);
void addTag(QString tag);
void setTrailer(QUrl trailer);
void setTvShowLink(QString tvShowLink);
void setTvShowLinks(QStringList tvShowLinks);
void setActors(QVector<Actor> actors);
void addActor(Actor actor);
void addGenre(QString genre);
Expand Down Expand Up @@ -216,7 +216,7 @@ class Movie : public QObject
virtual void exportStudios(const QStringList& studios) = 0;
virtual void exportTags(const QStringList& tags) = 0;
virtual void exportTrailer(const QUrl& trailer) = 0;
virtual void exportTvShowLink(const QString& tvShowLink) = 0;
virtual void exportTvShowLinks(const QStringList& tvShowLinks) = 0;
virtual void exportPlaycount(int playcount) = 0;
virtual void exportLastPlayed(const QDateTime& lastPlayed) = 0;
virtual void exportMovieSet(const MovieSet& set) = 0;
Expand Down Expand Up @@ -258,7 +258,7 @@ private slots:
QStringList m_studios;
QStringList m_tags;
QUrl m_trailer;
QString m_tvShowLink;
QStringList m_tvShowLinks;
int m_playcount = 0;
QDateTime m_lastPlayed;
ImdbId m_imdbId;
Expand Down
4 changes: 2 additions & 2 deletions src/export/CsvExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void CsvMovieExport::exportMovies(const QVector<Movie*>& movies, std::function<v
{s(Field::PlayCount), QString::number(movie->playcount())},
{s(Field::LastPlayed), movie->lastPlayed().toString(Qt::ISODate)},
{s(Field::MovieSet), movie->set().name},
{s(Field::TvShowLink), movie->tvShowLink()},
{s(Field::TvShowLinks), movie->tvShowLinks().join(", ")},
{s(Field::Directory), dirFromFileList(movie->files())},
{s(Field::Filenames), filesToString(movie->files())},
{s(Field::LastModified), movie->fileLastModified().toString(Qt::ISODate)},
Expand Down Expand Up @@ -205,7 +205,7 @@ QString CsvMovieExport::fieldToString(Field field)
case Field::PlayCount: return "movie_playcount";
case Field::LastPlayed: return "movie_last_played";
case Field::MovieSet: return "movie_set";
case Field::TvShowLink: return "tv_show_link";
case Field::TvShowLinks: return "tv_show_links";
case Field::Directory: return "movie_directory";
case Field::Filenames: return "movie_filenames";
case Field::LastModified: return "movie_date_added";
Expand Down
2 changes: 1 addition & 1 deletion src/export/CsvExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CsvMovieExport final : public CsvMediaExport
Type, // @since 2.8.17
LastModified, // @since 2.8.17
WikidataId, // @since 2.10.1
TvShowLink, // @since 2.10.8
TvShowLinks, // @since 2.10.8
};

public:
Expand Down
11 changes: 10 additions & 1 deletion src/media_center/kodi/MovieXmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ bool MovieXmlReader::parseNfoDom(QDomDocument domDoc)
tagParsers.insert("plot", &MovieXmlReader::simpleString<&Movie::setOverview>);
tagParsers.insert("outline", &MovieXmlReader::simpleString<&Movie::setOutline>);
tagParsers.insert("tagline", &MovieXmlReader::simpleString<&Movie::setTagline>);
tagParsers.insert("showlink", &MovieXmlReader::simpleString<&Movie::setTvShowLink>);
tagParsers.insert("set", &MovieXmlReader::movieSet);
tagParsers.insert("actor", &MovieXmlReader::movieActor);
tagParsers.insert("thumb", &MovieXmlReader::movieThumbnail);
Expand Down Expand Up @@ -135,6 +134,16 @@ bool MovieXmlReader::parseNfoDom(QDomDocument domDoc)
}
m_movie.setWriter(writers.join(", "));

QStringList tvShowLinks;
for (int i = 0, n = domDoc.elementsByTagName("showlink").size(); i < n; i++) {
const auto showlink =
domDoc.elementsByTagName("showlink").at(i).toElement().text().split(",", ElchSplitBehavior::SkipEmptyParts);
for (const QString& link : showlink) {
tvShowLinks.append(link.trimmed());
}
}
m_movie.setTvShowLinks(tvShowLinks);

QStringList directors;
for (int i = 0, n = domDoc.elementsByTagName("director").size(); i < n; i++) {
const auto directorsFound =
Expand Down
5 changes: 1 addition & 4 deletions src/media_center/kodi/MovieXmlWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ QByteArray MovieXmlWriterGeneric::getMovieXml(bool testMode)
for (const QString& credit : writersWithWhiteSpace) {
writers << credit.trimmed();
}

KodiXml::writeStringsAsOneTagEach(xml, "credits", writers);

QStringList directors;
Expand All @@ -142,9 +141,7 @@ QByteArray MovieXmlWriterGeneric::getMovieXml(bool testMode)

writeActors(xml, m_movie.actors());

if (!m_movie.tvShowLink().isEmpty()) {
xml.writeTextElement("showlink", m_movie.tvShowLink());
}
KodiXml::writeStringsAsOneTagEach(xml, "showlink", m_movie.tvShowLinks());

// <resume>
// <position>0.000000</position>
Expand Down
4 changes: 2 additions & 2 deletions src/scrapers/ScraperInfos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ QString scraper::movieScraperDetailToString(MovieScraperInfo detail)
case MovieScraperInfo::ClearArt: return QStringLiteral("clear-art");
case MovieScraperInfo::Banner: return QStringLiteral("banner");
case MovieScraperInfo::Thumb: return QStringLiteral("thumb");
case MovieScraperInfo::TvShowLink: return QStringLiteral("showlink");
case MovieScraperInfo::TvShowLinks: return QStringLiteral("showlinks");
}
MediaElch_Debug_Unreachable();
return QStringLiteral("unknown");
Expand Down Expand Up @@ -115,7 +115,7 @@ QSet<MovieScraperInfo> scraper::allMovieScraperInfos()
MovieScraperInfo::ClearArt,
MovieScraperInfo::Banner,
MovieScraperInfo::Thumb,
MovieScraperInfo::TvShowLink,
MovieScraperInfo::TvShowLinks,
MovieScraperInfo::First};
}

Expand Down
2 changes: 1 addition & 1 deletion src/scrapers/ScraperInfos.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum class MovieScraperInfo : int
ClearArt = 23,
Banner = 24,
Thumb = 25,
TvShowLink = 26, // not used for scraping
TvShowLinks = 26, // not used for scraping
First = 1,
Last = 26
};
Expand Down
4 changes: 2 additions & 2 deletions src/scrapers/movie/MovieMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void copyDetailToMovie(Movie& target,
target.setTrailer(source.trailer());
break;
}
case MovieScraperInfo::TvShowLink: {
target.setTvShowLink(source.tvShowLink());
case MovieScraperInfo::TvShowLinks: {
target.setTvShowLinks(source.tvShowLinks());
break;
}
case MovieScraperInfo::Overview: {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/export/CsvExportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void CsvExportDialog::initializeItems()
addField(Field::PlayCount, tr("Playcount"));
addField(Field::LastPlayed, tr("Last played"));
addField(Field::MovieSet, tr("Movie Set"));
addField(Field::TvShowLink, tr("TV Show Link"));
addField(Field::TvShowLinks, tr("TV Show Links"));
addField(Field::Directory, tr("Directory"));
addField(Field::Filenames, tr("Filename(s)"));
addField(Field::LastModified, tr("Last Modified Date"));
Expand Down
10 changes: 6 additions & 4 deletions src/ui/movies/MovieWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ui/notifications/NotificationBox.h"
#include "ui/small_widgets/ClosableImage.h"
#include "ui/trailer/TrailerDialog.h"
#include "utils/Containers.h"

#include <QDesktopServices>
#include <QDoubleValidator>
Expand Down Expand Up @@ -184,7 +185,7 @@ MovieWidget::MovieWidget(QWidget* parent) : QWidget(parent), ui(new Ui::MovieWid
connect(ui->playcount, elchOverload<int>(&QSpinBox::valueChanged), this, &MovieWidget::onPlayCountChange);

connect(ui->trailer, &QLineEdit::textEdited, this, &MovieWidget::onTrailerChange);
connect(ui->tvShowLink, &QLineEdit::textEdited, this, &MovieWidget::onTvShowLinkChange);
connect(ui->tvShowLink, &QLineEdit::textEdited, this, &MovieWidget::onTvShowLinksChange);
connect(ui->certification, &QComboBox::editTextChanged, this, &MovieWidget::onCertificationChange);
connect(ui->set, &QComboBox::editTextChanged, this, &MovieWidget::onSetChange);
connect(ui->badgeWatched, &Badge::clicked, this, &MovieWidget::onWatchedClicked);
Expand Down Expand Up @@ -585,7 +586,7 @@ void MovieWidget::updateMovieInfo()
ui->releaseDate->setDate(m_movie->released());
ui->runtime->setValue(static_cast<int>(m_movie->runtime().count()));
ui->trailer->setText(m_movie->trailer().toString());
ui->tvShowLink->setText(m_movie->tvShowLink());
ui->tvShowLink->setText(m_movie->tvShowLinks().join(", "));
ui->playcount->setValue(m_movie->playcount());
ui->lastPlayed->setDateTime(m_movie->lastPlayed());
ui->overview->setPlainText(m_movie->overview());
Expand Down Expand Up @@ -1287,12 +1288,13 @@ void MovieWidget::onTrailerChange(QString text)
ui->buttonRevert->setVisible(true);
}

void MovieWidget::onTvShowLinkChange(QString text)
void MovieWidget::onTvShowLinksChange(QString text)
{
if (m_movie == nullptr) {
return;
}
m_movie->setTvShowLink(text);
QStringList links = mediaelch::split_string_trimmed(text, ",");
m_movie->setTvShowLinks(links);
ui->buttonRevert->setVisible(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/movies/MovieWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private slots:
void onRuntimeChange(int value);
void onCertificationChange(QString text);
void onTrailerChange(QString text);
void onTvShowLinkChange(QString text);
void onTvShowLinksChange(QString text);
void onWatchedClicked();
void onPlayCountChange(int value);
void onLastWatchedChange(QDateTime dateTime);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/settings/ScraperSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ QString ScraperSettingsWidget::titleForMovieScraperInfo(MovieScraperInfo info)
case MovieScraperInfo::ClearArt: return tr("Clear Art");
case MovieScraperInfo::Banner: return tr("Banner");
case MovieScraperInfo::Thumb: return tr("Thumb");
case MovieScraperInfo::TvShowLink: return tr("TV Show Link");
case MovieScraperInfo::TvShowLinks: return tr("TV Show Links");
default: return tr("Unsupported");
}
}
23 changes: 22 additions & 1 deletion src/utils/Containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

namespace mediaelch {

// empty on purpose
QStringList split_string_trimmed(const QString& str, const QString& delimiter)
{
QStringList entries = str.split(delimiter);

for (QString& entry : entries) {
entry = entry.trimmed();
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
entries.removeIf([](const QString& entry) { return entry.isEmpty(); });
#else
for (auto i = 0; i < entries.length(); ++i) {
if (entries[i].isEmpty()) {
entries.removeAt(i);
--i; // entry was removed, hence i now contains the next value
}
}
#endif

return entries;
}


} // namespace mediaelch
3 changes: 3 additions & 0 deletions src/utils/Containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ QVector<T> setToVector(const QSet<T>& set)
#endif
}

/// Split a string at the given delimiter and trim all entries.
/// Removes empty entries.
QStringList split_string_trimmed(const QString& str, const QString& delimiter);

} // namespace mediaelch
5 changes: 4 additions & 1 deletion test/helpers/reference_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ class MovieTestExporter final : public Movie::Exporter
void exportStudios(const QStringList& studios) override { writeToReference(m_out, "studios", studios); }
void exportTags(const QStringList& tags) override { writeToReference(m_out, "tags", tags); }
void exportTrailer(const QUrl& trailer) override { writeToReference(m_out, "trailer", trailer); }
void exportTvShowLink(const QString& tvShowLink) override { writeToReference(m_out, "showlink", tvShowLink); }
void exportTvShowLinks(const QStringList& tvShowLinks) override
{
writeToReference(m_out, "showlink", tvShowLinks);
}
void exportPlaycount(int playcount) override { writeToReference(m_out, "playcount", playcount); }
void exportLastPlayed(const QDateTime& lastPlayed) override { writeToReference(m_out, "lastPlayed", lastPlayed); }
void exportMovieSet(const MovieSet& set) override
Expand Down
2 changes: 1 addition & 1 deletion test/integration/media_center/testKodi_v18_movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ TEST_CASE("Movie XML writer for Kodi v18", "[data][movie][kodi][nfo]")
movie.setReleased(QDate::fromString("2016-03-09", Qt::ISODate));
movie.addStudio("Summit Entertainment");
movie.setTrailer(QUrl("TmovieFc19"));
movie.setTvShowLink("Some Allegiant show");
movie.setTvShowLinks({"Some Allegiant show 1", "Some Allegiant show 2"});
// requires that setFiles() was called
movie.streamDetails()->setVideoDetail(StreamDetails::VideoDetails::Codec, "h264");
movie.streamDetails()->setVideoDetail(StreamDetails::VideoDetails::Aspect, "1.777778");
Expand Down
3 changes: 2 additions & 1 deletion test/resources/movie/kodi_v18_movie_all.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
<order>1</order>
<thumb>http://image.tmdb.org/t/p/original/hLNSoQ3gc52X5VVb172yO3CuUEq.jpg</thumb>
</actor>
<showlink>Some Allegiant show</showlink>
<showlink>Some Allegiant show 1</showlink>
<showlink>Some Allegiant show 2</showlink>
<resume>
<position>0</position>
<total>0</total>
Expand Down
2 changes: 1 addition & 1 deletion test/resources/scrapers/ade/DVD-Magic-Mike-1745335.ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ countries: (N=0)
studios: (N=1)
- Wicked Pictures
trailer:
showlink:
showlink: (N=0)
playcount: 0
lastPlayed: <not set or invalid>
dateAdded: <not set or invalid>
Expand Down
2 changes: 1 addition & 1 deletion test/resources/scrapers/ade/VOD-50-Shades-1670507.ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ countries: (N=0)
studios: (N=1)
- Pure XXX Films
trailer:
showlink:
showlink: (N=0)
playcount: 0
lastPlayed: <not set or invalid>
dateAdded: <not set or invalid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ countries: (N=0)
studios: (N=1)
- Innocent High
trailer:
showlink:
showlink: (N=0)
playcount: 0
lastPlayed: <not set or invalid>
dateAdded: <not set or invalid>
Expand Down
2 changes: 1 addition & 1 deletion test/resources/scrapers/aebn/Magic-Mike-188623.ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ countries: (N=0)
studios: (N=1)
- Wicked Pictures
trailer:
showlink:
showlink: (N=0)
playcount: 0
lastPlayed: <not set or invalid>
dateAdded: <not set or invalid>
Expand Down
2 changes: 1 addition & 1 deletion test/resources/scrapers/fernsehserien_de/Scrubs.ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ actors: (N>5)
imageHasChanged: false
- id:
name: Judy Reyes
role: Carla Espinosa (171 Folgen, 2001–2010)
role: Carla Espinosa (174 Folgen, 2001–2010)
thumb: https://bilder.fernsehserien.de/gfx/person_1000/j/judy-reyes.jpg
order: 5
imageHasChanged: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tags: (N=0)
countries: (N=0)
studios: (N=0)
trailer:
showlink:
showlink: (N=0)
playcount: 0
lastPlayed: <not set or invalid>
dateAdded: <not set or invalid>
Expand Down
Loading

0 comments on commit 3e3ccc5

Please sign in to comment.