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
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#VERSION: 1.10
|
||||
#VERSION: 1.20
|
||||
|
||||
# Author:
|
||||
# Christophe DUMEZ (chris@qbittorrent.org)
|
||||
|
@ -43,8 +43,8 @@ for engine in engines:
|
|||
if len(e.strip()) == 0: continue
|
||||
if e.startswith('_'): continue
|
||||
try:
|
||||
exec "from engines.%s import %s"%(e,e)
|
||||
exec "engine_url = %s.url"%e
|
||||
exec("from engines.%s import %s"%(e,e))
|
||||
exec("engine_url = %s.url"%e)
|
||||
supported_engines[engine_url] = e
|
||||
except:
|
||||
pass
|
||||
|
@ -54,11 +54,11 @@ if __name__ == '__main__':
|
|||
raise SystemExit('./nova2dl.py engine_url download_parameter')
|
||||
engine_url = sys.argv[1].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')
|
||||
exec "engine = %s()"%supported_engines[engine_url]
|
||||
exec("engine = %s()"%supported_engines[engine_url])
|
||||
if hasattr(engine, 'download_torrent'):
|
||||
engine.download_torrent(download_param)
|
||||
else:
|
||||
print download_file(download_param)
|
||||
print(download_file(download_param))
|
||||
sys.exit(0)
|
|
@ -25,20 +25,19 @@
|
|||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import sys, codecs
|
||||
from io import open
|
||||
|
||||
# Force UTF-8 printing
|
||||
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
|
||||
|
||||
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'])
|
||||
if dictionary.has_key('desc_link'):
|
||||
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'])
|
||||
else:
|
||||
print u"%s|%s|%s|%s|%s|%s"%(dictionary['link'],dictionary['name'].replace('|',' '),dictionary['size'],dictionary['seeds'],dictionary['leech'],dictionary['engine_url'])
|
||||
outtext = "|".join((dictionary["link"], dictionary["name"].replace("|", " "), str(dictionary["size"]), str(dictionary["seeds"]), str(dictionary["leech"]), dictionary["engine_url"]))
|
||||
if 'desc_link' in dictionary:
|
||||
outtext = "|".join((outtext, dictionary["desc_link"]))
|
||||
|
||||
with open(1, 'w', encoding='utf-8', closefd=False) as utf8_stdout:
|
||||
utf8_stdout.write("".join((outtext, "\n")))
|
||||
|
||||
def anySizeToBytes(size_string):
|
||||
"""
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#VERSION: 1.10
|
||||
#VERSION: 1.20
|
||||
|
||||
# Author:
|
||||
# Christophe DUMEZ (chris@qbittorrent.org)
|
||||
|
|
|
@ -26,12 +26,10 @@
|
|||
|
||||
|
||||
def prettyPrinter(dictionary):
|
||||
outtext = ''
|
||||
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:
|
||||
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'])
|
||||
else:
|
||||
outtext = '%s|%s|%s|%s|%s|%s'%(dictionary['link'],dictionary['name'].replace('|',' '),dictionary['size'],dictionary['seeds'],dictionary['leech'],dictionary['engine_url'])
|
||||
outtext = "|".join((outtext, dictionary["desc_link"]))
|
||||
|
||||
# fd 1 is stdout
|
||||
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue