public static IEnumerable <SmartPlaylistSource> LoadAll(PrimarySource parent) { ClearTemporary(); using (HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query( @"SELECT SmartPlaylistID, Name, Condition, OrderBy, LimitNumber, LimitCriterion, PrimarySourceID, CachedCount, IsTemporary, IsHiddenWhenEmpty FROM CoreSmartPlaylists WHERE PrimarySourceID = ?", parent.DbId))) { while (reader.Read()) { SmartPlaylistSource playlist = null; try { playlist = new SmartPlaylistSource( reader.Get <int> (0), reader.Get <string> (1), reader.Get <string> (2), reader.Get <string> (3), reader.Get <string> (4), reader.Get <string> (5), parent, reader.Get <int> (7), reader.Get <bool> (8), reader.Get <bool> (9) ); } catch (Exception e) { Log.Warning("Ignoring Smart Playlist", String.Format("Caught error: {0}", e), false); } if (playlist != null) { yield return(playlist); } } } }
public List <DatabaseTrackInfo> ParseQuery(XmlDocument xml_response) { Log.Debug("[Shoutcast] <ParseQuery> Start"); List <DatabaseTrackInfo> station_list; XmlNodeList XML_station_nodes = xml_response.GetElementsByTagName("station"); station_list = new List <DatabaseTrackInfo> (XML_station_nodes.Count); PrimarySource source = GetInternetRadioSource(); // If not found, throws exception caught in upper level. foreach (XmlNode node in XML_station_nodes) { XmlAttributeCollection xml_attributes = node.Attributes; try { string name = xml_attributes.GetNamedItem("name").InnerText; string media_type = xml_attributes.GetNamedItem("mt").InnerText; string id = xml_attributes.GetNamedItem("id").InnerText; string genre = xml_attributes.GetNamedItem("genre").InnerText; string now_playing = xml_attributes.GetNamedItem("ct").InnerText; string bitrate = xml_attributes.GetNamedItem("br").InnerText; int id_int; int bitrate_int; if (!Int32.TryParse(id.Trim(), out id_int)) { continue; //Something wrong with id, skip this } DatabaseTrackInfo new_station = new DatabaseTrackInfo(); new_station.Uri = new SafeUri("http://207.200.98.1/sbin/tunein-station.pls?id=" + id); new_station.ArtistName = "www.shoutcast.com"; new_station.Genre = genre; new_station.TrackTitle = name; new_station.Comment = now_playing; new_station.AlbumTitle = now_playing; new_station.MimeType = media_type; new_station.ExternalId = id_int; new_station.PrimarySource = source; new_station.IsLive = true; Int32.TryParse(bitrate.Trim(), out bitrate_int); new_station.BitRate = bitrate_int; new_station.IsLive = true; Log.DebugFormat("[Shoutcast] <ParseQuery> Station found! Name: {0} URL: {1}", name, new_station.Uri.ToString()); station_list.Add(new_station); } catch (Exception e) { Log.Warning("[Shoutcast] <ParseQuery> ERROR: ", e); continue; } } Log.Debug("[Shoutcast] <ParseQuery> End"); return(station_list); }
public static void ImportPlaylistToLibrary(string path, PrimarySource source, DatabaseImportManager importer) { try { SafeUri uri = new SafeUri(path); PlaylistParser parser = new PlaylistParser(); string relative_dir = System.IO.Path.GetDirectoryName(uri.LocalPath); if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar) { relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar; } parser.BaseUri = new Uri(relative_dir); if (parser.Parse(uri)) { List <string> uris = new List <string> (); foreach (Dictionary <string, object> element in parser.Elements) { uris.Add(((Uri)element["uri"]).LocalPath); } ImportPlaylistWorker worker = new ImportPlaylistWorker( parser.Title, uris.ToArray(), source, importer); worker.Import(); } } catch (Exception e) { Hyena.Log.Exception(e); } }
public ImportPlaylistWorker(string name, string [] uris, PrimarySource source, DatabaseImportManager importer) { this.name = name; this.uris = uris; this.source = source; this.importer = importer; }
//Full Data Mapping public PrimarySourceDataModel MappingToPrimarySourceDataModelFullData(PrimarySource obj) { PrimarySourceDataModel ReturnObj = new PrimarySourceDataModel() { Id = obj.Id, Code = obj.Code, Name = obj.Name, FacId = obj.FactoryId, FacName = GetFactoryName(obj.FactoryId), DesignValue = obj.DesignValue, MaxCurrent = obj.MaxCurrent, Topology = obj.Topology, Type = obj.Type }; foreach (var item in obj.secondarySources) { ReturnObj.secondarySources.Add(new SecoundrySouresDataModelSim() { Id = item.Id, Code = item.Code, Name = item.Name, PS_Id = obj.Id, PirmarySourceName = obj.Name }); } return(ReturnObj); }
public UPnPTrackInfo(Item track, PrimarySource source) : base() { if (track == null) { throw new ArgumentNullException("track"); } if (source == null) { throw new ArgumentNullException("source"); } TrackTitle = track.Title; Resource resource = FindSuitableResource(track.Resources); if (resource != null) { BitRate = (int)resource.BitRate.GetValueOrDefault(); BitsPerSample = (int)resource.BitsPerSample.GetValueOrDefault(); Duration = resource.Duration.GetValueOrDefault(); SampleRate = (int)resource.SampleFrequency.GetValueOrDefault(); FileSize = (int)resource.Size.GetValueOrDefault(); Uri = new SafeUri(resource.Uri); } else { CanPlay = false; } ExternalId = ++id; PrimarySource = source; }
public static void ImportPlaylistToLibrary(string path, PrimarySource source, DatabaseImportManager importer) { try { SafeUri uri = new SafeUri(path); PlaylistParser parser = new PlaylistParser(); string relative_dir = System.IO.Path.GetDirectoryName(uri.LocalPath); if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar) { relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar; } parser.BaseUri = new Uri(relative_dir); if (parser.Parse(uri)) { List <string> uris = new List <string> (); foreach (PlaylistElement element in parser.Elements) { uris.Add(element.Uri.LocalPath); } if (source == null) { if (uris.Count > 0) { // Get the media attribute of the 1st Uri in Playlist // and then determine whether the playlist belongs to Video or Music SafeUri uri1 = new SafeUri(uris[0]); var track = new TrackInfo(); StreamTagger.TrackInfoMerge(track, uri1); if (track.HasAttribute(TrackMediaAttributes.VideoStream)) { source = ServiceManager.SourceManager.VideoLibrary; } else { source = ServiceManager.SourceManager.MusicLibrary; } } } // Give source a fallback value - MusicLibrary when it's null if (source == null) { source = ServiceManager.SourceManager.MusicLibrary; } // Only import an non-empty playlist if (uris.Count > 0) { ImportPlaylistWorker worker = new ImportPlaylistWorker( parser.Title, uris.ToArray(), source, importer); worker.Import(); } } } catch (Exception e) { Hyena.Log.Exception(e); } }
public void NotifyAllSources() { foreach (int primary_source_id in counts.Keys) { PrimarySource.GetById(primary_source_id).NotifyTracksAdded(); } counts.Clear(); }
public override void Update() { if (PrimarySource != null) { PrimarySource.UpdateMetadata(this); } base.Update(); }
private void RemovePrimarySource(Source s) { PrimarySource p = s as PrimarySource; if (p != null && sources.Remove(p)) { p.TracksChanged -= OnTracksChanged; } }
public SmartPlaylistSource ToSmartPlaylistSource(PrimarySource primary_source) { return(new SmartPlaylistSource( Name, UserQueryParser.Parse(Condition, BansheeQuery.FieldSet), Order, Limit, LimitNumber, primary_source )); }
public void NotifyAllSources() { var all_primary_source_ids = new List <long> (counts.Keys); foreach (long primary_source_id in all_primary_source_ids) { PrimarySource.GetById(primary_source_id).NotifyTracksAdded(); } counts.Clear(); }
private void AddPrimarySource(Source s) { PrimarySource p = s as PrimarySource; if (p != null && p.HasEditableTrackProperties) { sources.Add(p); p.TracksChanged += OnTracksChanged; } }
public AbstractPlaylistSource(string generic_name, string name, PrimarySource parent) : base() { GenericName = generic_name; Name = name; if (parent != null) { primary_source_id = parent.DbId; SetParentSource(parent); } }
public TrackSyncPipelineElement(PrimarySource psource, DateTime scan_started) : base() { this.psource = psource; this.scan_started = scan_started; fetch_command = DatabaseTrackInfo.Provider.CreateFetchCommand( "CoreTracks.PrimarySourceID = ? AND CoreTracks.Uri = ? LIMIT 1"); fetch_similar_command = DatabaseTrackInfo.Provider.CreateFetchCommand( "CoreTracks.PrimarySourceID = ? AND CoreTracks.LastSyncedStamp < ? AND CoreTracks.MetadataHash = ?"); }
public PatternDisplay(PrimarySource source, object a, object b) { this.source = source; folder = (PatternComboBox)a; file = (PatternComboBox)b; folder.Changed += OnChanged; file.Changed += OnChanged; OnChanged(null, null); }
public RescanPipeline(LibrarySource psource) : base() { this.psource = psource; scan_started = DateTime.Now; AddElement(new Banshee.IO.DirectoryScannerPipelineElement()); AddElement(track_sync = new TrackSyncPipelineElement(psource, scan_started)); Finished += OnFinished; BuildJob(); Enqueue(psource.BaseDirectory); }
public TrackSyncPipelineElement(PrimarySource psource, DateTime scan_started) : base() { this.psource = psource; this.scan_started = scan_started; fetch_command = DatabaseTrackInfo.Provider.CreateFetchCommand(String.Format( "CoreTracks.PrimarySourceID = ? AND {0} = ? LIMIT 1", Banshee.Query.BansheeQuery.UriField.Column)); fetch_similar_command = DatabaseTrackInfo.Provider.CreateFetchCommand( "CoreTracks.PrimarySourceID = ? AND CoreTracks.LastSyncedStamp < ? AND CoreTracks.MetadataHash = ?"); }
public static void ClearTemporary(PrimarySource parent) { if (parent != null) { ServiceManager.DbConnection.BeginTransaction(); ServiceManager.DbConnection.Execute(@" DELETE FROM CorePlaylistEntries WHERE PlaylistID IN (SELECT PlaylistID FROM CorePlaylists WHERE PrimarySourceID = ? AND IsTemporary = 1); DELETE FROM CorePlaylists WHERE PrimarySourceID = ? AND IsTemporary = 1;", parent.DbId, parent.DbId ); ServiceManager.DbConnection.CommitTransaction(); } }
private void UpdateActions(bool force) { Source source = ActionSource; if ((force || source != last_source) && source != null) { IUnmapableSource unmapable = (source as IUnmapableSource); IImportSource import_source = (source as IImportSource); SmartPlaylistSource smart_playlist = (source as SmartPlaylistSource); PrimarySource primary_source = (source as PrimarySource) ?? (source.Parent as PrimarySource); UpdateAction("UnmapSourceAction", unmapable != null, unmapable != null && unmapable.CanUnmap, source); UpdateAction("RenameSourceAction", source.CanRename, true, null); UpdateAction("ImportSourceAction", import_source != null, import_source != null && import_source.CanImport, source); UpdateAction("ExportPlaylistAction", source is AbstractPlaylistSource, true, source); UpdateAction("SourcePropertiesAction", source.HasProperties, true, source); UpdateAction("SourcePreferencesAction", source.PreferencesPageId != null, true, source); UpdateAction("RefreshSmartPlaylistAction", smart_playlist != null && smart_playlist.CanRefresh, true, source); this["OpenSourceSwitcher"].Visible = false; bool playlists_writable = primary_source != null && primary_source.SupportsPlaylists && !primary_source.PlaylistsReadOnly; UpdateAction("NewPlaylistAction", playlists_writable, true, source); UpdateAction("NewSmartPlaylistAction", playlists_writable, true, source); /*UpdateAction ("NewSmartPlaylistFromSearchAction", (source is LibrarySource || source.Parent is LibrarySource), * !String.IsNullOrEmpty (source.FilterQuery), source);*/ ActionGroup browser_actions = Actions.FindActionGroup("BrowserView"); if (browser_actions != null) { IFilterableSource filterable_source = source as IFilterableSource; bool has_browser = filterable_source != null && filterable_source.AvailableFilters.Count > 0; UpdateAction(browser_actions["BrowserTopAction"], has_browser); UpdateAction(browser_actions["BrowserLeftAction"], has_browser); UpdateAction(browser_actions["BrowserVisibleAction"], has_browser); } last_source = source; } if (source != null) { UpdateAction("SortChildrenAction", source.ChildSortTypes.Length > 0 && source.Children.Count > 1, true, source); } Action <Source> handler = Updated; if (handler != null) { handler(source); } }
private void UpdateActions() { Source source = ServiceManager.SourceManager.ActiveSource; bool in_database = source is DatabaseSource; PrimarySource primary_source = (source as PrimarySource) ?? (source.Parent as PrimarySource); Hyena.Collections.Selection selection = (source is ITrackModelSource) ? (source as ITrackModelSource).TrackModel.Selection : null; if (selection != null) { Sensitive = Visible = true; bool has_selection = selection.Count > 0; foreach (string action in require_selection_actions) { this[action].Sensitive = has_selection; } bool has_single_selection = selection.Count == 1; this["SelectAllAction"].Sensitive = !selection.AllSelected; if (source != null) { ITrackModelSource track_source = source as ITrackModelSource; bool is_track_source = track_source != null; UpdateActions(is_track_source && source.CanSearch, has_single_selection, "SearchMenuAction", "SearchForSameArtistAction", "SearchForSameAlbumAction" ); UpdateAction("RemoveTracksAction", is_track_source && track_source.CanRemoveTracks, has_selection, source); UpdateAction("DeleteTracksFromDriveAction", is_track_source && track_source.CanDeleteTracks, has_selection, source); UpdateAction("RemoveTracksFromLibraryAction", source.Parent is LibrarySource, has_selection, null); UpdateAction("TrackPropertiesAction", source.HasViewableTrackProperties, has_selection, source); UpdateAction("TrackEditorAction", source.HasEditableTrackProperties, has_selection, source); UpdateAction("RateTracksAction", in_database, has_selection, null); UpdateAction("AddToPlaylistAction", in_database && primary_source != null && primary_source.SupportsPlaylists && !primary_source.PlaylistsReadOnly, has_selection, null); if (primary_source != null && !(primary_source is LibrarySource)) { this["DeleteTracksFromDriveAction"].Label = String.Format( Catalog.GetString("_Delete From \"{0}\""), primary_source.StorageName); } } } else { Sensitive = Visible = false; } }
/*public override void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, UserJob job) * { * Banshee.IO.File.Copy (track.Uri, uri, false); * }*/ protected override void AddTrack(DatabaseTrackInfo track) { // Ignore if already have it if (track.PrimarySourceId == DbId) { return; } PrimarySource source = track.PrimarySource; // If it's from a local primary source, change its PrimarySource if (source.IsLocal || source is LibrarySource) { track.PrimarySource = this; if (!(source is LibrarySource)) { track.CopyToLibraryIfAppropriate(false); } track.Save(false); // TODO optimize, remove this? I think it makes moving items // between local libraries very slow. //source.NotifyTracksChanged (); } else { // Figure out where we should put it if were to copy it var pattern = this.PathPattern ?? MusicLibrarySource.MusicFileNamePattern; string path = pattern.BuildFull(BaseDirectory, track); SafeUri uri = new SafeUri(path); // Make sure it's not already in the library // TODO optimize - no need to recreate this int [] every time if (DatabaseTrackInfo.ContainsUri(uri, new int [] { DbId })) { return; } // Since it's not, copy it and create a new TrackInfo object track.PrimarySource.CopyTrackTo(track, uri, AddTrackJob); // Create a new entry in CoreTracks for the copied file DatabaseTrackInfo new_track = new DatabaseTrackInfo(track); new_track.Uri = uri; new_track.PrimarySource = this; new_track.Save(false); } }
public void Save(bool notify, params QueryField [] fields_changed) { // If either the artist or album changed, if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true) { DatabaseArtistInfo artist = Artist; ArtistId = artist.DbId; DatabaseAlbumInfo album = Album; AlbumId = album.DbId; // TODO get rid of unused artists/albums } // If PlayCountField is not transient we still want to update the file only if it's from the music library var transient = transient_fields; if (!transient.Contains(BansheeQuery.PlayCountField) && !ServiceManager.SourceManager.MusicLibrary.Equals(PrimarySource)) { transient = new HashSet <QueryField> (transient_fields); transient.Add(BansheeQuery.PlayCountField); } if (fields_changed.Length == 0 || !transient.IsSupersetOf(fields_changed)) { DateUpdated = DateTime.Now; } bool is_new = (TrackId == 0); if (is_new) { LastSyncedStamp = DateAdded = DateUpdated = DateTime.Now; } ProviderSave(); if (notify && PrimarySource != null) { if (is_new) { PrimarySource.NotifyTracksAdded(); } else { PrimarySource.NotifyTracksChanged(fields_changed); } } }
public override bool TrackEqual(TrackInfo track) { if (PrimarySource != null && PrimarySource.TrackEqualHandler != null) { return(PrimarySource.TrackEqualHandler(this, track)); } DatabaseTrackInfo db_track = track as DatabaseTrackInfo; if (db_track == null) { return(base.TrackEqual(track)); } return(TrackEqual(this, db_track)); }
/// <summary> /// Adds the currently selected item(s) of the active source to the internet radio source /// as new stations. Any session data (as in live365 with activated user login) will previously /// be cleared. /// </summary> /// <param name="o"> /// A <see cref="System.Object"/> -- not used /// </param> /// <param name="e"> /// A <see cref="EventArgs"/> -- not used /// </param> protected void OnAddToInternetRadio(object o, EventArgs e) { PrimarySource internet_radio_source = GetInternetRadioSource(); PrimarySource current_source = ServiceManager.SourceManager.ActiveSource as PrimarySource; if (current_source == null) { Log.Debug("[LiveRadioSource]<OnAddToInternetRadio> ActiveSource not Primary"); return; } if (internet_radio_source == null) { Log.Debug("[LiveRadioSource]<OnAddToInternetRadio> Internet Radio not found"); return; } ITrackModelSource active_track_model_source = (ITrackModelSource)current_source; if (active_track_model_source.TrackModel.SelectedItems == null || active_track_model_source.TrackModel.SelectedItems.Count <= 0) { return; } ILiveRadioPlugin current_plugin = null; foreach (ILiveRadioPlugin plugin in plugins) { if (plugin.PluginSource != null && plugin.PluginSource.Equals(current_source)) { current_plugin = plugin; } } foreach (TrackInfo track in active_track_model_source.TrackModel.SelectedItems) { DatabaseTrackInfo station_track = new DatabaseTrackInfo(track as DatabaseTrackInfo); if (station_track != null) { station_track.PrimarySource = internet_radio_source; if (current_plugin != null) { station_track.Uri = current_plugin.CleanUpUrl(station_track.Uri); } station_track.Save(); } } }
public PrimarySource MappingToPrimarySourceWithId(PrimarySourceDataModel obj) { PrimarySource result = new PrimarySource() { Id = obj.Id, Name = obj.Name, Code = obj.Code, FactoryId = obj.FacId, DesignValue = obj.DesignValue, MaxCurrent = obj.MaxCurrent, Topology = obj.Topology, Type = obj.Type }; return(result); }
public static IEnumerable <PlaylistSource> LoadAll(PrimarySource parent) { ClearTemporary(); using (HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query( @"SELECT PlaylistID, Name, SortColumn, SortType, PrimarySourceID, CachedCount, IsTemporary FROM CorePlaylists WHERE Special = 0 AND PrimarySourceID = ?", parent.DbId))) { while (reader.Read()) { yield return(new PlaylistSource( reader.Get <string> (1), reader.Get <int> (0), reader.Get <int> (2), reader.Get <int> (3), parent, reader.Get <int> (5), reader.Get <bool> (6) )); } } }
private void UpdateForPlaylist(SmartPlaylistSource playlist) { PlaylistName = playlist.Name; Condition = playlist.ConditionTree; LimitEnabled = playlist.IsLimited; LimitValue = playlist.LimitValue; Limit = playlist.Limit; Order = playlist.QueryOrder; if (playlist.DbId > 0) { this.playlist = playlist; this.primary_source = playlist.PrimarySource; currently_editing = playlist; } }
//Mapping Single object To PSDM public PrimarySourceDataModel MappingToPrimarySourceDataModel(PrimarySource obj) { PrimarySourceDataModel ReturnObj = new PrimarySourceDataModel() { Id = obj.Id, Code = obj.Code, Name = obj.Name, FacId = obj.FactoryId, FacName = GetFactoryName(obj.FactoryId), DesignValue = obj.DesignValue, MaxCurrent = obj.MaxCurrent, Topology = obj.Topology, Type = obj.Type }; return(ReturnObj); }
public Editor(SmartPlaylistSource playlist) { currently_editing = playlist; this.playlist = playlist; this.primary_source = playlist.PrimarySource; /*Console.WriteLine ("Loading smart playlist into editor: {0}", * playlist.ConditionTree == null ? "" : playlist.ConditionTree.ToXml (BansheeQuery.FieldSet, true));*/ Initialize(); Title = Catalog.GetString("Edit Smart Playlist"); name_entry.Text = playlist.Name; UpdateForPlaylist(playlist); }