1

Fix for NNM Club domain change

This commit is contained in:
Vladimir Kozlov 2016-04-04 13:13:09 +04:00 committed by Vladimir Hodakov
parent d391c3ddea
commit 1871418e8b

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python2.7
# *-* encoding: utf-8 *-*
# For NNM-Club Uploaders
# Copyright (c) 2012-2014 Valdos Sine <iam@toofat.ru>
# Copyright (c) 2012-2016 Vladimir Kozlov <iam@toofat.ru>
#
# Usage:
#
@ -13,10 +14,10 @@ import lib.config as uconfig
import lib.messages as umessages
import dateutil
from dateutil.parser import *
version = 0.80
version = 0.92
unixtime = int(time.time())
cookie = tempfile.mkstemp()
curdir = os.getcwd()
curdir = uconfig.workdir
log_file = "/%i-massdl.log" % unixtime
domain = uconfig.domain
@ -170,7 +171,8 @@ def download():
cnsl_message("found_topics", str(len(topics)))
# Aaaand... the first real actions is here
torrentsdir = "%s/%s" % (curdir, sys.argv[1])
os.mkdir(torrentsdir)
if not os.path.exists(torrentsdir):
os.makedirs(torrentsdir)
get_torrent(topics, torrentsdir, forumname)
def parse_topic(topic, forumname, topics, torrents_count, torrentsdir):
@ -186,6 +188,11 @@ def parse_topic(topic, forumname, topics, torrents_count, torrentsdir):
for line in topicpage.splitlines():
if 'проверено модератором' in line:
tdate_raw = line
try:
tdate_raw
except NameError:
cnsl_message("skip_non_approved", str(torrents_count), str(len(topics)), topicname, (domain + "/" + topic))
return 340
# fix for russian months names (dateutil doesn't parse it, damnnt)
tdate_raw = tdate_raw.replace('Янв', '01').replace('Фев', '02').replace('Мар', '03').replace('Апр', '04').replace('Май', '05').replace('Июн', '06').replace('Июл', '07').replace('Авг', '08').replace('Сен', '09').replace('Окт', '10').replace('Ноя', '11').replace('Дек', '12')
topicdate = dateutil.parser.parse(tdate_raw.split('>')[1].split('<')[0].split(' ',3)[3]).strftime("%Y-%m-%d")
@ -197,13 +204,11 @@ def parse_topic(topic, forumname, topics, torrents_count, torrentsdir):
downlink = dl_raw.split('"')[1]
cnsl_message("downloading_torrent", str(torrents_count), str(len(topics)), topicname, (domain + "/" + topic), topicdate)
os.chdir(torrentsdir)
if not os.path.exists("./%s" % topicdate):
os.makedirs("./%s" % topicdate)
os.chdir("./%s" % topicdate)
download_torrent(downlink)
download_torrent(downlink, topicdate)
def download_torrent(downlink):
os.system('curl -b ' + cookie[1] + ' -O -J -L "' + domain + '/forum/' + downlink + '" 2>>' + curdir + log_file)
def download_torrent(downlink, topicdate):
basefilename = commands.getoutput('curl -sI -b ' + cookie[1] + ' -J -L "' + domain + '/forum/' + downlink + '"' + "| grep -o -E 'filename=.*$' | tr -d '\r\n' | sed -e 's/filename=//' | sed 's/\"//g'")
os.system('curl -b %s -L "%s/forum/%s" -o "%s %s" 2>> %s%s' % (cookie[1], domain, downlink, topicdate, basefilename, curdir, log_file))
def get_torrent(topics, torrentsdir, forumname):
cnsl_message("download_started")