From 1871418e8bc340c9a1a27e72a7a039cad361aac5 Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Mon, 4 Apr 2016 13:13:09 +0400 Subject: [PATCH] Fix for NNM Club domain change --- massdl.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/massdl.py b/massdl.py index 2c22b3b..ea4aef6 100755 --- a/massdl.py +++ b/massdl.py @@ -1,11 +1,12 @@ +#!/usr/bin/env python2.7 # *-* encoding: utf-8 *-* # For NNM-Club Uploaders -# Copyright (c) 2012-2014 Valdos Sine +# Copyright (c) 2012-2016 Vladimir Kozlov # # Usage: # # python2 ./massdl.py [forum_number] -# +# # For getting help, execute "python2 ./massdl.py" without params import time, tempfile, os, sys, commands @@ -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 @@ -149,7 +150,7 @@ def iteratorium(links_array, offset): def download(): """ And now that's main part of the script. We need to: - + * iterate over each other page of the forum * collect all forum topics * collect all torrents from topics @@ -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")