[shotwell/wip/phako/external-gstreamer: 1/5] video-support: Move into subdirectory



commit 7ef5be387f6d700606a2367b45bfdbe1bded9e30
Author: Jens Georg <mail jensge org>
Date:   Tue May 7 21:17:50 2019 +0200

    video-support: Move into subdirectory
    
    And split VideoSupport.vala into classes

 src/meson.build                                    | 473 ++++++++++----------
 .../Video.vala}                                    | 488 ---------------------
 src/video-support/VideoImportParams.vala           |  30 ++
 src/video-support/VideoReader.vala                 | 304 +++++++++++++
 src/video-support/VideoSourceCollection.vala       | 175 ++++++++
 5 files changed, 750 insertions(+), 720 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 69e721f1..5443c4f0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -46,235 +46,244 @@ endif
 
 subdir('publishing')
 
-executable('shotwell',
-           ['unit/Unit.vala',
-            'util/Util.vala',
-            'util/file.vala',
-            'util/image.vala',
-            'util/misc.vala',
-            'util/string.vala',
-            'util/system.vala',
-            'util/ui.vala',
-            'threads/Threads.vala',
-            'threads/Workers.vala',
-            'threads/BackgroundJob.vala',
-            'threads/Semaphore.vala',
-            'db/Db.vala',
-            'db/DatabaseTable.vala',
-            'db/PhotoTable.vala',
-            'db/EventTable.vala',
-            'db/FaceLocationTable.vala',
-            'db/FaceTable.vala',
-            'db/TagTable.vala',
-            'db/TombstoneTable.vala',
-            'db/VideoTable.vala',
-            'db/VersionTable.vala',
-            'db/SavedSearchDBTable.vala',
-            'editing_tools/EditingTools.vala',
-            'editing_tools/RGBHistogramManipulator.vala',
-            'editing_tools/StraightenTool.vala',
-            'faces/Face.vala',
-            'faces/FaceLocation.vala',
-            'slideshow/Slideshow.vala',
-            'slideshow/TransitionEffects.vala',
-            'photos/Photos.vala',
-            'photos/PhotoFileAdapter.vala',
-            'photos/PhotoFileFormat.vala',
-            'photos/PhotoFileSniffer.vala',
-            'photos/PhotoMetadata.vala',
-            'photos/GRaw.vala',
-            'photos/GdkSupport.vala',
-            'photos/GifSupport.vala',
-            'photos/JfifSupport.vala',
-            'photos/BmpSupport.vala',
-            'photos/RawSupport.vala',
-            'photos/PngSupport.vala',
-            'photos/TiffSupport.vala',
-            'photos/WebPSupport.vala',
-            'plugins/Plugins.vala',
-            'plugins/StandardHostInterface.vala',
-            'plugins/ManifestWidget.vala',
-            'publishing/Publishing.vala',
-            'publishing/PublishingUI.vala',
-            'publishing/PublishingPluginHost.vala',
-            'publishing/APIGlue.vala',
-            'library/Library.vala',
-            'library/LibraryWindow.vala',
-            'library/LibraryBranch.vala',
-            'library/TrashSidebarEntry.vala',
-            'library/OfflineSidebarEntry.vala',
-            'library/FlaggedSidebarEntry.vala',
-            'library/LastImportSidebarEntry.vala',
-            'library/ImportQueueSidebarEntry.vala',
-            'library/FlaggedPage.vala',
-            'library/ImportQueuePage.vala',
-            'library/LastImportPage.vala',
-            'library/OfflinePage.vala',
-            'library/TrashPage.vala',
-            'direct/Direct.vala',
-            'direct/DirectWindow.vala',
-            'direct/DirectPhoto.vala',
-            'direct/DirectPhotoPage.vala',
-            'direct/DirectView.vala',
-            'core/Core.vala',
-            'core/DataCollection.vala',
-            'core/DataSet.vala',
-            'core/util.vala',
-            'core/SourceCollection.vala',
-            'core/SourceHoldingTank.vala',
-            'core/DatabaseSourceCollection.vala',
-            'core/ContainerSourceCollection.vala',
-            'core/ViewCollection.vala',
-            'core/DataObject.vala',
-            'core/Alteration.vala',
-            'core/DataSource.vala',
-            'core/DataSourceTypes.vala',
-            'core/DataView.vala',
-            'core/DataViewTypes.vala',
-            'core/Tracker.vala',
-            'core/SourceInterfaces.vala',
-            'sidebar/Sidebar.vala',
-            'sidebar/Branch.vala',
-            'sidebar/Entry.vala',
-            'sidebar/Tree.vala',
-            'sidebar/common.vala',
-            'events/Events.vala',
-            'events/EventsBranch.vala',
-            'events/EventsDirectoryPage.vala',
-            'events/EventPage.vala',
-            'events/EventDirectoryItem.vala',
-            'tags/Tags.vala',
-            'tags/TagsBranch.vala',
-            'tags/TagPage.vala',
-            'tags/HierarchicalTagIndex.vala',
-            'tags/HierarchicalTagUtilities.vala',
-            'camera/Camera.vala',
-            'camera/CameraBranch.vala',
-            'camera/CameraTable.vala',
-            'camera/GPhoto.vala',
-            'camera/ImportPage.vala',
-            'searches/Searches.vala',
-            'searches/SearchesBranch.vala',
-            'searches/SearchBoolean.vala',
-            'searches/SavedSearchPage.vala',
-            'searches/SavedSearchDialog.vala',
-            'config/Config.vala',
-            'config/ConfigurationInterfaces.vala',
-            'config/GSettingsEngine.vala',
-            'data_imports/DataImports.vala',
-            'data_imports/DataImportsPluginHost.vala',
-            'data_imports/DataImportsUI.vala',
-            'data_imports/DataImportJob.vala',
-            'data_imports/DataImportSource.vala',
-            'folders/Folders.vala',
-            'folders/FoldersBranch.vala',
-            'folders/FoldersPage.vala',
-            'import-roll/ImportRollBranch.vala',
-            'import-roll/ImportRollEntry.vala',
-            'main.vala',
-            'AppWindow.vala',
-            'CollectionPage.vala',
-            'NaturalCollate.vala',
-            'Thumbnail.vala',
-            'ThumbnailCache.vala',
-            'CheckerboardItem.vala',
-            'CheckerboardItemText.vala',
-            'CheckerboardLayout.vala',
-            'PhotoPage.vala',
-            'Page.vala',
-            'SinglePhotoPage.vala',
-            'CheckerboardPage.vala',
-            'DragAndDropHandler.vala',
-            'PageMessagePane.vala',
-            'SortedList.vala',
-            'Dimensions.vala',
-            'Box.vala',
-            'Photo.vala',
-            'Orientation.vala',
-            'MapWidget.vala',
-            'BatchImport.vala',
-            'Dialogs.vala',
-            'Resources.vala',
-            'Debug.vala',
-            'Properties.vala',
-            'Event.vala',
-            'International.vala',
-            'AppDirs.vala',
-            'PixbufCache.vala',
-            'CommandManager.vala',
-            'Commands.vala',
-            'SlideshowPage.vala',
-            'LibraryFiles.vala',
-            'Printing.vala',
-            'Tag.vala',
-            'Screensaver.vala',
-            'Exporter.vala',
-            'DirectoryMonitor.vala',
-            'LibraryMonitor.vala',
-            'VideoSupport.vala',
-            'Tombstone.vala',
-            'MetadataWriter.vala',
-            'Application.vala',
-            'TimedQueue.vala',
-            'MediaPage.vala',
-            'MediaDataRepresentation.vala',
-            'DesktopIntegration.vala',
-            'MediaInterfaces.vala',
-            'MediaMetadata.vala',
-            'VideoMetadata.vala',
-            'MediaMonitor.vala',
-            'PhotoMonitor.vala',
-            'VideoMonitor.vala',
-            'SearchFilter.vala',
-            'MediaViewTracker.vala',
-            'UnityProgressBar.vala',
-            'Upgrades.vala',
-            'dialogs/AdjustDateTimeDialog.vala',
-            'dialogs/EntryMultiCompletion.vala',
-            'dialogs/ExportDialog.vala',
-            'dialogs/MultiTextEntryDialog.vala',
-            'dialogs/Preferences.vala',
-            'dialogs/ProgressDialog.vala',
-            'dialogs/SetBackgroundSlideshow.vala',
-            'dialogs/SetBackground.vala',
-            'dialogs/TextEntry.vala',
-            'dialogs/WelcomeDialog.vala',
-            '.unitize/_UnitInternals.vala',
-            '.unitize/_UtilInternals.vala',
-            '.unitize/_ThreadsInternals.vala',
-            '.unitize/_DbInternals.vala',
-            '.unitize/_EditingToolsInternals.vala',
-            '.unitize/_PluginsInternals.vala',
-            '.unitize/_SlideshowInternals.vala',
-            '.unitize/_PhotosInternals.vala',
-            '.unitize/_PublishingInternals.vala',
-            '.unitize/_LibraryInternals.vala',
-            '.unitize/_DirectInternals.vala',
-            '.unitize/_CoreInternals.vala',
-            '.unitize/_SidebarInternals.vala',
-            '.unitize/_EventsInternals.vala',
-            '.unitize/_TagsInternals.vala',
-            '.unitize/_CameraInternals.vala',
-            '.unitize/_SearchesInternals.vala',
-            '.unitize/_ConfigInternals.vala',
-            '.unitize/_DataImportsInternals.vala',
-            '.unitize/_FoldersInternals.vala',
-            '.unitize/_Library_unitize_entry.vala',
-            '.unitize/_Direct_unitize_entry.vala'] + shotwell_resources + face_sources,
-           include_directories : vapi_incdir,
-           dependencies : [
-               shotwell_deps,
-               sw_publishing_gui
-           ],
-           vala_args : ['--pkg', 'libgphoto2',
-                        '--pkg', 'libraw',
-                        '--pkg', 'libexif',
-                        '--pkg', 'version',
-                        '--gresources',
-                        join_paths(meson.source_root(), 'data',
-                          'org.gnome.Shotwell.gresource.xml')
-                       ],
-           link_with: [
-               sw_graphics_processor
-           ],
-           install : true)
+executable(
+    'shotwell',
+    [
+        'unit/Unit.vala',
+        'util/Util.vala',
+        'util/file.vala',
+        'util/image.vala',
+        'util/misc.vala',
+        'util/string.vala',
+        'util/system.vala',
+        'util/ui.vala',
+        'threads/Threads.vala',
+        'threads/Workers.vala',
+        'threads/BackgroundJob.vala',
+        'threads/Semaphore.vala',
+        'db/Db.vala',
+        'db/DatabaseTable.vala',
+        'db/PhotoTable.vala',
+        'db/EventTable.vala',
+        'db/FaceLocationTable.vala',
+        'db/FaceTable.vala',
+        'db/TagTable.vala',
+        'db/TombstoneTable.vala',
+        'db/VideoTable.vala',
+        'db/VersionTable.vala',
+        'db/SavedSearchDBTable.vala',
+        'editing_tools/EditingTools.vala',
+        'editing_tools/RGBHistogramManipulator.vala',
+        'editing_tools/StraightenTool.vala',
+        'faces/Face.vala',
+        'faces/FaceLocation.vala',
+        'slideshow/Slideshow.vala',
+        'slideshow/TransitionEffects.vala',
+        'photos/Photos.vala',
+        'photos/PhotoFileAdapter.vala',
+        'photos/PhotoFileFormat.vala',
+        'photos/PhotoFileSniffer.vala',
+        'photos/PhotoMetadata.vala',
+        'photos/GRaw.vala',
+        'photos/GdkSupport.vala',
+        'photos/GifSupport.vala',
+        'photos/JfifSupport.vala',
+        'photos/BmpSupport.vala',
+        'photos/RawSupport.vala',
+        'photos/PngSupport.vala',
+        'photos/TiffSupport.vala',
+        'photos/WebPSupport.vala',
+        'plugins/Plugins.vala',
+        'plugins/StandardHostInterface.vala',
+        'plugins/ManifestWidget.vala',
+        'publishing/Publishing.vala',
+        'publishing/PublishingUI.vala',
+        'publishing/PublishingPluginHost.vala',
+        'publishing/APIGlue.vala',
+        'library/Library.vala',
+        'library/LibraryWindow.vala',
+        'library/LibraryBranch.vala',
+        'library/TrashSidebarEntry.vala',
+        'library/OfflineSidebarEntry.vala',
+        'library/FlaggedSidebarEntry.vala',
+        'library/LastImportSidebarEntry.vala',
+        'library/ImportQueueSidebarEntry.vala',
+        'library/FlaggedPage.vala',
+        'library/ImportQueuePage.vala',
+        'library/LastImportPage.vala',
+        'library/OfflinePage.vala',
+        'library/TrashPage.vala',
+        'direct/Direct.vala',
+        'direct/DirectWindow.vala',
+        'direct/DirectPhoto.vala',
+        'direct/DirectPhotoPage.vala',
+        'direct/DirectView.vala',
+        'core/Core.vala',
+        'core/DataCollection.vala',
+        'core/DataSet.vala',
+        'core/util.vala',
+        'core/SourceCollection.vala',
+        'core/SourceHoldingTank.vala',
+        'core/DatabaseSourceCollection.vala',
+        'core/ContainerSourceCollection.vala',
+        'core/ViewCollection.vala',
+        'core/DataObject.vala',
+        'core/Alteration.vala',
+        'core/DataSource.vala',
+        'core/DataSourceTypes.vala',
+        'core/DataView.vala',
+        'core/DataViewTypes.vala',
+        'core/Tracker.vala',
+        'core/SourceInterfaces.vala',
+        'sidebar/Sidebar.vala',
+        'sidebar/Branch.vala',
+        'sidebar/Entry.vala',
+        'sidebar/Tree.vala',
+        'sidebar/common.vala',
+        'events/Events.vala',
+        'events/EventsBranch.vala',
+        'events/EventsDirectoryPage.vala',
+        'events/EventPage.vala',
+        'events/EventDirectoryItem.vala',
+        'tags/Tags.vala',
+        'tags/TagsBranch.vala',
+        'tags/TagPage.vala',
+        'tags/HierarchicalTagIndex.vala',
+        'tags/HierarchicalTagUtilities.vala',
+        'camera/Camera.vala',
+        'camera/CameraBranch.vala',
+        'camera/CameraTable.vala',
+        'camera/GPhoto.vala',
+        'camera/ImportPage.vala',
+        'searches/Searches.vala',
+        'searches/SearchesBranch.vala',
+        'searches/SearchBoolean.vala',
+        'searches/SavedSearchPage.vala',
+        'searches/SavedSearchDialog.vala',
+        'config/Config.vala',
+        'config/ConfigurationInterfaces.vala',
+        'config/GSettingsEngine.vala',
+        'data_imports/DataImports.vala',
+        'data_imports/DataImportsPluginHost.vala',
+        'data_imports/DataImportsUI.vala',
+        'data_imports/DataImportJob.vala',
+        'data_imports/DataImportSource.vala',
+        'folders/Folders.vala',
+        'folders/FoldersBranch.vala',
+        'folders/FoldersPage.vala',
+        'import-roll/ImportRollBranch.vala',
+        'import-roll/ImportRollEntry.vala',
+        'main.vala',
+        'AppWindow.vala',
+        'CollectionPage.vala',
+        'NaturalCollate.vala',
+        'Thumbnail.vala',
+        'ThumbnailCache.vala',
+        'CheckerboardItem.vala',
+        'CheckerboardItemText.vala',
+        'CheckerboardLayout.vala',
+        'PhotoPage.vala',
+        'Page.vala',
+        'SinglePhotoPage.vala',
+        'CheckerboardPage.vala',
+        'DragAndDropHandler.vala',
+        'PageMessagePane.vala',
+        'SortedList.vala',
+        'Dimensions.vala',
+        'Box.vala',
+        'Photo.vala',
+        'Orientation.vala',
+        'MapWidget.vala',
+        'BatchImport.vala',
+        'Dialogs.vala',
+        'Resources.vala',
+        'Debug.vala',
+        'Properties.vala',
+        'Event.vala',
+        'International.vala',
+        'AppDirs.vala',
+        'PixbufCache.vala',
+        'CommandManager.vala',
+        'Commands.vala',
+        'SlideshowPage.vala',
+        'LibraryFiles.vala',
+        'Printing.vala',
+        'Tag.vala',
+        'Screensaver.vala',
+        'Exporter.vala',
+        'DirectoryMonitor.vala',
+        'LibraryMonitor.vala',
+        'VideoSupport.vala',
+        'Tombstone.vala',
+        'MetadataWriter.vala',
+        'Application.vala',
+        'TimedQueue.vala',
+        'MediaPage.vala',
+        'MediaDataRepresentation.vala',
+        'DesktopIntegration.vala',
+        'MediaInterfaces.vala',
+        'MediaMetadata.vala',
+        'VideoMetadata.vala',
+        'MediaMonitor.vala',
+        'PhotoMonitor.vala',
+        'VideoMonitor.vala',
+        'SearchFilter.vala',
+        'MediaViewTracker.vala',
+        'UnityProgressBar.vala',
+        'Upgrades.vala',
+        'dialogs/AdjustDateTimeDialog.vala',
+        'dialogs/EntryMultiCompletion.vala',
+        'dialogs/ExportDialog.vala',
+        'dialogs/MultiTextEntryDialog.vala',
+        'dialogs/Preferences.vala',
+        'dialogs/ProgressDialog.vala',
+        'dialogs/SetBackgroundSlideshow.vala',
+        'dialogs/SetBackground.vala',
+        'dialogs/TextEntry.vala',
+        'dialogs/WelcomeDialog.vala',
+        '.unitize/_UnitInternals.vala',
+        '.unitize/_UtilInternals.vala',
+        '.unitize/_ThreadsInternals.vala',
+        '.unitize/_DbInternals.vala',
+        '.unitize/_EditingToolsInternals.vala',
+        '.unitize/_PluginsInternals.vala',
+        '.unitize/_SlideshowInternals.vala',
+        '.unitize/_PhotosInternals.vala',
+        '.unitize/_PublishingInternals.vala',
+        '.unitize/_LibraryInternals.vala',
+        '.unitize/_DirectInternals.vala',
+        '.unitize/_CoreInternals.vala',
+        '.unitize/_SidebarInternals.vala',
+        '.unitize/_EventsInternals.vala',
+        '.unitize/_TagsInternals.vala',
+        '.unitize/_CameraInternals.vala',
+        '.unitize/_SearchesInternals.vala',
+        '.unitize/_ConfigInternals.vala',
+        '.unitize/_DataImportsInternals.vala',
+        '.unitize/_FoldersInternals.vala',
+        '.unitize/_Library_unitize_entry.vala',
+        '.unitize/_Direct_unitize_entry.vala',
+        'video-support/VideoReader.vala',
+        'video-support/VideoImportParams.vala',
+        'video-support/Video.vala',
+        'video-support/VideoSourceCollection.vala'
+    ] + shotwell_resources + face_sources,
+    include_directories : vapi_incdir,
+    dependencies : [
+        shotwell_deps,
+        sw_publishing_gui
+    ],
+    vala_args : [
+        '--pkg', 'libgphoto2',
+        '--pkg', 'libraw',
+        '--pkg', 'libexif',
+        '--pkg', 'version',
+        '--gresources',
+        join_paths(meson.source_root(), 'data',
+        'org.gnome.Shotwell.gresource.xml')
+    ],
+    link_with: [
+        sw_graphics_processor
+    ],
+    install : true
+)
diff --git a/src/VideoSupport.vala b/src/video-support/Video.vala
similarity index 57%
rename from src/VideoSupport.vala
rename to src/video-support/Video.vala
index 533dfe67..d8aeb778 100644
--- a/src/VideoSupport.vala
+++ b/src/video-support/Video.vala
@@ -4,326 +4,6 @@
  * See the COPYING file in this distribution.
  */
 
