public MediaContentPort()
        {
            mediaDatabase = new MediaDatabase();
            mediaDatabase.Connect();

            mediaInfoCommand = new MediaInfoCommand(mediaDatabase);
        }
        static void Main(string[] args)
        {
            // Create a Media Database based on the .csv file
            MediaDatabase database = new MediaDatabase("Media_Library_Database.csv");

            Console.WriteLine("Welcome to the Multi-Media Library archive manager");

            while (true)
            {
                // Ask user for media type
                Console.WriteLine("\nPlease, select media type you want to filter on: [A]lbum | [M]ovie | [B]ook | [V]ideogame | [E]xit");
                string type = Console.ReadLine();

                string headers = MultimediaItem.GetHeaders(type);

                // When user specifies a type that doesn't exist, exit the application
                if (headers == null)
                {
                    return;
                }

                // Ask user for property to order elements by
                Console.WriteLine(headers);
                string sortingProperty = Console.ReadLine();

                // Get filtered and sorted items from our database
                IEnumerable <MultimediaItem> records = database.GetElements(type, sortingProperty);

                // Print them on screen
                foreach (MultimediaItem item in records)
                {
                    Console.WriteLine(item.DetailedInformation);
                }
            }
        }
示例#3
0
        private void PerformSyncThreadCycle()
        {
            Hyena.Log.Debug("Starting AppleDevice sync thread cycle");

            var progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"),
                                              Catalog.GetString("Preparing to synchronize..."), GetIconNames());

            progressUpdater.Register();
            MediaDatabase.StartSync();

            SyncTracksToAdd(progressUpdater);

            SyncTracksToUpdate(progressUpdater);

            SyncTracksToRemove(progressUpdater);

            SyncTracksToPlaylists();

            SyncDatabase(progressUpdater);

            MediaDatabase.StopSync();
            progressUpdater.Finish();

            Hyena.Log.Debug("Ending AppleDevice sync thread cycle");
        }
示例#4
0
        public MediaContentDatabase()
        {
            var database = new MediaDatabase();

            database.Connect();

            _mediaInfoCmd = new MediaInfoCommand(database);
        }
示例#5
0
        public LibraryScanningQueue(MediaDatabase dbOptions, IDistinctQueueProcessor <IConversionItem> converter, IEnumerable <IConversionPlugin> conversionPlugins, ILogger <LibraryScanningQueue> logger)
        {
            this.dbOptions         = dbOptions;
            this.converter         = converter;
            this.conversionPlugins = conversionPlugins;
            log = logger;

            Parallelization = 1; // Process linearly.
        }
示例#6
0
        public DataBase()
        {
            var database = new MediaDatabase();

            database.Connect();

            _mediaInfoCmd = new MediaInfoCommand(database);

            _files = Directory.GetFiles(_filePath, "*.jpg").Select(Path.GetFullPath).ToList();
        }
        /// <summary>
        /// Connects to Media Database.
        /// </summary>
        public void ConnectDatabase()
        {
            _mediaDatabase = new MediaDatabase();

            try
            {
                _mediaDatabase.Connect();
            }
            catch (Exception exception)
            {
                ErrorHandler("Connecting DB error: " + exception.Message);
            }
        }
示例#8
0
        void SyncDatabase(UserJob progressUpdater)
        {
            try {
                string message = Catalog.GetString("Writing media database");
                UpdateProgress(progressUpdater, message, 1, 1);

                lock (write_mutex) {
                    MediaDatabase.Write();
                }

                Log.Information("Wrote iPod database");
            } catch (Exception e) {
                Log.Error("Failed to save iPod database", e);
            }
        }
        /// <summary>
        /// This is a sample to demonstrate how to query the media database to retrieve media content
        /// For more information about media content, see https://docs.tizen.org/application/dotnet/guides/multimedia/media-content
        /// </summary>
        public static async Task AccessMediaContentSampleAsync()
        {
            // Ask the user for the permission
            PrivacyPermissionStatus permission = await PrivacyPermissionService.RequestAsync(PrivacyPrivilege.MediaStorage);

            if (permission != PrivacyPermissionStatus.Granted)
            {
                // TODO: The permission is not granted
                return;
            }

            using (var database = new MediaDatabase())
            {
                try
                {
                    // Establish a connection to the media database.
                    database.Connect();

                    // Note that the system automactically scans storage and adds media files to the database.
                    // To request the system to scan a directory explicitly, use MediaDatabase.ScanFolderAsync()
                    // await database.ScanFolderAsync(path);

                    // Query the database to retrieve media files and get a Reader containing results.
                    var command = new MediaInfoCommand(database);
                    var reader  = command.SelectMedia(new SelectArguments()
                    {
                        FilterExpression = $"{MediaInfoColumns.MediaType}={(int)MediaType.Music}"
                                           + $" OR {MediaInfoColumns.MediaType}={(int)MediaType.Sound}"
                                           + $" OR {MediaInfoColumns.MediaType}={(int)MediaType.Video}"
                    });

                    // Iterate over media data in the results.
                    while (reader.Read())
                    {
                        var media = reader.Current;

                        // TODO: Insert code to do something with a media file.
                        // Note that your app needs adequate permissions to perform operations on the file
                        Logger.Info($"{media.MediaType}: {media.Title}");
                    }
                }
                catch (MediaDatabaseException)
                {
                    // TODO: Handle exception as appropriate to your scenario.
                }
            }
        }
