3
from flexget.entry import Entry
4
from flexget.plugin import register_plugin, internet
5
from flexget.utils.cached_input import cached
6
from flexget.utils.tools import urlopener
8
log = logging.getLogger('csv')
11
class InputCSV(object):
13
Adds support for CSV format. Configuration may seem a bit complex,
14
but this has advantage of being universal solution regardless of CSV
15
and internal entry fields.
27
url: http://www.dattebayo.com/t/dump
29
title: 3 # title is in 3th field
30
url: 1 # download url is in 1st field
32
Fields title and url are mandatory. First field is 1.
33
List of other common (optional) fields can be found from wiki.
37
from flexget import validator
38
config = validator.factory('dict')
39
config.accept('url', key='url', required=True)
40
values = config.accept('dict', key='values', required=True)
41
values.accept_any_key('integer')
46
def on_feed_input(self, feed, config):
48
page = urlopener(config['url'], log)
49
for row in csv.reader(page):
53
for name, index in config.get('values', {}).items():
55
entry[name] = row[index-1]
57
raise Exception('Field `%s` index is out of range' % name)
61
register_plugin(InputCSV, 'csv', api_ver=2)