Skip to content

Commit 27653eb

Browse files
authored
adding Bit-HDTV support (#239)
adding Bit-hdtv
1 parent eef529e commit 27653eb

File tree

3 files changed

+229
-2
lines changed

3 files changed

+229
-2
lines changed

data/example-config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
"draft_default" : "True",
4949
# "anon" : False
5050
},
51+
"BHDTV": {
52+
"api_key": "found under https://www.bit-hdtv.com/my.php",
53+
"announce_url": "https://trackerr.bit-hdtv.com/announce",
54+
#passkey found under https://www.bit-hdtv.com/my.php
55+
"my_announce_url": "https://trackerr.bit-hdtv.com/passkey/announce",
56+
"tag": "BIT-HDTV, 7d"
57+
# "anon" : "False"
58+
},
5159
"PTP" : {
5260
"useAPI" : False, # Set to True if using PTP
5361
"add_web_source_to_desc" : True,
@@ -284,3 +292,4 @@
284292
}
285293
}
286294
}
295+

src/trackers/BHDTV.py

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# -*- coding: utf-8 -*-
2+
# import discord
3+
import asyncio
4+
from torf import Torrent
5+
import requests
6+
from src.console import console
7+
import distutils.util
8+
from pprint import pprint
9+
import os
10+
import traceback
11+
from src.trackers.COMMON import COMMON
12+
from pymediainfo import MediaInfo
13+
14+
15+
# from pprint import pprint
16+
17+
class BHDTV():
18+
"""
19+
Edit for Tracker:
20+
Edit BASE.torrent with announce and source
21+
Check for duplicates
22+
Set type/category IDs
23+
Upload
24+
"""
25+
26+
def __init__(self, config):
27+
self.config = config
28+
self.tracker = 'BHDTV'
29+
self.source_flag = 'BIT-HDTV'
30+
#search not implemented
31+
#self.search_url = 'https://api.bit-hdtv.com/torrent/search/advanced'
32+
self.upload_url = 'https://www.bit-hdtv.com/takeupload.php'
33+
#self.forum_link = 'https://www.bit-hdtv.com/rules.php'
34+
self.banned_groups = []
35+
pass
36+
37+
async def upload(self, meta):
38+
common = COMMON(config=self.config)
39+
await common.edit_torrent(meta, self.tracker, self.source_flag)
40+
await self.edit_desc(meta)
41+
cat_id = await self.get_cat_id(meta)
42+
sub_cat_id = ""
43+
if meta['category'] == 'MOVIE':
44+
sub_cat_id = await self.get_type_movie_id(meta)
45+
elif meta['category'] == 'TV' and not meta['tv_pack']:
46+
sub_cat_id = await self.get_type_tv_id(meta['type'])
47+
else:
48+
# must be TV pack
49+
sub_cat_id = await self.get_type_tv_pack_id(meta['type'])
50+
51+
52+
53+
resolution_id = await self.get_res_id(meta['resolution'])
54+
# region_id = await common.unit3d_region_ids(meta.get('region'))
55+
# distributor_id = await common.unit3d_distributor_ids(meta.get('distributor'))
56+
if meta['anon'] == 0 and bool(
57+
distutils.util.strtobool(self.config['TRACKERS'][self.tracker].get('anon', "False"))) == False:
58+
anon = 0
59+
else:
60+
anon = 1
61+
62+
if meta['bdinfo'] != None:
63+
mi_dump = None
64+
bd_dump = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/BD_SUMMARY_00.txt", 'r', encoding='utf-8').read()
65+
else:
66+
mi_dump = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/MEDIAINFO_CLEANPATH.txt", 'r', encoding='utf-8').read()
67+
bd_dump = None
68+
desc = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]DESCRIPTION.txt", 'r').read()
69+
open_torrent = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent", 'rb')
70+
files = {'file': open_torrent}
71+
72+
if meta['is_disc'] != 'BDMV':
73+
# Beautify MediaInfo for HDT using custom template
74+
video = meta['filelist'][0]
75+
mi_template = os.path.abspath(f"{meta['base_dir']}/data/templates/MEDIAINFO.txt")
76+
if os.path.exists(mi_template):
77+
media_info = MediaInfo.parse(video, output="STRING", full=False,
78+
mediainfo_options={"inform": f"file://{mi_template}"})
79+
80+
data = {
81+
'api_key': self.config['TRACKERS'][self.tracker]['api_key'].strip(),
82+
'name': meta['name'].replace(' ', '.').replace(':.', '.').replace(':', '.').replace('DD+', 'DDP'),
83+
'mediainfo': mi_dump if bd_dump == None else bd_dump,
84+
'cat': cat_id,
85+
'subcat': sub_cat_id,
86+
'resolution': resolution_id,
87+
#'anon': anon,
88+
# admins asked to remove short description.
89+
'sdescr': " ",
90+
'descr': media_info if bd_dump == None else "Disc so Check Mediainfo dump ",
91+
'screen': desc,
92+
'url': f"https://www.tvmaze.com/shows/{meta['tvmaze_id']}" if meta['category'] == 'TV' else f"https://www.imdb.com/title/tt{meta['imdb_id']}",
93+
'format': 'json'
94+
}
95+
96+
97+
if meta['debug'] == False:
98+
response = requests.post(url=self.upload_url, data=data, files=files)
99+
try:
100+
# pprint(data)
101+
console.print(response.json())
102+
except:
103+
console.print(f"[cyan]It may have uploaded, go check")
104+
# cprint(f"Request Data:", 'cyan')
105+
pprint(data)
106+
console.print(traceback.print_exc())
107+
else:
108+
console.print(f"[cyan]Request Data:")
109+
pprint(data)
110+
# # adding my anounce url to torrent.
111+
if 'view' in response.json()['data']:
112+
await common.add_tracker_torrent(meta, self.tracker, self.source_flag, self.config['TRACKERS']['BHDTV'].get('my_announce_url'), response.json()['data']['view'])
113+
else:
114+
await common.add_tracker_torrent(meta, self.tracker, self.source_flag,
115+
self.config['TRACKERS']['BHDTV'].get('my_announce_url'),
116+
"Torrent Did not upload")
117+
open_torrent.close()
118+
119+
120+
async def get_cat_id(self, meta):
121+
category_id = '0'
122+
if meta['category'] == 'MOVIE':
123+
category_id = '7'
124+
elif meta['tv_pack']:
125+
category_id = '12'
126+
else:
127+
# must be tv episode
128+
category_id = '10'
129+
return category_id
130+
131+
132+
async def get_type_movie_id(self, meta):
133+
type_id = '0'
134+
test = meta['type']
135+
if meta['type'] == 'DISC':
136+
if meta['3D']:
137+
type_id = '46'
138+
else:
139+
type_id = '2'
140+
elif meta['type'] == 'REMUX':
141+
if str(meta['name']).__contains__('265') :
142+
type_id = '48'
143+
elif meta['3D']:
144+
type_id = '45'
145+
else:
146+
type_id = '2'
147+
elif meta['type'] == 'HDTV':
148+
type_id = '6'
149+
elif meta['type'] == 'ENCODE':
150+
if str(meta['name']).__contains__('265') :
151+
type_id = '43'
152+
elif meta['3D']:
153+
type_id = '44'
154+
else:
155+
type_id = '1'
156+
elif meta['type'] == 'WEBDL' or meta['type'] == 'WEBRIP':
157+
type_id = '5'
158+
159+
return type_id
160+
161+
162+
async def get_type_tv_id(self, type):
163+
type_id = {
164+
'HDTV': '7',
165+
'WEBDL': '8',
166+
'WEBRIP': '8',
167+
#'WEBRIP': '55',
168+
#'SD': '59',
169+
'ENCODE': '10',
170+
'REMUX': '11',
171+
'DISC': '12',
172+
}.get(type, '0')
173+
return type_id
174+
175+
176+
async def get_type_tv_pack_id(self, type):
177+
type_id = {
178+
'HDTV': '13',
179+
'WEBDL': '14',
180+
'WEBRIP': '8',
181+
#'WEBRIP': '55',
182+
#'SD': '59',
183+
'ENCODE': '16',
184+
'REMUX': '17',
185+
'DISC': '18',
186+
}.get(type, '0')
187+
return type_id
188+
189+
190+
async def get_res_id(self, resolution):
191+
resolution_id = {
192+
'2160p': '4',
193+
'1080p': '3',
194+
'1080i':'2',
195+
'720p': '1'
196+
}.get(resolution, '10')
197+
return resolution_id
198+
199+
async def edit_desc(self, meta):
200+
base = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/DESCRIPTION.txt", 'r').read()
201+
with open(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]DESCRIPTION.txt", 'w') as desc:
202+
desc.write(base.replace("[img=250]", "[img=250x250]"))
203+
images = meta['image_list']
204+
if len(images) > 0:
205+
for each in range(len(images)):
206+
web_url = images[each]['web_url']
207+
img_url = images[each]['img_url']
208+
desc.write(f"[url={web_url}][img]{img_url}[/img][/url] ")
209+
# desc.write(common.get_links(meta, "[COLOR=red][size=4]", "[/size][/color]"))
210+
desc.close()
211+
return
212+
213+
async def search_existing(self, meta):
214+
console.print(f"[red]Dupes must be checked Manually")
215+
return ['Dupes must be checked Manually']
216+
### hopefully someone else has the time to implement this.

