1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-24 12:14:20 +01:00

Merge pull request #120 from matteosandrin/copymagnet

Copying torrent magnets from the pirate-get CLI
This commit is contained in:
Viktor Stanchev 2018-06-16 10:18:05 -07:00 committed by GitHub
commit 2cb5957a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -84,8 +84,8 @@ def parse_cmd(cmd, url):
def parse_torrent_command(l): def parse_torrent_command(l):
# Very permissive handling # Very permissive handling
# Check for any occurances or d, f, p, t, m, or q # Check for any occurances of c, d, f, p, t, m, or q
cmd_code_match = re.search(r'([hdfpmtq])', l, cmd_code_match = re.search(r'([hdfpmtqc])', l,
flags=re.IGNORECASE) flags=re.IGNORECASE)
if cmd_code_match: if cmd_code_match:
code = cmd_code_match.group(0).lower() code = cmd_code_match.group(0).lower()
@ -382,6 +382,7 @@ def pirate_main(args):
printer.print('Options:', printer.print('Options:',
'<links>: Download selected torrents', '<links>: Download selected torrents',
'[m<links>]: Save magnets as files', '[m<links>]: Save magnets as files',
'[c<links>]: Copy magnets to clipboard',
'[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',
@ -399,6 +400,8 @@ def pirate_main(args):
elif code == 'm': elif code == 'm':
pirate.torrent.save_magnets(printer, choices, results, pirate.torrent.save_magnets(printer, choices, results,
args.save_directory) args.save_directory)
elif code == 'c':
pirate.torrent.copy_magnets(printer, choices, results)
elif code == 't': elif code == 't':
pirate.torrent.save_torrents(printer, choices, results, pirate.torrent.save_torrents(printer, choices, results,
args.save_directory) args.save_directory)

View File

@ -1,6 +1,7 @@
import re import re
import sys import sys
import gzip import gzip
import pyperclip
import urllib.request as request import urllib.request as request
import urllib.parse as parse import urllib.parse as parse
import urllib.error import urllib.error
@ -197,3 +198,13 @@ def save_magnets(printer, chosen_links, results, folder):
printer.print('Saved {:X} in {}'.format(info_hash, file)) printer.print('Saved {:X} in {}'.format(info_hash, file))
with open(file, 'w') as f: with open(file, 'w') as f:
f.write(magnet + '\n') f.write(magnet + '\n')
def copy_magnets(printer, chosen_links, results):
clipboard_text = ''
for link in chosen_links:
magnet = results[link]['magnet']
info_hash = int(re.search(r'btih:([a-f0-9]{40})', magnet).group(1), 16)
clipboard_text += magnet + "\n"
printer.print('Copying {:X} to clipboard'.format(info_hash))
pyperclip.copy(clipboard_text)

View File

@ -24,7 +24,8 @@ if __name__ == '__main__':
}, },
install_requires=['colorama>=0.3.3', install_requires=['colorama>=0.3.3',
'beautifulsoup4>=4.4.1', 'beautifulsoup4>=4.4.1',
'veryprettytable>=0.8.1'], 'veryprettytable>=0.8.1',
'pyperclip>=1.6.2'],
keywords=['torrent', 'magnet', 'download', 'tpb', 'client'], keywords=['torrent', 'magnet', 'download', 'tpb', 'client'],
classifiers=[ classifiers=[
'Topic :: Utilities', 'Topic :: Utilities',