mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
[search engine] re-factoring of code
This commit is contained in:
parent
d6d0f422f5
commit
2fc1487603
6 changed files with 761 additions and 764 deletions
|
@ -25,7 +25,7 @@
|
||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#VERSION: 1.10
|
#VERSION: 1.20
|
||||||
|
|
||||||
# Author:
|
# Author:
|
||||||
# Christophe DUMEZ (chris@qbittorrent.org)
|
# Christophe DUMEZ (chris@qbittorrent.org)
|
||||||
|
@ -43,8 +43,8 @@ for engine in engines:
|
||||||
if len(e.strip()) == 0: continue
|
if len(e.strip()) == 0: continue
|
||||||
if e.startswith('_'): continue
|
if e.startswith('_'): continue
|
||||||
try:
|
try:
|
||||||
exec "from engines.%s import %s"%(e,e)
|
exec("from engines.%s import %s"%(e,e))
|
||||||
exec "engine_url = %s.url"%e
|
exec("engine_url = %s.url"%e)
|
||||||
supported_engines[engine_url] = e
|
supported_engines[engine_url] = e
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -54,11 +54,11 @@ if __name__ == '__main__':
|
||||||
raise SystemExit('./nova2dl.py engine_url download_parameter')
|
raise SystemExit('./nova2dl.py engine_url download_parameter')
|
||||||
engine_url = sys.argv[1].strip()
|
engine_url = sys.argv[1].strip()
|
||||||
download_param = sys.argv[2].strip()
|
download_param = sys.argv[2].strip()
|
||||||
if engine_url not in supported_engines.keys():
|
if engine_url not in list(supported_engines.keys()):
|
||||||
raise SystemExit('./nova2dl.py: this engine_url was not recognized')
|
raise SystemExit('./nova2dl.py: this engine_url was not recognized')
|
||||||
exec "engine = %s()"%supported_engines[engine_url]
|
exec("engine = %s()"%supported_engines[engine_url])
|
||||||
if hasattr(engine, 'download_torrent'):
|
if hasattr(engine, 'download_torrent'):
|
||||||
engine.download_torrent(download_param)
|
engine.download_torrent(download_param)
|
||||||
else:
|
else:
|
||||||
print download_file(download_param)
|
print(download_file(download_param))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
|
@ -25,20 +25,19 @@
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import sys, codecs
|
import sys, codecs
|
||||||
|
from io import open
|
||||||
|
|
||||||
# Force UTF-8 printing
|
# Force UTF-8 printing
|
||||||
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
|
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
|
||||||
|
|
||||||
def prettyPrinter(dictionary):
|
def prettyPrinter(dictionary):
|
||||||
# Convert everything to unicode for safe printing
|
|
||||||
for key,value in dictionary.items():
|
|
||||||
if isinstance(dictionary[key], str):
|
|
||||||
dictionary[key] = unicode(dictionary[key], 'utf-8')
|
|
||||||
dictionary['size'] = anySizeToBytes(dictionary['size'])
|
dictionary['size'] = anySizeToBytes(dictionary['size'])
|
||||||
if dictionary.has_key('desc_link'):
|
outtext = "|".join((dictionary["link"], dictionary["name"].replace("|", " "), str(dictionary["size"]), str(dictionary["seeds"]), str(dictionary["leech"]), dictionary["engine_url"]))
|
||||||
print u"%s|%s|%s|%s|%s|%s|%s"%(dictionary['link'],dictionary['name'].replace('|',' '),dictionary['size'],dictionary['seeds'],dictionary['leech'],dictionary['engine_url'],dictionary['desc_link'])
|
if 'desc_link' in dictionary:
|
||||||
else:
|
outtext = "|".join((outtext, dictionary["desc_link"]))
|
||||||
print u"%s|%s|%s|%s|%s|%s"%(dictionary['link'],dictionary['name'].replace('|',' '),dictionary['size'],dictionary['seeds'],dictionary['leech'],dictionary['engine_url'])
|
|
||||||
|
with open(1, 'w', encoding='utf-8', closefd=False) as utf8_stdout:
|
||||||
|
utf8_stdout.write("".join((outtext, "\n")))
|
||||||
|
|
||||||
def anySizeToBytes(size_string):
|
def anySizeToBytes(size_string):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#VERSION: 1.10
|
#VERSION: 1.20
|
||||||
|
|
||||||
# Author:
|
# Author:
|
||||||
# Christophe DUMEZ (chris@qbittorrent.org)
|
# Christophe DUMEZ (chris@qbittorrent.org)
|
||||||
|
|
|
@ -26,12 +26,10 @@
|
||||||
|
|
||||||
|
|
||||||
def prettyPrinter(dictionary):
|
def prettyPrinter(dictionary):
|
||||||
outtext = ''
|
|
||||||
dictionary['size'] = anySizeToBytes(dictionary['size'])
|
dictionary['size'] = anySizeToBytes(dictionary['size'])
|
||||||
|
outtext = "|".join((dictionary["link"], dictionary["name"].replace("|", " "), str(dictionary["size"]), str(dictionary["seeds"]), str(dictionary["leech"]), dictionary["engine_url"]))
|
||||||
if 'desc_link' in dictionary:
|
if 'desc_link' in dictionary:
|
||||||
outtext = '%s|%s|%s|%s|%s|%s|%s'%(dictionary['link'],dictionary['name'].replace('|',' '),dictionary['size'],dictionary['seeds'],dictionary['leech'],dictionary['engine_url'],dictionary['desc_link'])
|
outtext = "|".join((outtext, dictionary["desc_link"]))
|
||||||
else:
|
|
||||||
outtext = '%s|%s|%s|%s|%s|%s'%(dictionary['link'],dictionary['name'].replace('|',' '),dictionary['size'],dictionary['seeds'],dictionary['leech'],dictionary['engine_url'])
|
|
||||||
|
|
||||||
# fd 1 is stdout
|
# fd 1 is stdout
|
||||||
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
|
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue