My favorites | Sign in
Project Logo
                
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Zuse - A Zune Last.fm plugin
* Copyright (C) 2007-2008 Zachary Howe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.IO;
using System.Net;

using Zuse.Scrobbler;
using Zuse.Utilities;

namespace Zuse.Core
{
class ZuneCatcher
{
private const string TemporaryZuneXML = "tmp_zuneprofile.xml";

private string username;
private string url;

public ZuneCatcher(string username)
{
this.username = username;
this.url = "http://origin-zcards.zune.net/zcard/usercardservice.ashx/src/external/?zunetag=" + username;
}

public SongCollection FetchSongs()
{
return this.FetchSongs(false);
}

public SongCollection FetchSongs(bool test)
{
DateTime now = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.UtcNow);
SongCollection songs = new SongCollection();

try
{
XmlReader reader = XmlReader.Create(this.FetchProfile(string.Format("http://origin-zcards.zune.net/zcard/usercardservice.ashx/src/external/?zunetag={0:s}&MMplayerType=PlugIn", this.username)));
XmlDocument doc = new XmlDocument();
doc.Load(reader);

XmlElement el = null;

foreach (XmlElement x in doc.GetElementsByTagName("playlist"))
{
if (x.GetAttribute("type") == "recent_spins")
{
el = x;
break;
}
}

foreach (XmlElement x in el.GetElementsByTagName("track"))
{
Song song = new Song();

XmlNodeList els = x.GetElementsByTagName("label");
song.Title = els[0].InnerText;
song.Album = els[1].InnerText;
song.Artist = els[2].InnerText;

if (!test)
{
song.FetchSongLength();

TimeSpan songLength = new TimeSpan(0, 0, song.Length);

song.ExtraInfo.TimePlayed = now;
now -= songLength;
}

songs.Add(song);
}

reader.Close();
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
return null;
}

return songs;
}

public Stream FetchProfile(string url)
{
WebRequest webRequest = WebRequest.Create(url);
webRequest.Method = "GET";
webRequest.ConnectionGroupName = "keep-alive";

webRequest.Headers.Add("Host", "social.zune.net");
webRequest.Headers.Add("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
webRequest.Headers.Add("Cache-Control", "max-age=0");
webRequest.Headers.Add("Keep-Alive", "300");
webRequest.Headers.Add("Referer", "http://social.zune.net/member/" + this.username);
webRequest.Headers.Add("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
webRequest.Headers.Add("Cookie", "WT_FPC=id=24.209.95.160-584720416.29921779:lv=1207177958782:ss=1207174281128");
webRequest.Headers.Add("If-Modified-Since", "Fri, 08 Feb 2008 01:00:52 GMT");
webRequest.Headers.Add("If-None-Match", "\"d4d51cdee69c81:19a8\"");
webRequest.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest.Headers.Add("Accept-Encoding", "gzip,deflate");
webRequest.Headers.Add("Accept-Language", "en-us,en;q=0.5");

try
{
WebResponse webResponse = webRequest.GetResponse();
return webResponse.GetResponseStream();
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
return null;
}
}
}
}
Show details Hide details

Change log

r33 by zachowe on Apr 02, 2008   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r32 by zachowe on Apr 01, 2008   Diff
Added items remotely

C:\Users\Zachary Howe\Documents\Visual
Studio
2008\Projects\Zuse\Zuse.Scrobbler
...
All revisions of this file

File info

Size: 5033 bytes, 136 lines
Hosted by Google Code