pcremote-client-n8x0 -> client sources
[remotepc] / pcremote-server-desktop / utils / .svn / text-base / plistparser.py.svn-base
1 # -*- coding: utf-8 -*-
2
3 #  ****************************************************************************
4 #  Copyright (c) 2008 INdT/Fucapi.
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU Lesser General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public License
16 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 #  ============================================================================
19 #  Project Name : PC Remote
20 #  Author       : Jonatas Isvi
21 #  Email        : jonatas.nona@gmail.com
22 #  Reviewer     :
23 #  Email        :
24 #  Version      : 1.0
25 #  Package      : utils
26 #  Description  : plisparser
27 #  ============================================================================
28
29 from xml.etree import cElementTree as ElementTree
30
31 # get the file
32 def _request(url):
33     xml = url
34     return parse_playlist_file(xml)
35
36 # parser the file
37 def parse_playlist_file(xml):
38     tree = ElementTree.parse(xml)
39     listsongs = []
40     dictsongs = {}
41     count = duration = filesize = 0
42     title = artist = path = ''
43
44     for child in tree.getiterator():
45         if child.tag == 'Title':
46             title = child.text
47         elif child.tag == 'Artist':
48             artist = child.text
49         elif child.tag == 'Length':
50             duration = child.text
51         elif child.tag == 'Filesize':
52             filesize = child.text
53             count = count + 1
54             dictsongs = {'track' : count, 
55                          'title' : title, 
56                          'artist' : artist, 
57                          'duration' : duration, 
58                          'filesize' : filesize, 
59                          'path' : None,
60                          'extension' : None,
61                         }
62             listsongs.append(dictsongs)
63
64     return listsongs
65
66
67
68                         
69
70
71
72