Skip to content

Commit

Permalink
Get permalink
Browse files Browse the repository at this point in the history
Adds a config option to search site API after upload to find the permalink (direct site link) and insert as a comment in the torrent. ie: You client will have the direct page link in the torrent comment field.

Needs a good 5 seconds to ensure the API has updated, hence added as an option, default to False.

Tracker specific, will add some other trackers later.
  • Loading branch information
Audionut committed Oct 20, 2024
1 parent b4a04ed commit 991e5e1
Show file tree
Hide file tree
Showing 27 changed files with 1,052 additions and 2 deletions.
4 changes: 4 additions & 0 deletions data/example-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
# Play the bell sound effect when asking for confirmation
"sfx_on_prompt": True,

# Run an API search after upload to find the permalink and insert as comment in torrent
# Needs a 5 second wait to ensure the API is updated
"get_permalink": False,

},

"TRACKERS": {
Expand Down
40 changes: 40 additions & 0 deletions src/trackers/ACM.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from str2bool import str2bool
from src.trackers.COMMON import COMMON
from src.console import console
import bencodepy


class ACM():
Expand Down Expand Up @@ -374,3 +375,42 @@ async def edit_desc(self, meta):
descfile.write(self.signature)
descfile.close()
return

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
40 changes: 40 additions & 0 deletions src/trackers/AITHER.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from str2bool import str2bool
import platform
import re
import bencodepy

from src.trackers.COMMON import COMMON
from src.console import console
Expand Down Expand Up @@ -224,3 +225,42 @@ async def search_existing(self, meta, disctype):
await asyncio.sleep(5)

return dupes

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
40 changes: 40 additions & 0 deletions src/trackers/AL.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import platform
from str2bool import str2bool
import bencodepy

from src.trackers.COMMON import COMMON
from src.console import console
Expand Down Expand Up @@ -179,3 +180,42 @@ async def search_existing(self, meta, disctype):
async def edit_name(self, meta):
name = meta['uuid'].replace('.mkv', '').replace('.mp4', '').replace(".", " ").replace("DDP2 0", "DDP2.0").replace("DDP5 1", "DDP5.1").replace("H 264", "x264").replace("H 265", "x265").replace("DD+7 1", "DDP7.1").replace("AAC2 0", "AAC2.0").replace('DD5 1', 'DD5.1').replace('DD2 0', 'DD2.0').replace('TrueHD 7 1', 'TrueHD 7.1').replace('DTS-HD MA 7 1', 'DTS-HD MA 7.1').replace('DTS-HD MA 5 1', 'DTS-HD MA 5.1').replace("TrueHD 5 1", "TrueHD 5.1").replace("DTS-X 7 1", "DTS-X 7.1").replace("DTS-X 5 1", "DTS-X 5.1").replace("FLAC 2 0", "FLAC 2.0").replace("FLAC 2 0", "FLAC 2.0").replace("FLAC 5 1", "FLAC 5.1").replace("DD1 0", "DD1.0").replace("DTS ES 5 1", "DTS ES 5.1").replace("DTS5 1", "DTS 5.1").replace("AAC1 0", "AAC1.0").replace("DD+5 1", "DDP5.1").replace("DD+2 0", "DDP2.0").replace("DD+1 0", "DDP1.0")
return name

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
40 changes: 40 additions & 0 deletions src/trackers/BLU.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import platform
from str2bool import str2bool
import bencodepy

from src.trackers.COMMON import COMMON
from src.console import console
Expand Down Expand Up @@ -218,3 +219,42 @@ async def search_existing(self, meta, disctype):
await asyncio.sleep(5)

return dupes

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
40 changes: 40 additions & 0 deletions src/trackers/CBR.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
from str2bool import str2bool
import platform
import bencodepy

from src.trackers.COMMON import COMMON
from src.console import console
Expand Down Expand Up @@ -177,3 +178,42 @@ async def edit_name(self, meta):
name = meta['uuid'].replace('.mkv', '').replace('.mp4', '').replace(".", " ").replace("DDP2 0", "DDP2.0").replace("DDP5 1", "DDP5.1").replace("H 264", "H.264").replace("H 265", "H.265").replace("DD+7 1", "DDP7.1").replace("AAC2 0", "AAC2.0").replace('DD5 1', 'DD5.1').replace('DD2 0', 'DD2.0').replace('TrueHD 7 1', 'TrueHD 7.1').replace('DTS-HD MA 7 1', 'DTS-HD MA 7.1').replace('DTS-HD MA 5 1', 'DTS-HD MA 5.1').replace("TrueHD 5 1", "TrueHD 5.1").replace("DTS-X 7 1", "DTS-X 7.1").replace("DTS-X 5 1", "DTS-X 5.1").replace("FLAC 2 0", "FLAC 2.0").replace("FLAC 5 1", "FLAC 5.1").replace("DD1 0", "DD1.0").replace("DTS ES 5 1", "DTS ES 5.1").replace("DTS5 1", "DTS 5.1").replace("AAC1 0", "AAC1.0").replace("DD+5 1", "DDP5.1").replace("DD+2 0", "DDP2.0").replace("DD+1 0", "DDP1.0")

return name

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
40 changes: 40 additions & 0 deletions src/trackers/FNP.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
from str2bool import str2bool
import platform
import bencodepy

from src.trackers.COMMON import COMMON
from src.console import console
Expand Down Expand Up @@ -166,3 +167,42 @@ async def search_existing(self, meta, disctype):
await asyncio.sleep(5)

return dupes

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
40 changes: 40 additions & 0 deletions src/trackers/HP.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import platform
from str2bool import str2bool
import bencodepy

from src.trackers.COMMON import COMMON
from src.console import console
Expand Down Expand Up @@ -169,3 +170,42 @@ async def search_existing(self, meta, disctype):
await asyncio.sleep(5)

return dupes

async def search_torrent_page(self, meta, disctype):
torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent"
Name = meta['name']
quoted_name = f'"{Name}"'

params = {
'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
'name': quoted_name
}

try:
response = requests.get(url=self.search_url, params=params)
response.raise_for_status()
response_data = response.json()

if response_data['data'] and isinstance(response_data['data'], list):
details_link = response_data['data'][0]['attributes'].get('details_link')

if details_link:
with open(torrent_file_path, 'rb') as open_torrent:
torrent_data = open_torrent.read()

torrent = bencodepy.decode(torrent_data)
torrent[b'comment'] = details_link.encode('utf-8')
updated_torrent_data = bencodepy.encode(torrent)

with open(torrent_file_path, 'wb') as updated_torrent_file:
updated_torrent_file.write(updated_torrent_data)

return details_link
else:
return None
else:
return None

except requests.exceptions.RequestException as e:
print(f"An error occurred during the request: {e}")
return None
Loading

0 comments on commit 991e5e1

Please sign in to comment.