示例#10
0
        public MediaContentService()
        {
            try
            {
                mediaDB = new MediaDatabase();
#if media_svc_get_storage_id_failed_return_minus_2
                //mediaDB.Connect();
                //MediaDatabase.FolderUpdated += MediaDatabase_FolderUpdated;
                //MediaDatabase.MediaInfoUpdated += MediaDatabase_MediaInfoUpdated;
                //mediaInfoCmd = new MediaInfoCommand(mediaDB);
#endif
            }
            catch (Exception e)
            {
                Console.WriteLine("    FAILED MediaContentService() : " + e.Message);
                MessagingCenter.Send(this, MessageKeys.ErrorOccur, e);
            }
        }
示例#11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var builder = services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }

            services.AddOptions();
            services.Configure <VSettings>(Configuration.GetSection("VSettings"));
            MediaDatabase dbOptions = AddDatabase(services);

            ICompleteItems <IExportableConversionItem> completeQueue = new CompleteItems <IExportableConversionItem>(Settings.CompleteQueueLength);

            services.AddSingleton(completeQueue);

            MediaConversionQueue converter = new MediaConversionQueue(
                Settings.FFmpegPath,
                Settings.FFprobePath,
                Settings.Mp4BoxPath,
                GetTemp(),
                Settings.Parallelization,
                completeQueue,
                LoggerFactory.CreateLogger <MediaConversionQueue>());

            services.AddSingleton(converter);

            RateLimiter rateLimiter = new RateLimiter(TimeSpan.FromSeconds(10), LoggerFactory.CreateLogger <RateLimiter>());

            services.AddSingleton(rateLimiter);
            List <IConversionPlugin> plugins = GeneratePlugins(rateLimiter);

            services.AddSingleton(new LibraryScanningQueue(dbOptions, converter, plugins, LoggerFactory.CreateLogger <LibraryScanningQueue>()));

            services.AddSingleton(Settings);

            services.AddAuthorization();

            services.AddHttpClient();
        }
示例#12
0
        private void RaiseReadyToScrobble()
        {
            var handler = ReadyToScrobble;

            if (handler != null)
            {
                var recent_plays = new ScrobblingBatchEventArgs {
                    ScrobblingBatch = GatherRecentPlayInfo()
                };
                if (recent_plays.ScrobblingBatch.Count != 0)
                {
                    handler(this, recent_plays);

                    // We must perform a write to clear out the recent playcount information so we do not
                    // submit duplicate plays on subsequent invocations.
                    lock (write_mutex) {
                        MediaDatabase.Write();
                    }
                }
            }
        }
示例#13
0
        public Song nextSong(int[] ids, bool isShuffleOn, IntPtr handle)
        {
            // creating variables that will be used to ensure the song doesn't go out of range
            int highestId = ids.Max();
            int lowestId  = ids.Min();

            // if shuffle is on pick a random song using the ids array
            if (isShuffleOn)
            {
                Random random      = new Random();
                int    randomTrack = random.Next(lowestId, highestId);
                currentSongID = randomTrack;
                Song song = MediaDatabase.getSong(randomTrack);
                play(song, handle);
                return(song);
            }
            // else just go to the next song
            else
            {
                // if the highest id is greater than the current song's
                // just go to next song
                if (highestId > currentSongID)
                {
                    currentSongID++;

                    Song song = MediaDatabase.getSong(currentSongID);
                    play(song, handle);
                    return(song);
                }
                // if highest id is not greater than next song go back to first song
                else
                {
                    currentSongID = lowestId;
                    Song song = MediaDatabase.getSong(currentSongID);
                    play(song, handle);
                    return(song);
                }
            }
        }
