VLCPlaylistTableViewCell.m 23.5 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCPlaylistTableViewCell.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Gleb Pinigin <gpinigin # gmail.com>
10
 *          Carola Nitz <nitz.carola #googlemail.com>
11 12 13
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
14 15

#import "VLCPlaylistTableViewCell.h"
16
#import "VLCLinearProgressIndicator.h"
17
#import "VLCThumbnailsCache.h"
18
#import "NSString+SupportedMedia.h"
19

20 21 22 23 24 25 26
@interface VLCPlaylistTableViewCell ()
{
    UILongPressGestureRecognizer *_longPress;
}

@end

27 28
@implementation VLCPlaylistTableViewCell

29 30 31 32 33
- (void)dealloc
{
    [self _removeObserver];
}

34 35
+ (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
{
36
    NSArray *nibContentArray;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
37
    nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistTableViewCell" owner:nil options:nil];
38 39
    NSAssert([nibContentArray count] == 1, @"meh");
    NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
40
    VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
41
    cell.multipleSelectionBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
42
    cell.metaDataLabel.hidden = YES;
43 44 45 46

    return cell;
}

47 48 49 50 51 52
- (void)setNeedsDisplay
{
    [self collapsWithAnimation:NO];
    [super setNeedsDisplay];
}

53 54
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
55
    [self _updatedDisplayedInformationForKeyPath:keyPath];
56 57
}

58 59
- (void)_removeObserver
{
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    @try {
        if ([_mediaObject isKindOfClass:[MLLabel class]]) {
            [_mediaObject removeObserver:self forKeyPath:@"files"];
            [_mediaObject removeObserver:self forKeyPath:@"name"];
        } else if ([_mediaObject isKindOfClass:[MLShow class]])
            [_mediaObject removeObserver:self forKeyPath:@"episodes"];
        else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
            [_mediaObject removeObserver:self forKeyPath:@"name"];
            [_mediaObject removeObserver:self forKeyPath:@"files"];
            [_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
            [_mediaObject removeObserver:self forKeyPath:@"unread"];
        } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
            [_mediaObject removeObserver:self forKeyPath:@"name"];
            [_mediaObject removeObserver:self forKeyPath:@"tracks"];
        } else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
            [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
            [_mediaObject removeObserver:self forKeyPath:@"artist"];
            [_mediaObject removeObserver:self forKeyPath:@"title"];
            [_mediaObject removeObserver:self forKeyPath:@"files"];
79
            MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
            if (anyFileFromTrack)
                [anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
        } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
            [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
            [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
            [_mediaObject removeObserver:self forKeyPath:@"duration"];
            [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
            [_mediaObject removeObserver:self forKeyPath:@"title"];
            [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
            [_mediaObject removeObserver:self forKeyPath:@"unread"];
            [_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
            [_mediaObject removeObserver:self forKeyPath:@"album"];
            [_mediaObject removeObserver:self forKeyPath:@"artist"];
            [_mediaObject removeObserver:self forKeyPath:@"genre"];
            [[NSNotificationCenter defaultCenter] removeObserver:self];
            [(MLFile*)_mediaObject didHide];
        }
    }
    @catch (NSException *exception) {
        APLog(@"removing observer failed");
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    }
}

- (void)_addObserver
{
    if ([_mediaObject isKindOfClass:[MLLabel class]]) {
        [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLShow class]])
        [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
    else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"tracks" options:0 context:nil];
118 119 120 121 122
    } else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
123
        MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
124 125
        if (anyFileFromTrack)
            [anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
126 127 128 129 130 131 132 133 134 135 136 137
    } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
        [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
138 139 140 141
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(thumbnailWasUpdated:)
                                                     name:MLFileThumbnailWasUpdated
                                                   object:nil];
142 143 144 145
        [(MLFile*)_mediaObject willDisplay];
    }
}

146 147 148
- (void)setMediaObject:(MLFile *)mediaObject
{
    if (_mediaObject != mediaObject) {
149
        [self _removeObserver];
150 151

        _mediaObject = mediaObject;
152 153
        // prevent the cell from recycling the current snap for random contents
        self.thumbnailView.image = nil;
154

155
        [self _addObserver];
156 157
    }

158
    [self collapsWithAnimation:NO];
159
    [self _updatedDisplayedInformationForKeyPath:nil];
160 161
}

162 163 164
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
165
    [self _updatedDisplayedInformationForKeyPath:@"editing"];
166

Felix Paul Kühne's avatar
Felix Paul Kühne committed
167 168 169 170 171 172 173
    if (editing) {
        if (_longPress)
            [self removeGestureRecognizer:_longPress];
    } else {
        if (!_longPress)
            _longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
        [self addGestureRecognizer:_longPress];
174
    }
175 176
}