-public errordomain VideoError {
-    FILE,          // there's a problem reading the video container file (doesn't exist, no read
-                   // permission, etc.)
-
-    CONTENTS,      // we can read the container file but its contents are indecipherable (no codec,
-                   // malformed data, etc.)
-}
-
-public class VideoImportParams {
-    // IN:
-    public File file;
-    public ImportID import_id = ImportID();
-    public string? md5;
-    public time_t exposure_time_override;
-    
-    // IN/OUT:
-    public Thumbnails? thumbnails;
-    
-    // OUT:
-    public VideoRow row = new VideoRow();
-    
-    public VideoImportParams(File file, ImportID import_id, string? md5,
-        Thumbnails? thumbnails = null, time_t exposure_time_override = 0) {
-        this.file = file;
-        this.import_id = import_id;
-        this.md5 = md5;
-        this.thumbnails = thumbnails;
-        this.exposure_time_override = exposure_time_override;
-    }
-}
-
-public class VideoReader {
-    private const double UNKNOWN_CLIP_DURATION = -1.0;
-    private const uint THUMBNAILER_TIMEOUT = 10000; // In milliseconds.
-
-    // File extensions for video containers that pack only metadata as per the AVCHD spec
-    private const string[] METADATA_ONLY_FILE_EXTENSIONS = { "bdm", "bdmv", "cpi", "mpl" };
-    
-    private double clip_duration = UNKNOWN_CLIP_DURATION;
-    private Gdk.Pixbuf preview_frame = null;
-    private File file = null;
-    private GLib.Pid thumbnailer_pid = 0;
-    public DateTime? timestamp { get; private set; default = null; }
-
-    public VideoReader(File file) {
-        this.file = file;
-     }
-    
-    public static bool is_supported_video_file(File file) {
-        var mime_type = ContentType.guess(file.get_basename(), new uchar[0], null);
-        // special case: deep-check content-type of files ending with .ogg
-        if (mime_type == "audio/ogg" && file.has_uri_scheme("file")) {
-            try {
-                var info = file.query_info(FileAttribute.STANDARD_CONTENT_TYPE,
-                                           FileQueryInfoFlags.NONE);
-                var content_type = info.get_content_type();
-                if (content_type != null && content_type.has_prefix ("video/")) {
-                    return true;
-                }
-            } catch (Error error) {
-                debug("Failed to query content type: %s", error.message);
-            }
-        }
-
-        return is_supported_video_filename(file.get_basename());
-    }
-
-    public static bool is_supported_video_filename(string filename) {
-        string mime_type;
-        mime_type = ContentType.guess(filename, new uchar[0], null);
-        // Guessed mp4 from filename has application/ as prefix, so check for mp4 in the end
-        if (mime_type.has_prefix ("video/") || mime_type.has_suffix("mp4")) {
-            string? extension = null;
-            string? name = null;
-            disassemble_filename(filename, out name, out extension);
-
-            if (extension == null)
-                return true;
-
-            foreach (string s in METADATA_ONLY_FILE_EXTENSIONS) {
-                if (utf8_ci_compare(s, extension) == 0)
-                    return false;
-            }
-
-            return true;
-        } else {
-            debug("Skipping %s, unsupported mime type %s", filename, mime_type);
-            return false;
-        }
-    }
-    
-    public static ImportResult prepare_for_import(VideoImportParams params) {
-#if MEASURE_IMPORT
-        Timer total_time = new Timer();
-#endif
-        File file = params.file;
-        
-        FileInfo info = null;
-        try {
-            info = file.query_info(DirectoryMonitor.SUPPLIED_ATTRIBUTES,
-                FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
-        } catch (Error err) {
-            return ImportResult.FILE_ERROR;
-        }
-        
-        if (info.get_file_type() != FileType.REGULAR)
-            return ImportResult.NOT_A_FILE;
-        
-        if (!is_supported_video_file(file)) {
-            message("Not importing %s: file is marked as a video file but doesn't have a" +
-                "supported extension", file.get_path());
-            
-            return ImportResult.UNSUPPORTED_FORMAT;
-        }
-        
-        TimeVal timestamp = info.get_modification_time();
-        
-        // make sure params has a valid md5
-        assert(params.md5 != null);
-
-        time_t exposure_time = params.exposure_time_override;
-        string title = "";
-        string comment = "";
-        
-        VideoReader reader = new VideoReader(file);
-        bool is_interpretable = true;
-        double clip_duration = 0.0;
-        Gdk.Pixbuf preview_frame = reader.read_preview_frame();
-        try {
-            clip_duration = reader.read_clip_duration();
-        } catch (VideoError err) {
-            if (err is VideoError.FILE) {
-                return ImportResult.FILE_ERROR;
-            } else if (err is VideoError.CONTENTS) {
-                is_interpretable = false;
-                clip_duration = 0.0;
-            } else {
-                error("can't prepare video for import: an unknown kind of video error occurred");
-            }
-        }
-        
-        try {
-            VideoMetadata metadata = reader.read_metadata();
-            MetadataDateTime? creation_date_time = metadata.get_creation_date_time();
-            
-            if (creation_date_time != null && creation_date_time.get_timestamp() != 0)
-                exposure_time = creation_date_time.get_timestamp();
-            
-            string? video_title = metadata.get_title();
-            string? video_comment = metadata.get_comment();
-            if (video_title != null)
-                title = video_title;
-            if (video_comment != null)
-                comment = video_comment;
-        } catch (Error err) {
-            warning("Unable to read video metadata: %s", err.message);
-        }
-        
-        if (exposure_time == 0) {
-            // Use time reported by Gstreamer, if available.
-            exposure_time = (time_t) (reader.timestamp != null ? 
-                reader.timestamp.to_unix() : 0);
-        }
-        
-        params.row.video_id = VideoID();
-        params.row.filepath = file.get_path();
-        params.row.filesize = info.get_size();
-        params.row.timestamp = timestamp.tv_sec;
-        params.row.width = preview_frame.width;
-        params.row.height = preview_frame.height;
-        params.row.clip_duration = clip_duration;
-        params.row.is_interpretable = is_interpretable;
-        params.row.exposure_time = exposure_time;
-        params.row.import_id = params.import_id;
-        params.row.event_id = EventID();
-        params.row.md5 = params.md5;
-        params.row.time_created = 0;
-        params.row.title = title;
-        params.row.comment = comment;
-        params.row.backlinks = "";
-        params.row.time_reimported = 0;
-        params.row.flags = 0;
-
-        if (params.thumbnails != null) {
-            params.thumbnails = new Thumbnails();
-            ThumbnailCache.generate_for_video_frame(params.thumbnails, preview_frame);
-        }
-        
-#if MEASURE_IMPORT
-        debug("IMPORT: total time to import video = %lf", total_time.elapsed());
-#endif
-        return ImportResult.SUCCESS;
-    }
-    
-    private void read_internal() throws VideoError {
-        if (!does_file_exist())
-            throw new VideoError.FILE("video file '%s' does not exist or is inaccessible".printf(
-                file.get_path()));
-        
-        try {
-            Gst.PbUtils.Discoverer d = new Gst.PbUtils.Discoverer((Gst.ClockTime) (Gst.SECOND * 5));
-            Gst.PbUtils.DiscovererInfo info = d.discover_uri(file.get_uri());
-            
-            clip_duration = ((double) info.get_duration()) / 1000000000.0;
-            
-            // Get creation time.
-            // TODO: Note that TAG_DATE can be changed to TAG_DATE_TIME in the future
-            // (and the corresponding output struct) in order to implement #2836.
-            Date? video_date = null;
-            if (info.get_tags() != null && info.get_tags().get_date(Gst.Tags.DATE, out video_date)) {
-                // possible for get_date() to return true and a null Date
-                if (video_date != null) {
-                    timestamp = new DateTime.local(video_date.get_year(), video_date.get_month(),
-                        video_date.get_day(), 0, 0, 0);
-                }
-            }
-        } catch (Error e) {
-            debug("Video read error: %s", e.message);
-            throw new VideoError.CONTENTS("GStreamer couldn't extract clip information: %s"
-                .printf(e.message));
-        }
-    }
-    
-    // Used by thumbnailer() to kill the external process if need be.
-    private bool on_thumbnailer_timer() {
-        debug("Thumbnailer timer called");
-        if (thumbnailer_pid != 0) {
-            debug("Killing thumbnailer process: %d", thumbnailer_pid);
-#if VALA_0_40
-            Posix.kill(thumbnailer_pid, Posix.Signal.KILL);
-#else
-            Posix.kill(thumbnailer_pid, Posix.SIGKILL);
-#endif
-        }
-        return false; // Don't call again.
-    }
-    
-    // Performs video thumbnailing.
-    // Note: not thread-safe if called from the same instance of the class.
-    private Gdk.Pixbuf? thumbnailer(string video_file) {
-        // Use Shotwell's thumbnailer, redirect output to stdout.
-        debug("Launching thumbnailer process: %s", AppDirs.get_thumbnailer_bin().get_path());
-        string[] argv = {AppDirs.get_thumbnailer_bin().get_path(), video_file};
-        int child_stdout;
-        try {
-            GLib.Process.spawn_async_with_pipes(null, argv, null, GLib.SpawnFlags.SEARCH_PATH | 
-                GLib.SpawnFlags.DO_NOT_REAP_CHILD, null, out thumbnailer_pid, null, out child_stdout,
-                null);
-            debug("Spawned thumbnailer, child pid: %d", (int) thumbnailer_pid);
-        } catch (Error e) {
-            debug("Error spawning process: %s", e.message);
-            if (thumbnailer_pid != 0)
-                GLib.Process.close_pid(thumbnailer_pid);
-            return null;
-        }
-        
-        // Start timer.
-        Timeout.add(THUMBNAILER_TIMEOUT, on_thumbnailer_timer);
-        
-        // Read pixbuf from stream.
-        Gdk.Pixbuf? buf = null;
-        try {
-            GLib.UnixInputStream unix_input = new GLib.UnixInputStream(child_stdout, true);
-            buf = new Gdk.Pixbuf.from_stream(unix_input, null);
-        } catch (Error e) {
-            debug("Error creating pixbuf: %s", e.message);
-            buf = null;
-        }
-        
-        // Make sure process exited properly.
-        int child_status = 0;
-        int ret_waitpid = Posix.waitpid(thumbnailer_pid, out child_status, 0);
-        if (ret_waitpid < 0) {
-            debug("waitpid returned error code: %d", ret_waitpid);
-            buf = null;
-        } else if (0 != Process.exit_status(child_status)) {
-            debug("Thumbnailer exited with error code: %d",
-                    Process.exit_status(child_status));
-            buf = null;
-        }
-        
-        GLib.Process.close_pid(thumbnailer_pid);
-        thumbnailer_pid = 0;
-        return buf;
-    }
-    
-    private bool does_file_exist() {
-        return FileUtils.test(file.get_path(), FileTest.EXISTS | FileTest.IS_REGULAR);
-    }
-    
-    public Gdk.Pixbuf? read_preview_frame() {
-        if (preview_frame != null)
-            return preview_frame;
-        
-        if (!does_file_exist())
-            return null;
-        
-        // Get preview frame from thumbnailer.
-        preview_frame = thumbnailer(file.get_path());
-        if (null == preview_frame)
-            preview_frame = Resources.get_noninterpretable_badge_pixbuf();
-        
-        return preview_frame;
-    }
-    
-    public double read_clip_duration() throws VideoError {
-        if (clip_duration == UNKNOWN_CLIP_DURATION)
-            read_internal();
-
-        return clip_duration;
-    }
-    
-    public VideoMetadata read_metadata() throws Error {
-        VideoMetadata metadata = new VideoMetadata();
-        metadata.read_from_file(File.new_for_path(file.get_path()));
-        
-        return metadata;
-    }
-}
-
 public class Video : VideoSource, Flaggable, Monitorable, Dateable {
     public const string TYPENAME = "video";
     
@@ -1056,172 +736,4 @@ public class Video : VideoSource, Flaggable, Monitorable, Dateable {
     }
 }
 
-public class VideoSourceCollection : MediaSourceCollection {
-    public enum State {
-        UNKNOWN,
-        ONLINE,
-        OFFLINE,
-        TRASH
-    }
-    
-    public override TransactionController transaction_controller {
-        get {
-            if (_transaction_controller == null)
-                _transaction_controller = new MediaSourceTransactionController(this);
-            
-            return _transaction_controller;
-        }
-    }
-    
-    private TransactionController _transaction_controller = null;
-    private Gee.MultiMap<uint64?, Video> filesize_to_video =
-        new Gee.TreeMultiMap<uint64?, Video>(uint64_compare);
-    
-    public VideoSourceCollection() {
-        base("VideoSourceCollection", get_video_key);
-
-        get_trashcan().contents_altered.connect(on_trashcan_contents_altered);
-        get_offline_bin().contents_altered.connect(on_offline_contents_altered);
-    }
-    
-    protected override MediaSourceHoldingTank create_trashcan() {
-        return new MediaSourceHoldingTank(this, is_video_trashed, get_video_key);
-    }
-    
-    protected override MediaSourceHoldingTank create_offline_bin() {
-        return new MediaSourceHoldingTank(this, is_video_offline, get_video_key);
-    }
-    
-    public override MediaMonitor create_media_monitor(Workers workers, Cancellable cancellable) {
-        return new VideoMonitor(cancellable);
-    }
-    
-    public override bool holds_type_of_source(DataSource source) {
-        return source is Video;
-    }
-    
-    public override string get_typename() {
-        return Video.TYPENAME;
-    }
-    
-    public override bool is_file_recognized(File file) {
-        return VideoReader.is_supported_video_file(file);
-    }
-    
-    private void on_trashcan_contents_altered(Gee.Collection<DataSource>? added,
-        Gee.Collection<DataSource>? removed) {
-        trashcan_contents_altered((Gee.Collection<Video>?) added,
-            (Gee.Collection<Video>?) removed);
-    }
-
-    private void on_offline_contents_altered(Gee.Collection<DataSource>? added,
-        Gee.Collection<DataSource>? removed) {
-        offline_contents_altered((Gee.Collection<Video>?) added,
-            (Gee.Collection<Video>?) removed);
-    }
 
-    protected override MediaSource? fetch_by_numeric_id(int64 numeric_id) {
-        return fetch(VideoID(numeric_id));
-    }
-
-    public static int64 get_video_key(DataSource source) {
-        Video video = (Video) source;
-        VideoID video_id = video.get_video_id();
-        
-        return video_id.id;
-    }
-    
-    public static bool is_video_trashed(DataSource source) {
-        return ((Video) source).is_trashed();
-    }
-    
-    public static bool is_video_offline(DataSource source) {
-        return ((Video) source).is_offline();
-    }
-    
-    public Video fetch(VideoID video_id) {
-        return (Video) fetch_by_key(video_id.id);
-    }
-    
-    public override Gee.Collection<string> get_event_source_ids(EventID event_id){
-        return VideoTable.get_instance().get_event_source_ids(event_id);
-    }
-    
-    public Video? get_state_by_file(File file, out State state) {
-        Video? video = (Video?) fetch_by_master_file(file);
-        if (video != null) {
-            state = State.ONLINE;
-            
-            return video;
-        }
-        
-        video = (Video?) get_trashcan().fetch_by_master_file(file);
-        if (video != null) {
-            state = State.TRASH;
-            
-            return video;
-        }
-        
-        video = (Video?) get_offline_bin().fetch_by_master_file(file);
-        if (video != null) {
-            state = State.OFFLINE;
-            
-            return video;
-        }
-        
-        state = State.UNKNOWN;
-        
-        return null;
-    }
-    
-    private void compare_backing(Video video, FileInfo info, Gee.Collection<Video> matching_master) {
-        if (video.get_filesize() != info.get_size())
-            return;
-        
-        if (video.get_timestamp() == info.get_modification_time().tv_sec)
-            matching_master.add(video);
-    }
-    
-    public void fetch_by_matching_backing(FileInfo info, Gee.Collection<Video> matching_master) {
-        foreach (DataObject object in get_all())
-            compare_backing((Video) object, info, matching_master);
-        
-        foreach (MediaSource media in get_offline_bin_contents())
-            compare_backing((Video) media, info, matching_master);
-    }
-    
-    protected override void notify_contents_altered(Gee.Iterable<DataObject>? added,
-        Gee.Iterable<DataObject>? removed) {
-        if (added != null) {
-            foreach (DataObject object in added) {
-                Video video = (Video) object;
-                
-                filesize_to_video.set(video.get_master_filesize(), video);
-            }
-        }
-        
-        if (removed != null) {
-            foreach (DataObject object in removed) {
-                Video video = (Video) object;
-                
-                filesize_to_video.remove(video.get_master_filesize(), video);
-            }
-        }
-        
-        base.notify_contents_altered(added, removed);
-    }
-    
-    public VideoID get_basename_filesize_duplicate(string basename, uint64 filesize) {
-        foreach (Video video in filesize_to_video.get(filesize)) {
-            if (utf8_ci_compare(video.get_master_file().get_basename(), basename) == 0)
-                return video.get_video_id();
-        }
-        
-        return VideoID(); // the default constructor of the VideoID struct creates an invalid
-                          // video id, which is just what we want in this case
-    }
-    
-    public bool has_basename_filesize_duplicate(string basename, uint64 filesize) {
-        return get_basename_filesize_duplicate(basename, filesize).is_valid();
-    }
-}
diff --git a/src/video-support/VideoImportParams.vala b/src/video-support/VideoImportParams.vala
new file mode 100644
index 00000000..a7bb96ee
--- /dev/null
+++ b/src/video-support/VideoImportParams.vala
@@ -0,0 +1,30 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+public class VideoImportParams {
+    // IN:
+    public File file;
+    public ImportID import_id = ImportID();
+    public string? md5;
+    public time_t exposure_time_override;
+    
+    // IN/OUT:
+    public Thumbnails? thumbnails;
+    
+    // OUT:
+    public VideoRow row = new VideoRow();
+    
+    public VideoImportParams(File file, ImportID import_id, string? md5,
+        Thumbnails? thumbnails = null, time_t exposure_time_override = 0) {
+        this.file = file;
+        this.import_id = import_id;
+        this.md5 = md5;
+        this.thumbnails = thumbnails;
+        this.exposure_time_override = exposure_time_override;
+    }
+}
+
+
diff --git a/src/video-support/VideoReader.vala b/src/video-support/VideoReader.vala
new file mode 100644
index 00000000..06232df5
--- /dev/null
+++ b/src/video-support/VideoReader.vala
@@ -0,0 +1,304 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+public errordomain VideoError {
+    FILE,          // there's a problem reading the video container file (doesn't exist, no read
+                   // permission, etc.)
+
+    CONTENTS,      // we can read the container file but its contents are indecipherable (no codec,
+                   // malformed data, etc.)
+}
+
+public class VideoReader {
+    private const double UNKNOWN_CLIP_DURATION = -1.0;
+    private const uint THUMBNAILER_TIMEOUT = 10000; // In milliseconds.
+
+    // File extensions for video containers that pack only metadata as per the AVCHD spec
+    private const string[] METADATA_ONLY_FILE_EXTENSIONS = { "bdm", "bdmv", "cpi", "mpl" };
+    
+    private double clip_duration = UNKNOWN_CLIP_DURATION;
+    private Gdk.Pixbuf preview_frame = null;
+    private File file = null;
+    private GLib.Pid thumbnailer_pid = 0;
+    public DateTime? timestamp { get; private set; default = null; }
+
+    public VideoReader(File file) {
+        this.file = file;
+     }
+    
+    public static bool is_supported_video_file(File file) {
+        var mime_type = ContentType.guess(file.get_basename(), new uchar[0], null);
+        // special case: deep-check content-type of files ending with .ogg
+        if (mime_type == "audio/ogg" && file.has_uri_scheme("file")) {
+            try {
+                var info = file.query_info(FileAttribute.STANDARD_CONTENT_TYPE,
+                                           FileQueryInfoFlags.NONE);
+                var content_type = info.get_content_type();
+                if (content_type != null && content_type.has_prefix ("video/")) {
+                    return true;
+                }
+            } catch (Error error) {
+                debug("Failed to query content type: %s", error.message);
+            }
+        }
+
+        return is_supported_video_filename(file.get_basename());
+    }
+
+    public static bool is_supported_video_filename(string filename) {
+        string mime_type;
+        mime_type = ContentType.guess(filename, new uchar[0], null);
+        // Guessed mp4 from filename has application/ as prefix, so check for mp4 in the end
+        if (mime_type.has_prefix ("video/") || mime_type.has_suffix("mp4")) {
+            string? extension = null;
+            string? name = null;
+            disassemble_filename(filename, out name, out extension);
+
+            if (extension == null)
+                return true;
+
+            foreach (string s in METADATA_ONLY_FILE_EXTENSIONS) {
+                if (utf8_ci_compare(s, extension) == 0)
+                    return false;
+            }
+
+            return true;
+        } else {
+            debug("Skipping %s, unsupported mime type %s", filename, mime_type);
+            return false;
+        }
+    }
+    
+    public static ImportResult prepare_for_import(VideoImportParams params) {
+#if MEASURE_IMPORT
+        Timer total_time = new Timer();
+#endif
+        File file = params.file;
+        
+        FileInfo info = null;
+        try {
+            info = file.query_info(DirectoryMonitor.SUPPLIED_ATTRIBUTES,
+                FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
+        } catch (Error err) {
+            return ImportResult.FILE_ERROR;
+        }
+        
+        if (info.get_file_type() != FileType.REGULAR)
+            return ImportResult.NOT_A_FILE;
+        
+        if (!is_supported_video_file(file)) {
+            message("Not importing %s: file is marked as a video file but doesn't have a" +
+                "supported extension", file.get_path());
+            
+            return ImportResult.UNSUPPORTED_FORMAT;
+        }
+        
+        TimeVal timestamp = info.get_modification_time();
+        
+        // make sure params has a valid md5
+        assert(params.md5 != null);
+
+        time_t exposure_time = params.exposure_time_override;
+        string title = "";
+        string comment = "";
+        
+        VideoReader reader = new VideoReader(file);
+        bool is_interpretable = true;
+        double clip_duration = 0.0;
+        Gdk.Pixbuf preview_frame = reader.read_preview_frame();
+        try {
+            clip_duration = reader.read_clip_duration();
+        } catch (VideoError err) {
+            if (err is VideoError.FILE) {
+                return ImportResult.FILE_ERROR;
+            } else if (err is VideoError.CONTENTS) {
+                is_interpretable = false;
+                clip_duration = 0.0;
+            } else {
+                error("can't prepare video for import: an unknown kind of video error occurred");
+            }
+        }
+        
+        try {
+            VideoMetadata metadata = reader.read_metadata();
+            MetadataDateTime? creation_date_time = metadata.get_creation_date_time();
+            
+            if (creation_date_time != null && creation_date_time.get_timestamp() != 0)
+                exposure_time = creation_date_time.get_timestamp();
+            
+            string? video_title = metadata.get_title();
+            string? video_comment = metadata.get_comment();
+            if (video_title != null)
+                title = video_title;
+            if (video_comment != null)
+                comment = video_comment;
+        } catch (Error err) {
+            warning("Unable to read video metadata: %s", err.message);
+        }
+        
+        if (exposure_time == 0) {
+            // Use time reported by Gstreamer, if available.
+            exposure_time = (time_t) (reader.timestamp != null ? 
+                reader.timestamp.to_unix() : 0);
+        }
+        
+        params.row.video_id = VideoID();
+        params.row.filepath = file.get_path();
+        params.row.filesize = info.get_size();
+        params.row.timestamp = timestamp.tv_sec;
+        params.row.width = preview_frame.width;
+        params.row.height = preview_frame.height;
+        params.row.clip_duration = clip_duration;
+        params.row.is_interpretable = is_interpretable;
+        params.row.exposure_time = exposure_time;
+        params.row.import_id = params.import_id;
+        params.row.event_id = EventID();
+        params.row.md5 = params.md5;
+        params.row.time_created = 0;
+        params.row.title = title;
+        params.row.comment = comment;
+        params.row.backlinks = "";
+        params.row.time_reimported = 0;
+        params.row.flags = 0;
+
+        if (params.thumbnails != null) {
+            params.thumbnails = new Thumbnails();
+            ThumbnailCache.generate_for_video_frame(params.thumbnails, preview_frame);
+        }
+        
+#if MEASURE_IMPORT
+        debug("IMPORT: total time to import video = %lf", total_time.elapsed());
+#endif
+        return ImportResult.SUCCESS;
+    }
+    
+    private void read_internal() throws VideoError {
+        if (!does_file_exist())
+            throw new VideoError.FILE("video file '%s' does not exist or is inaccessible".printf(
+                file.get_path()));
+        
+        try {
+            Gst.PbUtils.Discoverer d = new Gst.PbUtils.Discoverer((Gst.ClockTime) (Gst.SECOND * 5));
+            Gst.PbUtils.DiscovererInfo info = d.discover_uri(file.get_uri());
+            
+            clip_duration = ((double) info.get_duration()) / 1000000000.0;
+            
+            // Get creation time.
+            // TODO: Note that TAG_DATE can be changed to TAG_DATE_TIME in the future
+            // (and the corresponding output struct) in order to implement #2836.
+            Date? video_date = null;
+            if (info.get_tags() != null && info.get_tags().get_date(Gst.Tags.DATE, out video_date)) {
+                // possible for get_date() to return true and a null Date
+                if (video_date != null) {
+                    timestamp = new DateTime.local(video_date.get_year(), video_date.get_month(),
+                        video_date.get_day(), 0, 0, 0);
+                }
+            }
+        } catch (Error e) {
+            debug("Video read error: %s", e.message);
+            throw new VideoError.CONTENTS("GStreamer couldn't extract clip information: %s"
+                .printf(e.message));
+        }
+    }
+    
+    // Used by thumbnailer() to kill the external process if need be.
+    private bool on_thumbnailer_timer() {
+        debug("Thumbnailer timer called");
+        if (thumbnailer_pid != 0) {
+            debug("Killing thumbnailer process: %d", thumbnailer_pid);
+#if VALA_0_40
+            Posix.kill(thumbnailer_pid, Posix.Signal.KILL);
+#else
+            Posix.kill(thumbnailer_pid, Posix.SIGKILL);
+#endif
+        }
+        return false; // Don't call again.
+    }
+    
+    // Performs video thumbnailing.
+    // Note: not thread-safe if called from the same instance of the class.
+    private Gdk.Pixbuf? thumbnailer(string video_file) {
+        // Use Shotwell's thumbnailer, redirect output to stdout.
+        debug("Launching thumbnailer process: %s", AppDirs.get_thumbnailer_bin().get_path());
+        string[] argv = {AppDirs.get_thumbnailer_bin().get_path(), video_file};
+        int child_stdout;
+        try {
+            GLib.Process.spawn_async_with_pipes(null, argv, null, GLib.SpawnFlags.SEARCH_PATH | 
+                GLib.SpawnFlags.DO_NOT_REAP_CHILD, null, out thumbnailer_pid, null, out child_stdout,
+                null);
+            debug("Spawned thumbnailer, child pid: %d", (int) thumbnailer_pid);
+        } catch (Error e) {
+            debug("Error spawning process: %s", e.message);
+            if (thumbnailer_pid != 0)
+                GLib.Process.close_pid(thumbnailer_pid);
+            return null;
+        }
+        
+        // Start timer.
+        Timeout.add(THUMBNAILER_TIMEOUT, on_thumbnailer_timer);
+        
+        // Read pixbuf from stream.
+        Gdk.Pixbuf? buf = null;
+        try {
+            GLib.UnixInputStream unix_input = new GLib.UnixInputStream(child_stdout, true);
+            buf = new Gdk.Pixbuf.from_stream(unix_input, null);
+        } catch (Error e) {
+            debug("Error creating pixbuf: %s", e.message);
+            buf = null;
+        }
+        
+        // Make sure process exited properly.
+        int child_status = 0;
+        int ret_waitpid = Posix.waitpid(thumbnailer_pid, out child_status, 0);
+        if (ret_waitpid < 0) {
+            debug("waitpid returned error code: %d", ret_waitpid);
+            buf = null;
+        } else if (0 != Process.exit_status(child_status)) {
+            debug("Thumbnailer exited with error code: %d",
+                    Process.exit_status(child_status));
+            buf = null;
+        }
+        
+        GLib.Process.close_pid(thumbnailer_pid);
+        thumbnailer_pid = 0;
+        return buf;
+    }
+    
+    private bool does_file_exist() {
+        return FileUtils.test(file.get_path(), FileTest.EXISTS | FileTest.IS_REGULAR);
+    }
+    
+    public Gdk.Pixbuf? read_preview_frame() {
+        if (preview_frame != null)
+            return preview_frame;
+        
+        if (!does_file_exist())
+            return null;
+        
+        // Get preview frame from thumbnailer.
+        preview_frame = thumbnailer(file.get_path());
+        if (null == preview_frame)
+            preview_frame = Resources.get_noninterpretable_badge_pixbuf();
+        
+        return preview_frame;
+    }
+    
+    public double read_clip_duration() throws VideoError {
+        if (clip_duration == UNKNOWN_CLIP_DURATION)
+            read_internal();
+
+        return clip_duration;
+    }
+    
+    public VideoMetadata read_metadata() throws Error {
+        VideoMetadata metadata = new VideoMetadata();
+        metadata.read_from_file(File.new_for_path(file.get_path()));
+        
+        return metadata;
+    }
+}
+
+
diff --git a/src/video-support/VideoSourceCollection.vala b/src/video-support/VideoSourceCollection.vala
new file mode 100644
index 00000000..aa294e67
--- /dev/null
+++ b/src/video-support/VideoSourceCollection.vala
@@ -0,0 +1,175 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+public class VideoSourceCollection : MediaSourceCollection {
+    public enum State {
+        UNKNOWN,
+        ONLINE,
+        OFFLINE,
+        TRASH
+    }
+    
+    public override TransactionController transaction_controller {
+        get {
+            if (_transaction_controller == null)
+                _transaction_controller = new MediaSourceTransactionController(this);
+            
+            return _transaction_controller;
+        }
+    }
+    
+    private TransactionController _transaction_controller = null;
+    private Gee.MultiMap<uint64?, Video> filesize_to_video =
+        new Gee.TreeMultiMap<uint64?, Video>(uint64_compare);
+    
+    public VideoSourceCollection() {
+        base("VideoSourceCollection", get_video_key);
+
+        get_trashcan().contents_altered.connect(on_trashcan_contents_altered);
+        get_offline_bin().contents_altered.connect(on_offline_contents_altered);
+    }
+    
+    protected override MediaSourceHoldingTank create_trashcan() {
+        return new MediaSourceHoldingTank(this, is_video_trashed, get_video_key);
+    }
+    
+    protected override MediaSourceHoldingTank create_offline_bin() {
+        return new MediaSourceHoldingTank(this, is_video_offline, get_video_key);
+    }
+    
+    public override MediaMonitor create_media_monitor(Workers workers, Cancellable cancellable) {
+        return new VideoMonitor(cancellable);
+    }
+    
+    public override bool holds_type_of_source(DataSource source) {
+        return source is Video;
+    }
+    
+    public override string get_typename() {
+        return Video.TYPENAME;
+    }
+    
+    public override bool is_file_recognized(File file) {
+        return VideoReader.is_supported_video_file(file);
+    }
+    
+    private void on_trashcan_contents_altered(Gee.Collection<DataSource>? added,
+        Gee.Collection<DataSource>? removed) {
+        trashcan_contents_altered((Gee.Collection<Video>?) added,
+            (Gee.Collection<Video>?) removed);
+    }
+
+    private void on_offline_contents_altered(Gee.Collection<DataSource>? added,
+        Gee.Collection<DataSource>? removed) {
+        offline_contents_altered((Gee.Collection<Video>?) added,
+            (Gee.Collection<Video>?) removed);
+    }
+
+    protected override MediaSource? fetch_by_numeric_id(int64 numeric_id) {
+        return fetch(VideoID(numeric_id));
+    }
+
+    public static int64 get_video_key(DataSource source) {
+        Video video = (Video) source;
+        VideoID video_id = video.get_video_id();
+        
+        return video_id.id;
+    }
+    
+    public static bool is_video_trashed(DataSource source) {
+        return ((Video) source).is_trashed();
+    }
+    
+    public static bool is_video_offline(DataSource source) {
+        return ((Video) source).is_offline();
+    }
+    
+    public Video fetch(VideoID video_id) {
+        return (Video) fetch_by_key(video_id.id);
+    }
+    
+    public override Gee.Collection<string> get_event_source_ids(EventID event_id){
+        return VideoTable.get_instance().get_event_source_ids(event_id);
+    }
+    
+    public Video? get_state_by_file(File file, out State state) {
+        Video? video = (Video?) fetch_by_master_file(file);
+        if (video != null) {
+            state = State.ONLINE;
+            
+            return video;
+        }
+        
+        video = (Video?) get_trashcan().fetch_by_master_file(file);
+        if (video != null) {
+            state = State.TRASH;
+            
+            return video;
+        }
+        
+        video = (Video?) get_offline_bin().fetch_by_master_file(file);
+        if (video != null) {
+            state = State.OFFLINE;
+            
+            return video;
+        }
+        
+        state = State.UNKNOWN;
+        
+        return null;
+    }
+    
+    private void compare_backing(Video video, FileInfo info, Gee.Collection<Video> matching_master) {
+        if (video.get_filesize() != info.get_size())
+            return;
+        
+        if (video.get_timestamp() == info.get_modification_time().tv_sec)
+            matching_master.add(video);
+    }
+    
+    public void fetch_by_matching_backing(FileInfo info, Gee.Collection<Video> matching_master) {
+        foreach (DataObject object in get_all())
+            compare_backing((Video) object, info, matching_master);
+        
+        foreach (MediaSource media in get_offline_bin_contents())
+            compare_backing((Video) media, info, matching_master);
+    }
+    
+    protected override void notify_contents_altered(Gee.Iterable<DataObject>? added,
+        Gee.Iterable<DataObject>? removed) {
+        if (added != null) {
+            foreach (DataObject object in added) {
+                Video video = (Video) object;
+                
+                filesize_to_video.set(video.get_master_filesize(), video);
+            }
+        }
+        
+        if (removed != null) {
+            foreach (DataObject object in removed) {
+                Video video = (Video) object;
+                
+                filesize_to_video.remove(video.get_master_filesize(), video);
+            }
+        }
+        
+        base.notify_contents_altered(added, removed);
+    }
+    
+    public VideoID get_basename_filesize_duplicate(string basename, uint64 filesize) {
+        foreach (Video video in filesize_to_video.get(filesize)) {
+            if (utf8_ci_compare(video.get_master_file().get_basename(), basename) == 0)
+                return video.get_video_id();
+        }
+        
+        return VideoID(); // the default constructor of the VideoID struct creates an invalid
+                          // video id, which is just what we want in this case
+    }
+    
+    public bool has_basename_filesize_duplicate(string basename, uint64 filesize) {
+        return get_basename_filesize_duplicate(basename, filesize).is_valid();
+    }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]