source: titan/mediathek/localhoster/lib/helpers.py @ 38962

Last change on this file since 38962 was 38962, checked in by obi, 7 years ago

localhoster add needed libs

File size: 2.0 KB
Line 
1"""
2    URLResolver Addon for Kodi
3    Copyright (C) 2016 t0mm0, tknorris
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU 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 General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17"""
18import re
19import xbmcgui
20from urlresolver import common
21from urlresolver.resolver import ResolverError
22
23def get_hidden(html, form_id=None):
24    hidden = {}
25    if form_id:
26        pattern = '''<form [^>]*id\s*=\s*['"]?%s['"]?[^>]*>(.*?)</form>'''
27    else:
28        pattern = '''<form[^>]*>(.*?)</form>'''
29       
30    for form in re.finditer(pattern, html, re.DOTALL | re.I):
31        for field in re.finditer('''<input [^>]*type=['"]?hidden['"]?[^>]*>''', form.group(1)):
32            match = re.search('''name\s*=\s*['"]([^'"]+)''', field.group(0))
33            match1 = re.search('''value\s*=\s*['"]([^'"]*)''', field.group(0))
34            if match and match1:
35                hidden[match.group(1)] = match1.group(1)
36           
37    common.log_utils.log_debug('Hidden fields are: %s' % (hidden))
38    return hidden
39
40def pick_source(sources, auto_pick=False):
41    if len(sources) == 1:
42        return sources[0][1]
43    elif len(sources) > 1:
44        if auto_pick:
45            return sources[0][1]
46        else:
47            result = xbmcgui.Dialog().select('Choose the link', [source[0] if source[0] else 'Uknown' for source in sources])
48            if result == -1:
49                raise ResolverError('No link selected')
50            else:
51                return sources[result][1]
52    else:
53        raise ResolverError('No Video Link Found')
Note: See TracBrowser for help on using the repository browser.