-
Notifications
You must be signed in to change notification settings - Fork 1
/
MusicSource.cs
85 lines (68 loc) · 1.7 KB
/
MusicSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using Banshee.Sources;
using Banshee.Collection;
using Banshee.ServiceStack;
using Hyena.Collections;
namespace Banshee.GoogleMusic
{
public class MusicSource : PrimarySource, IDisposable
{
const int sort_order = 190;
private Google.Music.Api api;
private MusicDownloadWrapper downloadWrapper;
public MusicSource () : base("Google Music", "Google Music", "google-music", sort_order)
{
api = new Google.Music.Api();
downloadWrapper = new MusicDownloadWrapper(api);
downloadWrapper.Start();
Properties.Set<Gdk.Pixbuf>("Icon.Pixbuf_16", Gdk.Pixbuf.LoadFromResource("google-music-favicon"));
AfterInitialized();
var win = new Gtk.Window("Google Music Login");
var loginWidget = new LoginWidget();
loginWidget.UserLoggedIn += (cookies) => {
api.SetCookies(cookies);
AsyncUserJob.Create(() => {
Refetch();
}, "Fetching playlist");
win.Destroy();
};
win.Add(loginWidget);
win.ShowAll();
}
~MusicSource()
{
Dispose ();
}
public override void Dispose ()
{
downloadWrapper.Stop();
base.Dispose();
}
public override bool CanDeleteTracks {
get { return false; }
}
public override bool CanAddTracks {
get { return false; }
}
private void Refetch ()
{
PurgeTracks();
OnTracksRemoved();
int counter = 0;
foreach (var track in api.GetTracks()) {
AddTrack(track);
if (counter++ > 100) {
OnTracksAdded(); // update GUI
counter = 0;
}
}
OnTracksAdded();
}
private void AddTrack(Google.Music.Track track)
{
var track_info = new MusicTrack(track, downloadWrapper.formTrackUrl(track.id), this);
track_info.Save (false);
}
}
}