-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.py
39 lines (30 loc) · 1.17 KB
/
import.py
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
#!/usr/bin/python
import sys
import getpass
import urllib2
from xml.etree import ElementTree
if 3 != len(sys.argv):
sys.exit('Please provide TuneIn username and password.')
path = '/home/' + getpass.getuser() + '/.local/share/rhythmbox/rhythmdb.xml'
url = 'http://opml.radiotime.com/Browse.ashx?c=presets&partnerId=k2YHnXyS&username=' + sys.argv[1] + '&password=' + sys.argv[2]
xml = urllib2.urlopen(url).read()
tree = ElementTree.fromstring(xml)
rhythmdb = ElementTree.parse(path)
for child in tree.find('body').findall('outline'):
entry = ElementTree.Element('entry', {'type': 'iradio'})
if 'unavailable' == child.get('key'):
continue
title = ElementTree.Element('title')
if -1 == child.get('text').find('|'):
title.text = child.get('text')
else:
title.text = child.get('text').split('|')[1].split('(')[0].strip()
entry.append(title)
genre = ElementTree.Element('genre')
genre.text = 'TuneIn'
entry.append(genre)
location = ElementTree.Element('location')
location.text = urllib2.urlopen(child.get('URL')).read().splitlines()[0]
entry.append(location)
rhythmdb.getroot().append(entry)
rhythmdb.write(path)