File indexing completed on 2025-01-05 04:26:11

0001 /****************************************************************************************
0002  * Copyright (c) 2007-2008 Maximilian Kossick <maximilian.kossick@googlemail.com>       *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "core-impl/meta/stream/Stream.h"
0018 #include "core-impl/meta/stream/Stream_p.h"
0019 
0020 #include "core/support/Amarok.h"
0021 #include "core/support/Debug.h"
0022 #include "core/meta/Meta.h"
0023 #include "core-impl/meta/default/DefaultMetaTypes.h"
0024 #include "core-impl/support/UrlStatisticsStore.h"
0025 
0026 #include <QWeakPointer>
0027 #include <QString>
0028 
0029 using namespace MetaStream;
0030 
0031 Track::Track( const QUrl &url )
0032     : Meta::Track()
0033     , d( new Track::Private( this ) )
0034 {
0035     d->url = url;
0036     d->artistPtr = Meta::ArtistPtr( new StreamArtist( d ) );
0037     d->albumPtr = Meta::AlbumPtr( new StreamAlbum( d ) );
0038     d->genrePtr = Meta::GenrePtr( new StreamGenre( d ) );
0039     d->composerPtr = Meta::ComposerPtr( new Meta::DefaultComposer() );
0040     d->yearPtr = Meta::YearPtr( new Meta::DefaultYear() );
0041 }
0042 
0043 Track::~Track()
0044 {
0045     delete d;
0046 }
0047 
0048 QString
0049 Track::name() const
0050 {
0051     if( d->title.isEmpty() )
0052         return i18n( "Stream (%1)", d->url.url() );
0053     return d->title;
0054 }
0055 
0056 QUrl
0057 Track::playableUrl() const
0058 {
0059     return d->url;
0060 }
0061 
0062 QString
0063 Track::prettyUrl() const
0064 {
0065     return playableUrl().toDisplayString();
0066 }
0067 
0068 QString
0069 Track::uidUrl() const
0070 {
0071     return playableUrl().url();
0072 }
0073 
0074 QString
0075 Track::notPlayableReason() const
0076 {
0077     return networkNotPlayableReason();
0078 }
0079 
0080 Meta::AlbumPtr
0081 Track::album() const
0082 {
0083     return d->albumPtr;
0084 }
0085 
0086 Meta::ArtistPtr
0087 Track::artist() const
0088 {
0089     return d->artistPtr;
0090 }
0091 
0092 Meta::GenrePtr
0093 Track::genre() const
0094 {
0095     return d->genrePtr;
0096 }
0097 
0098 Meta::ComposerPtr
0099 Track::composer() const
0100 {
0101     return d->composerPtr;
0102 }
0103 
0104 Meta::YearPtr
0105 Track::year() const
0106 {
0107     return d->yearPtr;
0108 }
0109 
0110 qreal
0111 Track::bpm() const
0112 {
0113     return -1.0;
0114 }
0115 
0116 QString
0117 Track::comment() const
0118 {
0119     return d->comment;
0120 }
0121 
0122 int
0123 Track::trackNumber() const
0124 {
0125     return d->trackNumber;
0126 }
0127 
0128 int
0129 Track::discNumber() const
0130 {
0131     return 0;
0132 }
0133 
0134 qint64
0135 Track::length() const
0136 {
0137     return d->length;
0138 }
0139 
0140 int
0141 Track::filesize() const
0142 {
0143     return 0;
0144 }
0145 
0146 int
0147 Track::sampleRate() const
0148 {
0149     return 0;
0150 }
0151 
0152 int
0153 Track::bitrate() const
0154 {
0155     return 0;
0156 }
0157 
0158 void
0159 Track::finishedPlaying( double playedFraction )
0160 {
0161     // playedFraction will nearly always be 1, because EngineController updates length
0162     // just before calling finishedPlaying(). Mimic Last.fm scrobbling wrt min length
0163     // requirement, tracks shorter than 30s are often ads etc.
0164     if( length() < 30 * 1000 )
0165         return;
0166     Meta::Track::finishedPlaying( playedFraction );
0167 }
0168 
0169 QString
0170 Track::type() const
0171 {
0172     // don't localize. See EngineController quirks
0173     return QStringLiteral("stream");
0174 }
0175 
0176 void
0177 Track::setInitialInfo( const QString &artist, const QString &album, const QString &title,
0178                        qint64 length, int trackNumber )
0179 {
0180     if( d->artist.isEmpty() )
0181         d->artist = artist;
0182     if( d->album.isEmpty() )
0183         d->album = album;
0184     if( d->title.isEmpty() )
0185         d->title = title;
0186 
0187     if( d->length == 0 )
0188         d->length = length;
0189     if( d->trackNumber == 0 )
0190         d->trackNumber = trackNumber;
0191 }