Skip to content

Instantly share code, notes, and snippets.

@dannofx
Last active May 16, 2022 12:06
Show Gist options
  • Save dannofx/561d304dceea33335a4ff4f7a3b53f90 to your computer and use it in GitHub Desktop.
Save dannofx/561d304dceea33335a4ff4f7a3b53f90 to your computer and use it in GitHub Desktop.
Parse a list of links from eztv, extract the magnet links and format the output to use it with transmission-remote
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import requests
import sys
def scrap_magnet(url):
try:
html = requests.get(url)
soup = BeautifulSoup(html.text, 'html.parser')
tag = soup.find('a', 'downloadLink')
magnet_link = tag.get('href')
return magnet_link
except Exception as e:
print ('Error: ' + str(e))
return None
if len(sys.argv) == 1:
print('Usage :', sys.argv[0], 'file_with_eztv_links additional_tranmission_args')
sys.exit(0)
content = None
with open(sys.argv[1]) as f:
content = f.readlines()
urls = content = [x.strip() for x in content]
magnet_links = []
for url in urls:
magnet = scrap_magnet(url)
if not magnet is None:
magnet_links.append(magnet)
additional_transmission_args = ''
if len(sys.argv) > 2:
additional_transmission_args = sys.argv[2]
if len(magnet_links) > 0:
for magnet_link in magnet_links:
result = 'transmission-remote {0} --add "{1}"'.format(additional_transmission_args, magnet_link)
print(result)
else:
print('No links found')
sys.exit(1)
@asuraphel
Copy link

You can do soup.find('a', href = re.compile(r'magnet.*')) to extract magnet links only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment