Exemplo n.º 1
0
/// Compares two VideoMetadata instances
bool VideoFilterSettings::meta_less_than(const VideoMetadata &lhs,
                                         const VideoMetadata &rhs,
                                         bool sort_ignores_case) const
{
    bool ret = false;
    switch (orderby)
    {
        case kOrderByTitle:
        {
            VideoMetadata::SortKey lhs_key;
            VideoMetadata::SortKey rhs_key;
            if (lhs.HasSortKey() && rhs.HasSortKey())
            {
                lhs_key = lhs.GetSortKey();
                rhs_key = rhs.GetSortKey();
            }
            else
            {
                lhs_key = VideoMetadata::GenerateDefaultSortKey(lhs,
                                                           sort_ignores_case);
                rhs_key = VideoMetadata::GenerateDefaultSortKey(rhs,
                                                           sort_ignores_case);
            }
            ret = lhs_key < rhs_key;
            break;
        }
        case kOrderBySeasonEp:
        {
            if ((lhs.GetSeason() == rhs.GetSeason())
                && (lhs.GetEpisode() == rhs.GetEpisode())
                && (lhs.GetSeason() == 0)
                && (rhs.GetSeason() == 0)
                && (lhs.GetEpisode() == 0)
                && (rhs.GetEpisode() == 0))
            {
                VideoMetadata::SortKey lhs_key;
                VideoMetadata::SortKey rhs_key;
                if (lhs.HasSortKey() && rhs.HasSortKey())
                {
                    lhs_key = lhs.GetSortKey();
                    rhs_key = rhs.GetSortKey();
                }
                else
                {
                    lhs_key = VideoMetadata::GenerateDefaultSortKey(lhs,
                                                               sort_ignores_case);
                    rhs_key = VideoMetadata::GenerateDefaultSortKey(rhs,
                                                               sort_ignores_case);
                }
                ret = lhs_key < rhs_key;
            }
            else if (lhs.GetSeason() == rhs.GetSeason()
                     && lhs.GetTitle() == rhs.GetTitle())
                ret = lhs.GetEpisode() < rhs.GetEpisode();
            else
                ret = lhs.GetSeason() < rhs.GetSeason();
            break;
        }
        case kOrderByYearDescending:
        {
            ret = lhs.GetYear() > rhs.GetYear();
            break;
        }
        case kOrderByUserRatingDescending:
        {
            ret = lhs.GetUserRating() > rhs.GetUserRating();
            break;
        }
        case kOrderByLength:
        {
            ret = lhs.GetLength() < rhs.GetLength();
            break;
        }
        case kOrderByFilename:
        {
            QString lhsfn(sort_ignores_case ?
                          lhs.GetFilename().toLower() : lhs.GetFilename());
            QString rhsfn(sort_ignores_case ?
                          rhs.GetFilename().toLower() : rhs.GetFilename());
            ret = QString::localeAwareCompare(lhsfn, rhsfn) < 0;
            break;
        }
        case kOrderByID:
        {
            ret = lhs.GetID() < rhs.GetID();
            break;
        }
        case kOrderByDateAddedDescending:
        {
            ret = lhs.GetInsertdate() > rhs.GetInsertdate();
            break;
        }
        default:
        {
            LOG(VB_GENERAL, LOG_ERR, QString("Error: unknown sort type %1")
                    .arg(orderby));
        }
    }

    return ret;
}
Exemplo n.º 2
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();
    }
}
Exemplo n.º 3
0
bool VideoFilterSettings::matches_filter(const VideoMetadata &mdata) const
{
    bool matches = true;

    //textfilter
    if (!textfilter.isEmpty())
    {
        matches = false;
        matches = matches || mdata.GetTitle().contains(textfilter, Qt::CaseInsensitive);
        matches = matches || mdata.GetSubtitle().contains(textfilter, Qt::CaseInsensitive);
        matches = matches || mdata.GetPlot().contains(textfilter, Qt::CaseInsensitive);
    }
    //search for season with optionally episode nr.
    if (matches && season != -1) {
        matches = season == mdata.GetSeason();
        matches = matches && (episode == -1 || episode == mdata.GetEpisode());
    }
    if (matches && insertdate.isValid()) {
        matches = mdata.GetInsertdate().isValid() && mdata.GetInsertdate() >= insertdate;
    }
    if (matches && genre != kGenreFilterAll)
    {
        matches = false;

        const VideoMetadata::genre_list &gl = mdata.GetGenres();
        for (VideoMetadata::genre_list::const_iterator p = gl.begin();
             p != gl.end(); ++p)
        {
            if ((matches = p->first == genre))
            {
                break;
            }
        }
    }

    if (matches && country != kCountryFilterAll)
    {
        matches = false;

        const VideoMetadata::country_list &cl = mdata.GetCountries();
        for (VideoMetadata::country_list::const_iterator p = cl.begin();
             p != cl.end(); ++p)
        {
            if ((matches = p->first == country))
            {
                break;
            }
        }
    }

    if (matches && cast != kCastFilterAll)
    {
        const VideoMetadata::cast_list &cl = mdata.GetCast();

        if (cast == kCastFilterUnknown && cl.size() == 0)
        {
            matches = true;
        }
        else
        {
            matches = false;

            for (VideoMetadata::cast_list::const_iterator p = cl.begin();
                 p != cl.end(); ++p)
            {
                if ((matches = p->first == cast))
                {
                    break;
                }
            }
        }
    }

    if (matches && category != kCategoryFilterAll)
    {
        matches = category == mdata.GetCategoryID();
    }

    if (matches && year != kYearFilterAll)
    {
        if (year == kYearFilterUnknown)
        {
            matches = (mdata.GetYear() == 0) ||
                    (mdata.GetYear() == VIDEO_YEAR_DEFAULT);
        }
        else
        {
            matches = year == mdata.GetYear();
        }
    }

    if (matches && runtime != kRuntimeFilterAll)
    {
        if (runtime == kRuntimeFilterUnknown)
        {
            matches = mdata.GetLength() == 0;
        }
        else
        {
            matches = runtime == (mdata.GetLength() / 30);
        }
    }

    if (matches && userrating != kUserRatingFilterAll)
    {
        matches = mdata.GetUserRating() >= userrating;
    }

    if (matches && browse != kBrowseFilterAll)
    {
        matches = mdata.GetBrowse() == browse;
    }

    if (matches && watched != kWatchedFilterAll)
    {
        matches = mdata.GetWatched() == watched;
    }

    if (matches && m_inetref != kInetRefFilterAll)
    {
        matches = mdata.GetInetRef() == VIDEO_INETREF_DEFAULT;
    }

    if (matches && m_coverfile != kCoverFileFilterAll)
    {
        matches = IsDefaultCoverFile(mdata.GetCoverFile());
    }

    if (matches && m_parental_level)
    {
        matches = (mdata.GetShowLevel() != ParentalLevel::plNone) &&
                (mdata.GetShowLevel() <= m_parental_level);
    }

    return matches;
}