diff --git a/TotalDL/timesearch_dl.py b/TotalDL/timesearch_dl.py index cc6f2b6..65c533d 100644 --- a/TotalDL/timesearch_dl.py +++ b/TotalDL/timesearch_dl.py @@ -7,6 +7,7 @@ cur = sql.cursor() cur2 = sql.cursor() cur.execute('CREATE TABLE IF NOT EXISTS totaldl_urls(url TEXT)') +cur.execute('CREATE INDEX IF NOT EXISTS urlindex ON totaldl_urls(url)') sql.commit() cur.execute('SELECT * FROM posts WHERE self=0 AND url IS NOT NULL') while True: diff --git a/TotalDL/totaldl.py b/TotalDL/totaldl.py index 23181de..1f90144 100644 --- a/TotalDL/totaldl.py +++ b/TotalDL/totaldl.py @@ -2,6 +2,7 @@ import json import requests import os import time +import sys HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36'} @@ -140,7 +141,9 @@ def handle_imgur(url, albumid='', customname=None): if len(images) > 1: for imagei in range(len(images)): image = images[imagei] - handle_imgur(image, albumid=name, customname=str(imagei)) + iname = image.split('/')[-1] + iname = iname.split('.')[0] + handle_imgur(image, albumid=name, customname='%d_%s' % (imagei, iname)) else: handle_imgur(images[0], customname=name) @@ -249,6 +252,27 @@ def handle_youtube(url, customname=None): def handle_twitter(url, customname=None): pagedata = request_get(url) pagedata = pagedata.text + + idnumber = url.split('status/')[1].split('/')[0] + if customname: + name = customname + else: + name = idnumber + customname = idnumber + tweetpath = '%s.html' % (DOWNLOAD_DIRECTORY + name) + if not os.path.exists(tweetpath): + psplit = '