upload.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from src.trackers.HDT import HDT
3232
from src.trackers.RF import RF
3333
from src.trackers.OE import OE
34+
from src.trackers.BHDTV import BHDTV
3435
import json
3536
from pathlib import Path
3637
import asyncio
@@ -242,12 +243,12 @@ async def do_the_thing(base_dir):
242243
####### Upload to Trackers #######
243244
####################################
244245
common = COMMON(config=config)
245-
api_trackers = ['BLU', 'AITHER', 'STC', 'R4E', 'STT', 'RF', 'ACM','LCD','LST','HUNO', 'SN', 'LT', 'NBL', 'ANT', 'JPTV', 'TDC', 'OE']
246+
api_trackers = ['BLU', 'AITHER', 'STC', 'R4E', 'STT', 'RF', 'ACM','LCD','LST','HUNO', 'SN', 'LT', 'NBL', 'ANT', 'JPTV', 'TDC', 'OE', 'BHDTV']
246247
http_trackers = ['HDB', 'TTG', 'FL', 'PTER', 'HDT', 'MTV']
247248
tracker_class_map = {
248249
'BLU' : BLU, 'BHD': BHD, 'AITHER' : AITHER, 'STC' : STC, 'R4E' : R4E, 'THR' : THR, 'STT' : STT, 'HP' : HP, 'PTP' : PTP, 'RF' : RF, 'SN' : SN,
249250
'ACM' : ACM, 'HDB' : HDB, 'LCD': LCD, 'TTG' : TTG, 'LST' : LST, 'HUNO': HUNO, 'FL' : FL, 'LT' : LT, 'NBL' : NBL, 'ANT' : ANT, 'PTER': PTER, 'JPTV' : JPTV,
250-
'TL' : TL, 'TDC' : TDC, 'HDT' : HDT, 'MTV': MTV, 'OE': OE
251+
'TL' : TL, 'TDC' : TDC, 'HDT' : HDT, 'MTV': MTV, 'OE': OE, 'BHDTV': BHDTV
251252
}
252253

253254
for tracker in trackers:
@@ -271,6 +272,7 @@ async def do_the_thing(base_dir):
271272
continue
272273
dupes = await tracker_class.search_existing(meta)
273274
dupes = await common.filter_dupes(dupes, meta)
275+
# note BHDTV does not have search implemented.
274276
meta = dupe_check(dupes, meta)
275277
if meta['upload'] == True:
276278
await tracker_class.upload(meta)

0 commit comments

Comments
 (0)