177
- (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
178
{
179
    self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
180
    if ([self.mediaObject isKindOfClass:[MLFile class]]) {
181
        [self _configureForMLFile:(MLFile *)self.mediaObject];
182
    } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
183
        [self _configureForFolder:(MLLabel *)self.mediaObject];
184
    } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
185
        [self _configureForAlbum:(MLAlbum *)self.mediaObject];
186
    } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
187
        [self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
188 189 190
        if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
        }
191
    } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
192

193
        MLShow *mediaObject = (MLShow *)self.mediaObject;
194
        [self _configureForShow:mediaObject];
195

196 197
        if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
198
        }
199
    } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
200 201 202 203
        [self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
    }
    if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
        self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
204
    }
205 206 207
    [self setNeedsDisplay];
}

208 209
+ (CGFloat)heightOfCell
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
210
    return 90.;
211 212
}

213 214
#pragma mark - presentation

215
- (void)_configureForShow:(MLShow *)show
216 217 218
{
    self.titleLabel.text = show.name;
    NSUInteger count = show.episodes.count;
219 220 221
    NSString *string = @"";
    if (show.releaseYear)
        string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
222
    self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
223 224
    self.mediaIsUnreadView.hidden = YES;
    self.progressIndicator.hidden = YES;
225
    self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
226
    self.folderIconView.hidden = NO;
227 228
}

