else/TotalDL/timesearch_dl.py

47 lines
1.2 KiB
Python
Raw Normal View History

2015-05-16 10:31:37 +00:00
import traceback
2015-05-15 06:02:21 +00:00
import sqlite3
import totaldl
2015-06-03 03:30:35 +00:00
import praw
r = praw.Reddit('')
r.login('', '')
2015-05-15 06:02:21 +00:00
sql = sqlite3.connect('!!testdata.db')
cur = sql.cursor()
2015-05-16 10:31:00 +00:00
cur2 = sql.cursor()
2015-05-15 06:02:21 +00:00
2015-05-16 10:31:00 +00:00
cur.execute('CREATE TABLE IF NOT EXISTS totaldl_urls(url TEXT)')
2015-05-20 03:17:00 +00:00
cur.execute('CREATE INDEX IF NOT EXISTS urlindex ON totaldl_urls(url)')
2015-05-16 10:31:00 +00:00
sql.commit()
2015-05-15 06:02:21 +00:00
cur.execute('SELECT * FROM posts WHERE self=0 AND url IS NOT NULL')
while True:
item = cur.fetchone()
if item is None:
break
2015-05-16 10:31:00 +00:00
url = item[7]
if 'youtube.com' in url and '?v=' not in url:
continue
2015-05-16 10:31:00 +00:00
cur2.execute('SELECT * FROM totaldl_urls WHERE url=?', [url])
if cur2.fetchone():
continue
2015-05-15 21:46:32 +00:00
title = item[6]
for character in '\\/?:*"><|.':
title = title.replace(character, '')
if len(title) > 35:
title = title[:34] + '-'
2015-05-16 10:31:37 +00:00
try:
2015-06-03 03:30:35 +00:00
filepath = totaldl.handle_master(url, customname=title)
2015-06-03 20:48:48 +00:00
if filepath is None:
continue
2015-06-03 03:31:02 +00:00
filepath = filepath.replace('\\', '/')
2015-06-03 03:30:35 +00:00
filepath = filepath.split('/')[-1]
if '.mp4' in filepath:
filepath = 'http://syriancivilwar.pw/Videos/' + filepath
submission = r.get_info(thing_id=item[1])
2015-06-03 03:41:49 +00:00
submission.add_comment('[Mirror](%s)' % filepath)
2015-06-03 03:30:35 +00:00
print(filepath)
2015-05-16 10:31:37 +00:00
except:
traceback.print_exc()
2015-05-16 10:31:00 +00:00
cur2.execute('INSERT INTO totaldl_urls VALUES(?)', [url])
sql.commit()