/// <summary> /// Submits a Track Scrobble request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="ScrobbleResponse"/></returns> /// <remarks>A track should only be scrobbled when the following conditions have been met: The track must be longer than 30 seconds. /// And the track has been played for at least half its duration, or for 4 minutes (whichever occurs earlier). See http://www.last.fm/api/scrobbling </remarks> /// <exception cref="InvalidOperationException"/> public bool Scrobble(Track track) { /* * if (track.Duration.TotalSeconds < MinimumScrobbleTrackLengthInSeconds) * { * return null; * throw new InvalidOperationException(string.Format("Duration is too short. Tracks shorter than {0} seconds in duration must not be scrobbled", * MinimumScrobbleTrackLengthInSeconds)); * }*/ if (!track.WhenStartedPlaying.HasValue) { throw new ArgumentException("A Track must have a WhenStartedPlaying value when Scrobbling"); } /* * int minimumPlayingTime = (int) track.Duration.TotalSeconds/2; * if (minimumPlayingTime > (4*60)) minimumPlayingTime = (4*60); * if (track.WhenStartedPlaying > DateTime.Now.AddSeconds(-minimumPlayingTime)) * { * throw new InvalidOperationException( * "Track has not been playing long enough. A scrobbled track must have been played for at least half its duration, or for 4 minutes (whichever occurs earlier)"); * }*/ return(TrackApi.Scrobble(track, Authentication)); }
/// <summary> /// /// </summary> /// <param name="apiKey">An API Key from Last.fm. See http://www.last.fm/api/account </param> /// <param name="apiSecret">An API Secret from Last.fm. See http://www.last.fm/api/account </param> /// <param name="sessionKey">An authorized Last.fm Session Key. See <see cref="GetSession"/></param> /// <exception cref="ArgumentNullException"/> public Scrobbler(string apiKey, string apiSecret, string sessionKey = null) { if (string.IsNullOrEmpty(apiKey)) { throw new ArgumentNullException("apiKey"); } if (string.IsNullOrEmpty(apiSecret)) { throw new ArgumentNullException("apiSecret"); } Authentication = new Authentication { ApiKey = apiKey, ApiSecret = apiSecret }; if (!string.IsNullOrEmpty(sessionKey)) { Authentication.Session = new Session { Key = sessionKey } } ; AuthApi = new AuthApi(); TrackApi = new TrackApi(); }
/// <summary> /// Submits a Track Love request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="RatingResponse"/></returns> /// <remarks>The <see cref="Track"/> passed in must be a "Corrected Track" as /// returned in <see cref="ScrobbleResponse"/> or <see cref="NowPlayingResponse"/> public bool Love(Track track) { var result = TrackApi.Love(track, Authentication); //result.Track = track; return(result); }
/// <summary> /// Submits a Track UnBan request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="RatingResponse"/></returns> /// <remarks>The <see cref="Track"/> passed in must be a "Corrected Track" as /// returned in <see cref="ScrobbleResponse"/> or <see cref="NowPlayingResponse"/> public bool UnBan(Track track) { var result = TrackApi.UnBan(track, Authentication); //result.Track = track; return(result); }
public ITrackApi LastFmTrackRepository() { if (this._trackApi == null) { this._trackApi = _lastfmClient.Track; } return(_trackApi); }
/// <summary> /// Initializes a new instance of the <see cref="LastFmApi"/> class. /// </summary> /// <param name="config">The config.</param> public LastFmApi(ILastFmConfig config) { Config = config; Track = new TrackApi(this); Tag = new TagApi(this); Album = new AlbumApi(this); Artist = new ArtistApi(this); }
/// <summary> /// Initializes a new instance of the <see cref="LastFmApi"/> class. /// </summary> /// <param name="config">The config.</param> public LastFmApi(ILastFmConfig config) { Config = config; Track = new TrackApi(this); Tag = new TagApi(this); Album = new AlbumApi(this); Artist = new ArtistApi(this); }
public ScrobblerService() { // _credentialHelper = credentialHelper; _auth = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret); _albumApi = new AlbumApi(_auth); _artistApi = new ArtistApi(_auth); _chartApi = new ChartApi(_auth); _trackApi = new TrackApi(_auth); // _userApi = new UserApi(_auth); // loadthis(); }
public ScrobblerService(ICredentialHelper credentialHelper) { _credentialHelper = credentialHelper; _auth = new LastAuth(ApiKeys.LastFmId, ApiKeys.LastFmSecret); _albumApi = new AlbumApi(_auth); _artistApi = new ArtistApi(_auth); _chartApi = new ChartApi(_auth); _trackApi = new TrackApi(_auth); _userApi = new UserApi(_auth); GetSessionTokenAsync(); }
public TrackResponse GetTrackInfo(Track track, bool isUserOnly) { string userName = null; if (isUserOnly) { userName = Authentication.Session.Username; } var result = TrackApi.GetInfo(track, Authentication, userName); return(result); }
public void Init() { var ak = "jmH6fA2QzDWfyPvkKslL741L"; var service_id = "105686"; var yingyan = new YingYanApi(ak, service_id); api = yingyan.Track; entity_name1 = "data1"; entity_name2 = "data2"; entity_name3 = "data3"; //var r1 = yingyan.entity.add(entity_name1).Result; //var r2 = yingyan.entity.delete(entity_name3).Result; var r3 = yingyan.Entity.Add(entity_name3).Result; }
/// <summary> /// 鹰眼轨迹服务接口 /// </summary> /// <param name="ak">用户的ak</param> /// <param name="serviceId">service的ID,service 的唯一标识</param> /// <param name="sk">sn签名的验证方式的 Security Key</param> public YingYanApi(string ak, string serviceId, string sk = null) { this.Ak = ak; ServiceId = serviceId; this.Sk = sk; _client = new HttpClient(); Entity = new EntityApi(this); Track = new TrackApi(this); Fence = new FenceApi(this); Analysis = new AnalysisApi(this); Export = new ExportApi(this); _client = new HttpClient { BaseAddress = new Uri(Url) }; _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public async void ScrobbleTrack(string artist, string album, string track) { var trackApi = new TrackApi(_auth); var scrobble = new Scrobble(artist, album, track, DateTimeOffset.Now); IScrobbler _scrobbler; _scrobbler = new Scrobbler(_auth); var response = await _scrobbler.ScrobbleAsync(scrobble); if (response.Success) { Debug.WriteLine("Scrobble success!"); } else { Debug.WriteLine("Scrobble failed!"); } }
public async Task UpdatesNowPlaying() { var trackPlayed = DateTime.UtcNow.AddMinutes(-1); var testScrobble = new Scrobble(ARTIST_NAME, ALBUM_NAME, TRACK_NAME, trackPlayed) { Duration = new TimeSpan(0, 0, 3, 49, 200), AlbumArtist = ARTIST_NAME }; var trackApi = new TrackApi(Auth); var response = await trackApi.UpdateNowPlayingAsync(testScrobble); Assert.IsTrue(response.Success); var userApi = new UserApi(Auth); var tracks = await userApi.GetRecentScrobbles(Auth.UserSession.Username, null, 1, 1); var expectedTrack = new LastTrack { Name = TRACK_NAME, ArtistName = ARTIST_NAME, AlbumName = ALBUM_NAME, Mbid = "1b9ee1d8-c5a7-44d9-813e-85beb0d59f1b", ArtistMbid = "b1570544-93ab-4b2b-8398-131735394202", Url = new Uri("http://www.last.fm/music/Crystal+Castles/_/Not+in+Love"), Images = new LastImageSet("http://userserve-ak.last.fm/serve/34s/61473043.png", "http://userserve-ak.last.fm/serve/64s/61473043.png", "http://userserve-ak.last.fm/serve/126/61473043.png", "http://userserve-ak.last.fm/serve/300x300/61473043.png"), IsNowPlaying = true }; var expectedJson = expectedTrack.TestSerialise(); var actualJson = tracks.Content.FirstOrDefault().TestSerialise(); Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); }
public async Task ScrobblesSingle() { var trackPlayed = DateTime.UtcNow.AddMinutes(-1); var testScrobble = new Scrobble("Hot Chip", "The Warning", "Over and Over", trackPlayed) { AlbumArtist = ARTIST_NAME, ChosenByUser = false }; var trackApi = new TrackApi(Auth); var response = await trackApi.ScrobbleAsync(testScrobble); Assert.IsTrue(response.Success); var userApi = new UserApi(Auth); var tracks = await userApi.GetRecentScrobbles(Auth.UserSession.Username, null, 0, 1); var expectedTrack = new LastTrack { Name = TRACK_NAME, ArtistName = ARTIST_NAME, AlbumName = ALBUM_NAME, Mbid = "c1af4137-92c5-43e4-ba4a-b43c7004a624", ArtistMbid = "d8915e13-d67a-4aa0-9c0b-1f126af951af", Url = new Uri("http://www.last.fm/music/Hot+Chip/_/Over+and+Over"), Images = new LastImageSet("http://userserve-ak.last.fm/serve/34s/50921593.png", "http://userserve-ak.last.fm/serve/64s/50921593.png", "http://userserve-ak.last.fm/serve/126/50921593.png", "http://userserve-ak.last.fm/serve/300x300/50921593.png"), TimePlayed = trackPlayed.RoundToNearestSecond() }; var expectedJson = expectedTrack.TestSerialise(); var actualJson = tracks.Content.FirstOrDefault().TestSerialise(); Assert.AreEqual(expectedJson, actualJson, expectedJson.DifferencesTo(actualJson)); }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { AlbumApi = new AlbumApi(this); AnmmarApi = new AnmmarApi(this); AnnouncementApi = new AnnouncementApi(this); AssessmentsMessages = new AssessmentsMessages(this); AttendanceApi = new AttendanceApi(this); AuthorizationApi = new AuthorizationApi(this); BadgeApi = new BadgeApi(this); BehaviourApi = new BehaviourApi(this); CalendarApi = new CalendarApi(this); CertificateApi = new CertificateApi(this); ClassApi = new ClassApi(this); ConfigurationMangerApi = new ConfigurationMangerApi(this); CopyApi = new CopyApi(this); CourseApi = new CourseApi(this); CourseCatalogueApi = new CourseCatalogueApi(this); CourseGroupAuthors = new CourseGroupAuthors(this); CourseImageApi = new CourseImageApi(this); CourseRequestsApi = new CourseRequestsApi(this); CoursesProgress = new CoursesProgress(this); DiscussionApi = new DiscussionApi(this); EduShareApi = new EduShareApi(this); EvaluationApi = new EvaluationApi(this); EventApi = new EventApi(this); FileApi = new FileApi(this); FormsTemplatesApi = new FormsTemplatesApi(this); GradeApi = new GradeApi(this); GradeBookApi = new GradeBookApi(this); HelpApi = new HelpApi(this); IenApi = new IenApi(this); InvitationApi = new InvitationApi(this); InviteApi = new InviteApi(this); LanguageApi = new LanguageApi(this); LearningObjectivesApi = new LearningObjectivesApi(this); LearningPathApi = new LearningPathApi(this); LTILMSConsumerApi = new LTILMSConsumerApi(this); MaterialApi = new MaterialApi(this); MaterialSeenByUser = new MaterialSeenByUser(this); MembersApi = new MembersApi(this); MentorApi = new MentorApi(this); NotificationsApi = new NotificationsApi(this); OfferApi = new OfferApi(this); Office365 = new Office365(this); OfficeAddInApi = new OfficeAddInApi(this); Onenote = new Onenote(this); OrganizationUserAPI = new OrganizationUserAPI(this); OutcomesApi = new OutcomesApi(this); PointsApi = new PointsApi(this); PollApi = new PollApi(this); PrerequisitesApi = new PrerequisitesApi(this); QtiInteroperability = new QtiInteroperability(this); QuestionBankApi = new QuestionBankApi(this); ReflectionApi = new ReflectionApi(this); RelatedCoursesApi = new RelatedCoursesApi(this); ReportApi = new ReportApi(this); RoleManagementApi = new RoleManagementApi(this); ScheduleVisitApi = new ScheduleVisitApi(this); SchoolTypeApi = new SchoolTypeApi(this); SessionApi = new SessionApi(this); SpaceApi = new SpaceApi(this); StudentApi = new StudentApi(this); SubjectApi = new SubjectApi(this); SystemAdministrationApi = new SystemAdministrationApi(this); SystemReportsApi = new SystemReportsApi(this); TagsApi = new TagsApi(this); Themes = new Themes(this); TimeTableApi = new TimeTableApi(this); ToolConsumerProfileApi = new ToolConsumerProfileApi(this); TourApi = new TourApi(this); TrackApi = new TrackApi(this); TrainingPlanApi = new TrainingPlanApi(this); UserApi = new UserApi(this); UserProfileApi = new UserProfileApi(this); UserProgressApi = new UserProgressApi(this); UserSettingsApi = new UserSettingsApi(this); WallApi = new WallApi(this); BaseUri = new System.Uri("https://xwinji.azurewebsites.net"); SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); }
/// <summary> /// Submits a Track Update Now Playing request to the Last.fm web service /// </summary> /// <param name="track">A <see cref="Track"/></param> /// <returns>A <see cref="NowPlayingResponse"/></returns> public bool NowPlaying(Track track) { return(TrackApi.UpdateNowPlaying(track, Authentication)); }