示例#14
0
        public void TestConversion()
        {
            var globalTemp = Path.Join(Environment.CurrentDirectory, "testing\\globaltemp");

            Directory.CreateDirectory(globalTemp);

            var inputDirectory = Path.Join(Environment.CurrentDirectory, "testing\\input");

            Directory.CreateDirectory(inputDirectory);

            if (!File.Exists("testing\\input\\test5.mkv"))
            {
                File.Copy(Path.Join(Environment.CurrentDirectory, "..\\..\\..\\test5.mkv"), "testing\\input\\test5.mkv");
            }
            if (!File.Exists("testing\\input\\test52.mkv"))
            {
                File.Copy(Path.Join(Environment.CurrentDirectory, "..\\..\\..\\test52.mkv"), "testing\\input\\test52.mkv");
            }
            if (!File.Exists("testing\\input\\testfile.ogg"))
            {
                File.Copy(Path.Join(Environment.CurrentDirectory, "..\\..\\..\\testfile.ogg"), "testing\\input\\testfile.ogg");
            }
            if (!File.Exists("testing\\input\\testfile2.ogg"))
            {
                File.Copy(Path.Join(Environment.CurrentDirectory, "..\\..\\..\\testfile2.ogg"), "testing\\input\\testfile2.ogg");
            }

            var libraryTemp = Path.Join(Environment.CurrentDirectory, "testing\\librarytemp");

            Directory.CreateDirectory(libraryTemp);

            var outputDirectory = Path.Join(Environment.CurrentDirectory, "testing\\output");

            Directory.CreateDirectory(outputDirectory);

            string litePath = Path.Combine(Environment.CurrentDirectory, "temp.sqlite");

            if (File.Exists(litePath))
            {
                File.Delete(litePath);
            }

            var connection = new SqliteConnection("Data Source=:memory:");

            connection.Open();

            try
            {
                var dbBuilder = new DbContextOptionsBuilder <VolyContext>()
                                .UseSqlite(connection);
                MediaDatabase db = new MediaDatabase
                {
                    Database = dbBuilder.Options
                };

                var logFactory = new LoggerFactory();

                DQP.IDistinctQueueProcessor <IConversionItem> converter = new MediaConversionQueue(
                    "ffmpeg",
                    "ffprobe",
                    "mp4box",
                    globalTemp,
                    1,
                    new CompleteItems <IExportableConversionItem>(),
                    new Logger <MediaConversionQueue>(logFactory));
                var scanQueue = new LibraryScanningQueue(db, converter, new List <IConversionPlugin>(), new Logger <LibraryScanningQueue>(logFactory));

                var quality1    = new Quality(640, 480, 300, DEnc.H264Preset.ultrafast);
                var quality2    = new Quality(640, 480, 400, DEnc.H264Preset.ultrafast);
                var testLibrary = new Library()
                {
                    Name       = "Test",
                    OriginPath = inputDirectory,
                    Qualities  = new List <Quality>()
                    {
                        quality1, quality2
                    },
                    ValidExtensions = new HashSet <string>()
                    {
                        ".mp4", ".mkv", ".ogg"
                    },
                    TempPath = libraryTemp
                };

                IStorage storage = new MStorage.FilesystemStorage.FilesystemStorage(outputDirectory);

                using var context = new VolyContext(dbBuilder.Options);
                VolySeed.Initialize(context, logFactory.CreateLogger("VolySeed"));

                scanQueue.ScheduleLibraryScan(testLibrary, storage, context);

                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                while (converter.ItemsQueued.Count == 0)
                {
                    if (sw.ElapsedMilliseconds > 10000)
                    {
                        Assert.Fail("Disk scan took too long.");
                    }
                    System.Threading.Thread.Sleep(10);
                }

                var itemsProcessed      = new Dictionary <string, IConversionItem>();
                int lastProgressesSeen  = 0;
                int progressMovedEvents = 0;
                while (converter.ItemsQueued.Count > 0)
                {
                    foreach (var item in converter.ItemsProcessing)
                    {
                        Assert.IsTrue(item.Value.Quality.Where(x => x.Bitrate == quality1.Bitrate).SingleOrDefault() != null, "Item does not have the correct quality1 configuration.");
                        Assert.IsTrue(item.Value.Quality.Where(x => x.Bitrate == quality2.Bitrate).SingleOrDefault() != null, "Item does not have the correct quality2 configuration.");
                        if (!itemsProcessed.ContainsKey(item.Key))
                        {
                            itemsProcessed.Add(item.Key, item.Value.DeepClone());
                            Assert.AreEqual(item.Value.SourcePath, itemsProcessed[item.Key].SourcePath);
                        }
                        else
                        {
                            int progressesSeen    = 0;
                            var updateProgresses  = item.Value.Progress.GetEnumerator();
                            var currentProgresses = itemsProcessed[item.Key].Progress.GetEnumerator();
                            while (updateProgresses.MoveNext())
                            {
                                progressesSeen++;
                                if (currentProgresses.MoveNext())
                                {
                                    Assert.AreEqual(currentProgresses.Current.Description, updateProgresses.Current.Description);
                                    Assert.IsTrue(updateProgresses.Current.Progress >= currentProgresses.Current.Progress, "Progress not expected to go backwards.");
                                    if (updateProgresses.Current.Progress > currentProgresses.Current.Progress)
                                    {
                                        progressMovedEvents++;
                                    }
                                }
                            }
                            lastProgressesSeen = progressesSeen;

                            item.Value.DeepCloneTo(itemsProcessed[item.Key]);
                        }
                    }
                    System.Threading.Thread.Sleep(10);
                }

                Assert.IsTrue(lastProgressesSeen > 1);
                Assert.IsTrue(progressMovedEvents > 1);
            }
            finally
            {
                connection.Close();
            }
        }
