1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

Save magnets in separated files

This commit is contained in:
Rnhmjoj 2015-03-26 23:42:03 +01:00
parent f984a474ce
commit 9343dbba34
2 changed files with 14 additions and 16 deletions

View File

@ -29,7 +29,7 @@ These are the default options:
```INI
[Save]
directory = ~/downloads/pirate-get ; directory where to save files
magnets = false ; save every selected torrent as a magnet in a single file
magnets = false ; save each selected magnet link in a .magnet file
torrents = false ; save each selected torrent in a .torrent file
[LocalDB]

View File

@ -19,7 +19,6 @@
import os
import sys
import random
import re
import string
import gzip
@ -326,10 +325,6 @@ def get_torrent(info_hash):
return torrent.read()
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
# enhanced print output with column titles
def print_search_results(mags, sizes, uploaded):
columns = int(os.popen('stty size', 'r').read().split()[1]) - 52
@ -432,13 +427,16 @@ def save_torrents(chosen_links, mags, folder):
def save_magnets(chosen_links, mags, folder):
filename = os.path.join(folder, id_generator() + '.magnets')
print('Saving magnets to', filename)
with open(filename, 'w') as f:
for link in chosen_links:
url = mags[int(link)][0]
f.write(url + '\n')
magnet = mags[int(link)][0]
name = re.search(r'dn=([^\&]*)', magnet)
torrent_name = parse.unquote(name.group(1)).replace('+', ' ')
info_hash = int(re.search(r'btih:([a-f0-9]{40})', magnet).group(1), 16)
file = os.path.join(folder, torrent_name + '.magnet')
print('Saved {:X} in {}'.format(info_hash, file))
with open(file, 'w') as f:
f.write(magnet + '\n')
def main():
@ -483,7 +481,7 @@ def main():
help='open magnets with transmission-remote')
parser.add_argument('-M', '--save-magnets',
action='store_true', default=False,
help='save magnets links into a file')
help='save magnets links as files')
parser.add_argument('-T', '--save-torrents',
action='store_true', default=False,
help='save torrent files')
@ -598,7 +596,7 @@ def main():
if code == 'h':
print('Options:',
'<links>: Download selected torrents',
'[m<links>]: Save magnets in a file',
'[m<links>]: Save magnets as files',
'[t<links>]: Save .torrent files',
'[d<links>]: Get descriptions',
'[f<links>]: Get files',