Ejemplo n.º 1
0
void MetadataFactory::OnVideoResult(MetadataLookup *lookup)
{
    if (!lookup)
       return;

    VideoMetadata *metadata = qVariantValue<VideoMetadata *>(lookup->GetData());

    if (!metadata)
        return;

    metadata->SetTitle(lookup->GetTitle());
    metadata->SetSubtitle(lookup->GetSubtitle());

    if (metadata->GetTagline().isEmpty())
        metadata->SetTagline(lookup->GetTagline());
    if (metadata->GetYear() == 1895 || metadata->GetYear() == 0)
        metadata->SetYear(lookup->GetYear());
    if (metadata->GetReleaseDate() == QDate())
        metadata->SetReleaseDate(lookup->GetReleaseDate());
    if (metadata->GetDirector() == VIDEO_DIRECTOR_UNKNOWN ||
        metadata->GetDirector().isEmpty())
    {
        QList<PersonInfo> director = lookup->GetPeople(kPersonDirector);
        if (director.count() > 0)
            metadata->SetDirector(director.takeFirst().name);
    }
    if (metadata->GetStudio().isEmpty())
    {
        QStringList studios = lookup->GetStudios();
        if (studios.count() > 0)
            metadata->SetStudio(studios.takeFirst());
    }
    if (metadata->GetPlot() == VIDEO_PLOT_DEFAULT ||
        metadata->GetPlot().isEmpty())
        metadata->SetPlot(lookup->GetDescription());
    if (metadata->GetUserRating() == 0)
        metadata->SetUserRating(lookup->GetUserRating());
    if (metadata->GetRating() == VIDEO_RATING_DEFAULT)
        metadata->SetRating(lookup->GetCertification());
    if (metadata->GetLength() == 0)
        metadata->SetLength(lookup->GetRuntime());
    if (metadata->GetSeason() == 0)
        metadata->SetSeason(lookup->GetSeason());
    if (metadata->GetEpisode() == 0)
        metadata->SetEpisode(lookup->GetEpisode());
    if (metadata->GetHomepage().isEmpty())
        metadata->SetHomepage(lookup->GetHomepage());

    metadata->SetInetRef(lookup->GetInetref());

//    m_d->AutomaticParentalAdjustment(metadata);

    // Cast
    QList<PersonInfo> actors = lookup->GetPeople(kPersonActor);
    QList<PersonInfo> gueststars = lookup->GetPeople(kPersonGuestStar);

    for (QList<PersonInfo>::const_iterator p = gueststars.begin();
        p != gueststars.end(); ++p)
    {
        actors.append(*p);
    }

    VideoMetadata::cast_list cast;
    QStringList cl;

    for (QList<PersonInfo>::const_iterator p = actors.begin();
        p != actors.end(); ++p)
    {
        cl.append((*p).name);
    }

    for (QStringList::const_iterator p = cl.begin();
        p != cl.end(); ++p)
    {
        QString cn = (*p).trimmed();
        if (cn.length())
        {
            cast.push_back(VideoMetadata::cast_list::
                        value_type(-1, cn));
        }
    }

    metadata->SetCast(cast);

    // Genres
    VideoMetadata::genre_list video_genres;
    QStringList genres = lookup->GetCategories();

    for (QStringList::const_iterator p = genres.begin();
        p != genres.end(); ++p)
    {
        QString genre_name = (*p).trimmed();
        if (genre_name.length())
        {
            video_genres.push_back(
                    VideoMetadata::genre_list::value_type(-1, genre_name));
        }
    }

    metadata->SetGenres(video_genres);

    // Countries
    VideoMetadata::country_list video_countries;
    QStringList countries = lookup->GetCountries();

    for (QStringList::const_iterator p = countries.begin();
        p != countries.end(); ++p)
    {
        QString country_name = (*p).trimmed();
        if (country_name.length())
        {
            video_countries.push_back(
                    VideoMetadata::country_list::value_type(-1,
                            country_name));
        }
    }

    metadata->SetCountries(video_countries);

    ArtworkMap map = lookup->GetDownloads();

    QUrl coverurl(map.value(kArtworkCoverart).url);
    if (!coverurl.path().isEmpty())
        metadata->SetCoverFile(coverurl.path().remove(0,1));

    QUrl fanarturl(map.value(kArtworkFanart).url);
    if (!fanarturl.path().isEmpty())
        metadata->SetFanart(fanarturl.path().remove(0,1));

    QUrl bannerurl(map.value(kArtworkBanner).url);
    if (!bannerurl.path().isEmpty())
        metadata->SetBanner(bannerurl.path().remove(0,1));

    QUrl sshoturl(map.value(kArtworkScreenshot).url);
    if (!sshoturl.path().isEmpty())
        metadata->SetScreenshot(sshoturl.path().remove(0,1));

    metadata->SetProcessed(true);
    metadata->UpdateDatabase();

    if (gCoreContext->HasGUI() && m_parent)
    {
        QCoreApplication::postEvent(m_parent,
            new MetadataFactorySingleResult(lookup));
    }
    else
    {
        lookup->deleteLater();
    }
}
Ejemplo n.º 2
0
bool SetArtwork(const QString &inetref,
                       uint season,
                       const QString &host,
                       const ArtworkMap map)
{
    if (inetref.isEmpty())
        return false;

    QString coverart, fanart, banner;

    QUrl coverurl(map.value(kArtworkCoverart).url);
    if (!coverurl.path().isEmpty())
    {
        coverart = coverurl.path();
        coverart = coverart.remove(0,1);
    }

    QUrl fanarturl(map.value(kArtworkFanart).url);
    if (!fanarturl.path().isEmpty())
    {
        fanart = fanarturl.path();
        fanart = fanart.remove(0,1);
    }

    QUrl bannerurl(map.value(kArtworkBanner).url);
    if (!bannerurl.path().isEmpty())
    {
        banner = bannerurl.path();
        banner = banner.remove(0,1);
    }

    // Have to delete the old row for this item

    MSqlQuery prequery(MSqlQuery::InitCon());
    prequery.prepare("DELETE FROM recordedartwork WHERE "
                     "inetref = :INETREF AND season = :SEASON;");

    prequery.bindValue(":INETREF", inetref);
    prequery.bindValue(":SEASON", season);

    if (!prequery.exec())
    {
        MythDB::DBError("SetArtwork DELETE FROM", prequery);
        return false;
    }

    // Now we can insert the new
    MSqlQuery query(MSqlQuery::InitCon());
    query.prepare("INSERT INTO recordedartwork(inetref,"
                  "season,host,coverart,fanart,banner) VALUES( "
                  ":INETREF, :SEASON, :HOST, :COVERART, "
                  ":FANART, :BANNER);");

    query.bindValue(":INETREF", inetref);
    query.bindValue(":SEASON", season);
    query.bindValue(":HOST", host);
    query.bindValue(":COVERART", coverart);
    query.bindValue(":FANART", fanart);
    query.bindValue(":BANNER", banner);

    if (!query.exec())
    {
        MythDB::DBError("SetArtwork INSERT INTO", query);
        return false;
    }

    return true;
}