示例#15
0
 /// <summary>
 /// MusicContentService class constructor.
 /// </summary>
 public MusicContentService()
 {
     _mediaDatabase = new MediaDatabase();
 }
示例#16
0
        private void PerformSyncThreadCycle()
        {
            Hyena.Log.Debug("Starting AppleDevice sync thread cycle");

            string message;
            int    total, i = 0;
            var    progressUpdater = new UserJob(Catalog.GetString("Syncing iPod"),
                                                 Catalog.GetString("Preparing to synchronize..."), GetIconNames());

            progressUpdater.Register();
            MediaDatabase.StartSync();
            message = Catalog.GetString("Adding track {0} of {1}");
            total   = tracks_to_add.Count;
            while (tracks_to_add.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    total = tracks_to_add.Count + i;
                    track = tracks_to_add.Dequeue();
                }

                try {
                    UpdateProgress(progressUpdater, message, ++i, total);
                    track.CommitToIpod(MediaDatabase);
                    track.Save(false);
                    tracks_map[track.TrackId] = track;
                } catch (Exception e) {
                    Log.Exception("Cannot save track to the Apple device", e);
                }
            }
            if (total > 0)
            {
                OnTracksAdded();
                OnUserNotifyUpdated();
            }

            while (tracks_to_update.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_update.Dequeue();
                }

                try {
                    track.CommitToIpod(MediaDatabase);
                } catch (Exception e) {
                    Log.Exception("Cannot save track to iPod", e);
                }
            }

            message = Catalog.GetString("Removing track {0} of {1}");
            total   = tracks_to_remove.Count;
            while (tracks_to_remove.Count > 0)
            {
                AppleDeviceTrackInfo track = null;
                lock (sync_mutex) {
                    track = tracks_to_remove.Dequeue();
                }

                if (tracks_map.ContainsKey(track.TrackId))
                {
                    tracks_map.Remove(track.TrackId);
                }

                try {
                    if (track.IpodTrack != null)
                    {
                        UpdateProgress(progressUpdater, message, total - tracks_to_remove.Count, total);

                        DeleteTrack(track.IpodTrack, true);
                    }
                    else
                    {
                        Log.Error("The ipod track was null");
                    }
                } catch (Exception e) {
                    Log.Exception("Cannot remove track from iPod", e);
                }
            }

            if (SupportsPlaylists)
            {
                // Remove playlists on the device
                var device_playlists = new List <GPod.Playlist> (MediaDatabase.Playlists);
                foreach (var playlist in device_playlists)
                {
                    if (!playlist.IsMaster && !playlist.IsPodcast)
                    {
                        MediaDatabase.Playlists.Remove(playlist);
                    }
                }

                // Add playlists from Banshee to the device
                foreach (Source child in Children)
                {
                    PlaylistSource from = child as PlaylistSource;
                    if (from != null && from.Count > 0)
                    {
                        var playlist = new GPod.Playlist(from.Name);
                        MediaDatabase.Playlists.Add(playlist);
                        foreach (int track_id in ServiceManager.DbConnection.QueryEnumerable <int> (String.Format(
                                                                                                        "SELECT CoreTracks.TrackID FROM {0} WHERE {1}",
                                                                                                        from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition)))
                        {
                            if (tracks_map.ContainsKey(track_id))
                            {
                                playlist.Tracks.Add(tracks_map[track_id].IpodTrack);
                            }
                        }
                    }
                }
            }

            try {
                message = Catalog.GetString("Writing media database");
                UpdateProgress(progressUpdater, message, 1, 1);

                lock (write_mutex) {
                    MediaDatabase.Write();
                }

                Log.Information("Wrote iPod database");
            } catch (Exception e) {
                Log.Exception("Failed to save iPod database", e);
            }
            MediaDatabase.StopSync();
            progressUpdater.Finish();

            Hyena.Log.Debug("Ending AppleDevice sync thread cycle");
        }
 /// <summary>
 /// DatabaseManagerService class constructor.
 /// </summary>
 public DatabaseManagerService()
 {
     _mediaDatabase = new MediaDatabase();
 }