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:
parent
f984a474ce
commit
9343dbba34
@ -29,7 +29,7 @@ These are the default options:
|
|||||||
```INI
|
```INI
|
||||||
[Save]
|
[Save]
|
||||||
directory = ~/downloads/pirate-get ; directory where to save files
|
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
|
torrents = false ; save each selected torrent in a .torrent file
|
||||||
|
|
||||||
[LocalDB]
|
[LocalDB]
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import random
|
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
import gzip
|
import gzip
|
||||||
@ -326,10 +325,6 @@ def get_torrent(info_hash):
|
|||||||
return torrent.read()
|
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
|
# enhanced print output with column titles
|
||||||
def print_search_results(mags, sizes, uploaded):
|
def print_search_results(mags, sizes, uploaded):
|
||||||
columns = int(os.popen('stty size', 'r').read().split()[1]) - 52
|
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):
|
def save_magnets(chosen_links, mags, folder):
|
||||||
filename = os.path.join(folder, id_generator() + '.magnets')
|
for link in chosen_links:
|
||||||
print('Saving magnets to', filename)
|
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')
|
||||||
|
|
||||||
with open(filename, 'w') as f:
|
print('Saved {:X} in {}'.format(info_hash, file))
|
||||||
for link in chosen_links:
|
with open(file, 'w') as f:
|
||||||
url = mags[int(link)][0]
|
f.write(magnet + '\n')
|
||||||
f.write(url + '\n')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -483,7 +481,7 @@ def main():
|
|||||||
help='open magnets with transmission-remote')
|
help='open magnets with transmission-remote')
|
||||||
parser.add_argument('-M', '--save-magnets',
|
parser.add_argument('-M', '--save-magnets',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='save magnets links into a file')
|
help='save magnets links as files')
|
||||||
parser.add_argument('-T', '--save-torrents',
|
parser.add_argument('-T', '--save-torrents',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='save torrent files')
|
help='save torrent files')
|
||||||
@ -598,7 +596,7 @@ def main():
|
|||||||
if code == 'h':
|
if code == 'h':
|
||||||
print('Options:',
|
print('Options:',
|
||||||
'<links>: Download selected torrents',
|
'<links>: Download selected torrents',
|
||||||
'[m<links>]: Save magnets in a file',
|
'[m<links>]: Save magnets as files',
|
||||||
'[t<links>]: Save .torrent files',
|
'[t<links>]: Save .torrent files',
|
||||||
'[d<links>]: Get descriptions',
|
'[d<links>]: Get descriptions',
|
||||||
'[f<links>]: Get files',
|
'[f<links>]: Get files',
|
||||||
|
Loading…
Reference in New Issue
Block a user