2
from flexget.feed import Entry
3
from flexget.plugin import *
4
from flexget.utils.cached_input import cached
5
from flexget.utils.tools import urlopener
7
log = logging.getLogger('csv')
10
class InputCSV(object):
12
Adds support for CSV format. Configuration may seem a bit complex,
13
but this has advantage of being universal solution regardless of CSV
14
and internal entry fields.
26
url: http://www.dattebayo.com/t/dump
28
title: 3 # title is in 3th field
29
url: 1 # download url is in 1st field
31
Fields title and url are mandatory. First field is 1.
32
List of other common (optional) fields can be found from wiki.
36
from flexget import validator
37
config = validator.factory('dict')
38
config.accept('url', key='url', required=True)
39
values = config.accept('dict', key='values', required=True)
40
values.accept_any_key('integer')
45
def on_feed_input(self, feed):
46
url = feed.config['csv'].get('url', None)
48
raise Exception('CSV in %s is missing url' % feed.name)
49
page = urlopener(url, log)
50
for line in page.readlines():
51
data = line.split(",")
53
for name, index in feed.config['csv'].get('values', {}).items():
55
entry[name] = data[index-1]
57
raise Exception('Field %s index is out of range' % name)
58
feed.entries.append(entry)
60
register_plugin(InputCSV, 'csv')