229
- (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
230
{
231
    MLFile *anyFileFromTrack = albumTrack.anyFileFromTrack;
232
    self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
233
    self.titleLabel.text = albumTrack.title;
234
    [self _showPositionOfItem:anyFileFromTrack];
235
    self.folderIconView.hidden = YES;
236 237
}

238
- (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
239 240 241 242 243
{
    self.titleLabel.text = showEpisode.name;

    MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
    if (self.titleLabel.text.length < 1) {
244
        self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
245 246
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
    } else
247
        self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
248

249
    [self _showPositionOfItem:anyFileFromEpisode];
250
    self.folderIconView.hidden = YES;
251 252
}

253
- (void)_configureForAlbum:(MLAlbum *)album
254 255 256 257
{
    self.titleLabel.text = album.name;
    MLAlbumTrack *anyTrack = [album.tracks anyObject];
    NSUInteger count = album.tracks.count;
258 259
    NSMutableString *string = [[NSMutableString alloc] init];
    if (anyTrack) {
260 261 262 263
        if (anyTrack.artist.length > 0) {
            [string appendString:anyTrack.artist];
            [string appendString:@" — "];
        }
264
    }
265
    [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
266
    if (album.releaseYear.length > 0)
Felix Paul Kühne's avatar
Felix Paul Kühne committed
267
        [string appendFormat:@" — %@", album.releaseYear];
268
    self.subtitleLabel.text = string;
269 270
    self.mediaIsUnreadView.hidden = YES;
    self.progressIndicator.hidden = YES;
271
    self.folderIconView.hidden = YES;
272 273
}

274 275 276 277
- (void)_configureForFolder:(MLLabel *)label
{
    self.titleLabel.text = label.name;
    NSUInteger count = label.files.count;
278
    self.subtitleLabel.text = (count == 1) ? NSLocalizedString(@"ONE_FILE", nil) : [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
279 280
    self.mediaIsUnreadView.hidden = YES;
    self.progressIndicator.hidden = YES;
281 282
    self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
    self.folderIconView.hidden = NO;
283 284
}

285
- (void)_configureForMLFile:(MLFile *)mediaFile
286
{
287
    if (mediaFile.isAlbumTrack) {
288 289 290 291 292 293
        NSString *string = @"";
        if (mediaFile.albumTrack.artist)
            string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
        else if (mediaFile.albumTrack.album.name)
            string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
        self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
294 295 296 297
    } else
        self.titleLabel.text = mediaFile.title;

    if (self.isEditing)
298
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
299 300 301 302 303 304 305 306 307
    else {
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
        if (mediaFile.videoTrack) {
            NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
            NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
            if (width.intValue > 0 && height.intValue > 0)
                self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
        }
    }
308
    [self _showPositionOfItem:mediaFile];
309
    self.folderIconView.hidden = YES;
310 311
}

312
- (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
313
{
314 315
    if (!mediaLibraryFile)
        return;
316
    CGFloat position = mediaLibraryFile.lastPosition.floatValue;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
317 318 319 320 321
    CGFloat duration = mediaLibraryFile.duration.floatValue;

    if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
        [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
        self.mediaIsUnreadView.hidden = NO;
322 323 324
    } else if (position != 0.) {
        self.mediaIsUnreadView.hidden = YES;
    } else {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
325 326
        [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
        self.mediaIsUnreadView.hidden = NO;
327
    }
328 329
}

330 331
- (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
{
332
    _isExpanded = YES;
333
    CGRect frame = self.frame;
334 335 336 337 338 339 340
    frame.size.height = 180.;
    BOOL metaHidden = NO;

    MLFile *theFile;
    if ([self.mediaObject isKindOfClass:[MLFile class]])
        theFile = (MLFile *)self.mediaObject;
    else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
341
        theFile = [(MLShowEpisode *)self.mediaObject anyFileFromEpisode];
342
    else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
343
        theFile = [(MLAlbumTrack *)self.mediaObject anyFileFromTrack];
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368

    NSMutableString *mediaInfo = [[NSMutableString alloc] init];

    if (theFile) {
        NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
        NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
        NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
        NSArray *tracks = [[theFile tracks] allObjects];
        NSUInteger trackCount = tracks.count;

        for (NSUInteger x = 0; x < trackCount; x++) {
            NSManagedObject *track = tracks[x];
            NSString *trackEntityName = [[track entity] name];
            if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
                [videoTracks addObject:track];
            else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
                [audioTracks addObject:track];
            else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
                [spuTracks addObject:track];
        }

        /* print video info */
        trackCount = videoTracks.count;

        if (trackCount > 0) {
369 370 371 372 373
            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 video track"];

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
            [mediaInfo appendString:@" ("];
            for (NSUInteger x = 0; x < trackCount; x++) {
                int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
                if (x != 0)
                    [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
                else
                    [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
            }
            [mediaInfo appendString:@")"];
        }

        /* print audio info */
        trackCount = audioTracks.count;

        if (trackCount > 0) {
389 390 391 392 393 394 395 396
            if (mediaInfo.length > 0)
                [mediaInfo appendString:@"\n\n"];

            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 audio track"];

397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
            [mediaInfo appendString:@":\n"];
            for (NSUInteger x = 0; x < trackCount; x++) {
                NSManagedObject *track = audioTracks[x];
                int fourcc = [[track valueForKey:@"codec"] intValue];
                if (x != 0)
                    [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
                else
                    [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];

                int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
                NSString *language = [track valueForKey:@"language"];
                int bitrate = [[track valueForKey:@"bitrate"] intValue];
                if (channelNumber != 0 || language != nil || bitrate > 0) {
                    [mediaInfo appendString:@" ["];

                    if (bitrate > 0)
                        [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];

                    if (channelNumber > 0) {
                        if (bitrate > 0)
                            [mediaInfo appendString:@", "];

                        if (channelNumber == 1)
                            [mediaInfo appendString:@"MONO"];
                        else if (channelNumber == 2)
                            [mediaInfo appendString:@"STEREO"];
                        else
                            [mediaInfo appendString:@"MULTI-CHANNEL"];
                    }

                    if (language != nil) {
                        if (channelNumber > 0 || bitrate > 0)
                            [mediaInfo appendString:@", "];

                        [mediaInfo appendString:[language uppercaseString]];
                    }

                    [mediaInfo appendString:@"]"];
                }
            }
        }

        /* SPU */
        trackCount = spuTracks.count;
441 442
        if (trackCount == 0) {
            NSFileManager *fileManager = [NSFileManager defaultManager];
443
            NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
444
            NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
445
            NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
446 447 448 449 450 451 452 453 454
            NSUInteger count = allfiles.count;
            NSString *additionalFilePath;
            for (unsigned int x = 0; x < count; x++) {
                additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
                if ([additionalFilePath isSupportedSubtitleFormat])
                    if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
                        trackCount ++;
            }
        }
455

456
        if ((trackCount > 0) || (spuTracks.count > 0)) {
457 458 459 460 461 462 463
            if (mediaInfo.length > 0)
                [mediaInfo appendString:@"\n\n"];

            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 subtitles track"];
464
            
465
            if (spuTracks.count > 0) {
466 467 468 469 470 471 472 473 474 475
                [mediaInfo appendString:@" ("];
                for (NSUInteger x = 0; x < trackCount; x++) {
                    NSString *language = [spuTracks[x] valueForKey:@"language"];

                    if (language) {
                        if (x != 0)
                            [mediaInfo appendFormat:@", %@", [language uppercaseString]];
                        else
                            [mediaInfo appendString:[language uppercaseString]];
                    }
476
                }
477
                [mediaInfo appendString:@")"];
478
            }
479
        }
480 481

        self.metaDataLabel.text = mediaInfo;
482 483
        [self.metaDataLabel sizeToFit];
        [self.metaDataLabel setFrame:CGRectMake((self.frame.size.width - self.metaDataLabel.frame.size.width)/2, self.metaDataLabel.frame.origin.y, self.metaDataLabel.frame.size.width, self.metaDataLabel.frame.size.height)];
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        videoTracks = audioTracks = spuTracks = nil;
    } else
        self.metaDataLabel.text = @"";

    void (^animationBlock)() = ^() {
        self.frame = frame;
        self.metaDataLabel.hidden = metaHidden;
    };

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        self.frame = frame;
        self.metaDataLabel.hidden = metaHidden;
    };

    NSTimeInterval animationDuration = .2;
    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
}

- (void)collapsWithAnimation:(BOOL)animate
{
    _isExpanded = NO;
    if (!animate) {
        self.metaDataLabel.hidden = YES;
        CGRect frame = self.frame;
508
        frame.size.height = 90.;
509 510 511 512 513 514 515
        self.frame = frame;
        return;
    }

    CGRect frame = self.frame;
    frame.size.height = 90.;
    BOOL metaHidden = YES;
516 517 518

    void (^animationBlock)() = ^() {
        self.frame = frame;
519
        self.metaDataLabel.hidden = metaHidden;
520 521 522 523
    };

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        self.frame = frame;
524
        self.metaDataLabel.hidden = metaHidden;
525 526 527 528 529 530
    };

    NSTimeInterval animationDuration = .2;
    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
}

531 532 533 534 535 536
- (void)thumbnailWasUpdated:(NSNotification *)aNotification
{
    self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
    self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject refreshCache:YES];
}

537
@end