<commit_before>﻿using System;
using System.Threading.Tasks;
using Plugin.MediaManager.Abstractions;

namespace Plugin.MediaManager
{
    public class MediaExtractorImplementation : IMediaExtractor
    {
        public Task<IMediaFile> ExtractMediaInfo(IMediaFile mediaFile)
        {
            return Task.FromResult(mediaFile);
        }
    }
}<commit_msg>Implement MediaExtractor for iOS<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AVFoundation;
using Foundation;
using Plugin.MediaManager.Abstractions;
using UIKit;

namespace Plugin.MediaManager
{
    public class MediaExtractorImplementation : IMediaExtractor
    {
        public async Task<IMediaFile> ExtractMediaInfo(IMediaFile mediaFile)
        {
            try
            {
                var assetsToLoad = new List<string>
                {
                    AVMetadata.CommonKeyArtist,
                    AVMetadata.CommonKeyTitle,
                    AVMetadata.CommonKeyArtwork
                };
                var nsUrl = new NSUrl(mediaFile.Url);
            
                // Default title to filename
                mediaFile.Title = nsUrl.LastPathComponent;
            
                var asset = AVAsset.FromUrl(nsUrl);
                await asset.LoadValuesTaskAsync(assetsToLoad.ToArray());

                foreach (var avMetadataItem in asset.CommonMetadata)
                {
                    if (avMetadataItem.CommonKey == AVMetadata.CommonKeyArtist)
                    {
                        mediaFile.Artist = ((NSString) avMetadataItem.Value).ToString();
                    }
                    else if (avMetadataItem.CommonKey == AVMetadata.CommonKeyTitle)
                    {
                        mediaFile.Title = ((NSString) avMetadataItem.Value).ToString();
                    }
                    else if (avMetadataItem.CommonKey == AVMetadata.CommonKeyArtwork)
                    {
                        var image = UIImage.LoadFromData(avMetadataItem.DataValue);
                        mediaFile.Cover = image;
                    }
                }
                return mediaFile;
            }
            catch (Exception)
            {
                return mediaFile;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06893542757417102, 'fraction_numerical': 0.0, 'mean_word_length': 1.5197802197802197, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6961497', 'n_tokens_mistral': 565, 'n_tokens_neox': 533, 'n_words': 102}