Skip to content

Commit

Permalink
Merge branch 'main' into improve_tv_shows_results
Browse files Browse the repository at this point in the history
  • Loading branch information
Riushda committed Nov 18, 2024
2 parents 7f19c4c + 43b7e37 commit 986c4be
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ SCRAPE_MEDIAFUSION=False # scrape MediaFusion - has better results for Indian co
MEDIAFUSION_URL=https://mediafusion.elfhosted.com # Allows you to scrape custom instances of MediaFusion
PROXY_DEBRID_STREAM=False # Proxy Debrid Streams (very useful to use your debrid service on multiple IPs at same time)
PROXY_DEBRID_STREAM_PASSWORD=CHANGE_ME # Secret password to enter on configuration page to prevent people from abusing your debrid stream proxy
PROXY_DEBRID_STREAM_MAX_CONNECTIONS=100 # IP-Based connection limit for the Debrid Stream Proxy
PROXY_DEBRID_STREAM_MAX_CONNECTIONS=-1 # IP-Based connection limit for the Debrid Stream Proxy (-1 = disabled)
PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE=realdebrid # if you want your users who use the Debrid Stream Proxy not to have to specify Debrid information, but to use the default one instead
PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY=CHANGE_ME # if you want your users who use the Debrid Stream Proxy not to have to specify Debrid information, but to use the default one instead
TITLE_MATCH_CHECK=True # disable if you only use Torrentio / MediaFusion and are sure you're only scraping good titles, for example (keep it True if Zilean is enabled)
REMOVE_ADULT_CONTENT=False # detect and remove adult content
CUSTOM_HEADER_HTML=None # only set it if you know what it is
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Changelog

## [1.40.0](https://github.com/g0ldyy/comet/compare/v1.39.0...v1.40.0) (2024-11-18)


### Features

* reverse order results ([15098f3](https://github.com/g0ldyy/comet/commit/15098f379e0e2012e229d275095afe618304567f))

## [1.39.0](https://github.com/g0ldyy/comet/compare/v1.38.0...v1.39.0) (2024-11-18)


### Features

* shit filter and adult content check ([fe3ddb6](https://github.com/g0ldyy/comet/commit/fe3ddb6702aac23de8e3ad6b51c56899f3f3ea24))


### Bug Fixes

* webui config ([0487af5](https://github.com/g0ldyy/comet/commit/0487af542e3f03a2d95719b4cb7243bc21f8e119))

## [1.38.0](https://github.com/g0ldyy/comet/compare/v1.37.0...v1.38.0) (2024-11-17)


### Features

* ability to disable max connection ([9ebcb71](https://github.com/g0ldyy/comet/commit/9ebcb71ef1cd48ed9ac3079838cf4b2da1575cc2))
* ability to disable max connection [#2](https://github.com/g0ldyy/comet/issues/2) ([412699f](https://github.com/g0ldyy/comet/commit/412699fb55a77069ef17c0e5f826d87cca2d7c8d))
* ability to disable max connection [#3](https://github.com/g0ldyy/comet/issues/3) ([05fe062](https://github.com/g0ldyy/comet/commit/05fe06294b0471a2cd8e7cfb3c3b96a9863e1f6a))
* ability to disable max connection [#4](https://github.com/g0ldyy/comet/issues/4) ([a18dceb](https://github.com/g0ldyy/comet/commit/a18dceb01c49f4a0fee50b3afda11b5008da3085))
* add max results per resolution configuration option ([fefc260](https://github.com/g0ldyy/comet/commit/fefc260b083e46ac062ede04abd694c9841f7c42))
* add search term ([fdb62ab](https://github.com/g0ldyy/comet/commit/fdb62ab60adb046e92279f7f5c2578d9b54fd8bc))
* language unknown support ([6f7c79f](https://github.com/g0ldyy/comet/commit/6f7c79f91dffabd28bcce667be6c72837711414b))


### Bug Fixes

* fix 2160p issue ([5ca4aa5](https://github.com/g0ldyy/comet/commit/5ca4aa59a0b704f77ab45190f2e03fc83e75023e))

## [1.37.0](https://github.com/g0ldyy/comet/compare/v1.36.1...v1.37.0) (2024-11-15)


Expand Down
3 changes: 2 additions & 1 deletion comet/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ async def health():

indexers = settings.INDEXER_MANAGER_INDEXERS
languages = [language for language in PTT.parse.LANGUAGES_TRANSLATION_TABLE.values()]
languages.insert(0, "Multi")
languages.insert(0, "Unknown")
languages.insert(1, "Multi")
web_config = {
"indexers": [indexer.replace(" ", "_").lower() for indexer in indexers],
"languages": languages,
Expand Down
152 changes: 71 additions & 81 deletions comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@

@streams.get("/stream/{type}/{id}.json")
async def stream_noconfig(request: Request, type: str, id: str):
return {
"streams": [
{
"name": "[⚠️] Comet",
"description": f"{request.url.scheme}://{request.url.netloc}/configure",
"url": "https://comet.fast",
}
]
}
return {
"streams": [
{
"name": "[⚠️] Comet",
"description": f"{request.url.scheme}://{request.url.netloc}/configure",
"url": "https://comet.fast",
}
]
}


@streams.get("/{b64config}/stream/{type}/{id}.json")
async def stream(request: Request, b64config: str, type: str, id: str):
Expand Down Expand Up @@ -196,51 +197,40 @@ async def stream(request: Request, b64config: str, type: str, id: str):
)
balanced_hashes = get_balanced_hashes(all_sorted_ranked_files, config)

seen_hashes = set()
for hash, hash_data in all_sorted_ranked_files.items():
if hash in seen_hashes:
continue

for resolution, hash_list in balanced_hashes.items():
if hash in hash_list:
data = hash_data["data"]

the_stream = {
"name": f"[{debrid_extension}{debrid_emoji}] Comet {data['resolution']}",
"description": format_title(data, config),
"torrentTitle": (
data["torrent_title"]
if "torrent_title" in data
else None
),
"torrentSize": (
data["torrent_size"] if "torrent_size" in data else None
),
"behaviorHints": {
"filename": data["raw_title"],
"bingeGroup": "comet|" + hash,
},
}

if config["debridApiKey"] != "":
the_stream["url"] = (
f"{request.url.scheme}://{request.url.netloc}/{b64config}/playback/{hash}/{data['index']}"
)
else:
the_stream["infoHash"] = hash

index = data["index"]
the_stream["fileIdx"] = (
1 if "|" in index else int(index)
) # 1 because for Premiumize it's impossible to get the file index
for resolution in balanced_hashes:
for hash in balanced_hashes[resolution]:
data = all_sorted_ranked_files[hash]["data"]

the_stream = {
"name": f"[{debrid_extension}{debrid_emoji}] Comet {data['resolution']}",
"description": format_title(data, config),
"torrentTitle": (
data["torrent_title"] if "torrent_title" in data else None
),
"torrentSize": (
data["torrent_size"] if "torrent_size" in data else None
),
"behaviorHints": {
"filename": data["raw_title"],
"bingeGroup": "comet|" + hash,
},
}

the_stream["sources"] = trackers
if config["debridApiKey"] != "":
the_stream["url"] = (
f"{request.url.scheme}://{request.url.netloc}/{b64config}/playback/{hash}/{data['index']}"
)
else:
the_stream["infoHash"] = hash

results.append(the_stream)
index = data["index"]
the_stream["fileIdx"] = (
1 if "|" in index else int(index)
) # 1 because for Premiumize it's impossible to get the file index

seen_hashes.add(hash)
the_stream["sources"] = trackers

break
results.append(the_stream)

results_count = len(results)
if results_count != 0:
Expand Down Expand Up @@ -410,11 +400,13 @@ async def stream(request: Request, b64config: str, type: str, id: str):
try:
ranked_file = rtn.rank(
files[hash]["title"],
hash, # , correct_title=name, remove_trash=True
hash,
remove_trash=True, # , correct_title=name, remove_trash=True
)

ranked_files.add(ranked_file)
except:
except Exception as e:
logger.info(f"Filtered out: {e}")
pass

sorted_ranked_files = sort_torrents(ranked_files)
Expand Down Expand Up @@ -484,25 +476,22 @@ async def stream(request: Request, b64config: str, type: str, id: str):
}
)

for hash, hash_data in sorted_ranked_files.items():
for resolution, hash_list in balanced_hashes.items():
if hash in hash_list:
data = hash_data["data"]
results.append(
{
"name": f"[{debrid_extension}⚡] Comet {data['resolution']}",
"description": format_title(data, config),
"torrentTitle": data["torrent_title"],
"torrentSize": data["torrent_size"],
"url": f"{request.url.scheme}://{request.url.netloc}/{b64config}/playback/{hash}/{data['index']}",
"behaviorHints": {
"filename": data["raw_title"],
"bingeGroup": "comet|" + hash,
},
}
)

continue
for resolution in balanced_hashes:
for hash in balanced_hashes[resolution]:
data = sorted_ranked_files[hash]["data"]
results.append(
{
"name": f"[{debrid_extension}⚡] Comet {data['resolution']}",
"description": format_title(data, config),
"torrentTitle": data["torrent_title"],
"torrentSize": data["torrent_size"],
"url": f"{request.url.scheme}://{request.url.netloc}/{b64config}/playback/{hash}/{data['index']}",
"behaviorHints": {
"filename": data["raw_title"],
"bingeGroup": "comet|" + hash,
},
}
)

return {"streams": results}

Expand Down Expand Up @@ -602,16 +591,17 @@ async def playback(request: Request, b64config: str, hash: str, index: str):
and settings.PROXY_DEBRID_STREAM_PASSWORD
== config["debridStreamProxyPassword"]
):
active_ip_connections = await database.fetch_all(
"SELECT ip, COUNT(*) as connections FROM active_connections GROUP BY ip"
)
if any(
connection["ip"] == ip
and connection["connections"]
>= settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS
for connection in active_ip_connections
):
return FileResponse("comet/assets/proxylimit.mp4")
if settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS != -1:
active_ip_connections = await database.fetch_all(
"SELECT ip, COUNT(*) as connections FROM active_connections GROUP BY ip"
)
if any(
connection["ip"] == ip
and connection["connections"]
>= settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS
for connection in active_ip_connections
):
return FileResponse("comet/assets/proxylimit.mp4")

proxy = None

Expand Down
1 change: 1 addition & 0 deletions comet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def start_log():
f"Debrid Stream Proxy: {bool(settings.PROXY_DEBRID_STREAM)} - Password: {settings.PROXY_DEBRID_STREAM_PASSWORD} - Max Connections: {settings.PROXY_DEBRID_STREAM_MAX_CONNECTIONS} - Default Debrid Service: {settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE} - Default Debrid API Key: {settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY}",
)
logger.log("COMET", f"Title Match Check: {bool(settings.TITLE_MATCH_CHECK)}")
logger.log("COMET", f"Remove Adult Content: {bool(settings.REMOVE_ADULT_CONTENT)}")
logger.log("COMET", f"Custom Header HTML: {bool(settings.CUSTOM_HEADER_HTML)}")


Expand Down
41 changes: 31 additions & 10 deletions comet/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@
<sl-input id="maxResults" type="number" min=0 value=0 label="Max Results" placeholder="Enter max results"></sl-input>
</div>

<div class="form-item">
<sl-input id="maxResultsPerResolution" type="number" min=0 value=0 label="Max Results Per Resolution" placeholder="Enter max results per resolution"></sl-input>
</div>

<div class="form-item">
<sl-input id="maxSize" type="number" min=0 value=0 label="Max Size (GB)" placeholder="Enter max size in gigabytes"></sl-input>
</div>
Expand Down Expand Up @@ -555,6 +559,7 @@

<sl-details summary="Advanced Settings">
<div class="form-item">
<sl-checkbox id="reverseResultOrder" help-text="Reverse the order of the results for each resolution (useful for those who need small file sizes)">Reverse Result Order</sl-checkbox>
<sl-select id="resultFormat" multiple label="Result Format" placeholder="Select what to show in result title" hoist max-options-visible=10>
</sl-select>
</div>
Expand Down Expand Up @@ -594,6 +599,7 @@

<script type="module">
const languagesEmojis = {
"Unknown": "❓",
"Multi": "🌎",
"English": "🇬🇧",
"Japanese": "🇯🇵",
Expand Down Expand Up @@ -655,7 +661,8 @@
customElements.whenDefined("sl-select"),
customElements.whenDefined("sl-input"),
customElements.whenDefined("sl-option"),
customElements.whenDefined("sl-icon")
customElements.whenDefined("sl-icon"),
customElements.whenDefined("sl-checkbox")
]);

const webConfig = {{webConfig|tojson}};
Expand Down Expand Up @@ -710,7 +717,9 @@
const languages = Array.from(document.getElementById("languages").selectedOptions).map(option => option.value);
const resolutions = Array.from(document.getElementById("resolutions").selectedOptions).map(option => option.value);
const maxResults = document.getElementById("maxResults").value;
const maxResultsPerResolution = document.getElementById("maxResultsPerResolution").value;
const maxSize = document.getElementById("maxSize").value;
const reverseResultOrder = document.getElementById("reverseResultOrder").checked;
const resultFormat = Array.from(document.getElementById("resultFormat").selectedOptions).map(option => option.value);
const debridService = document.getElementById("debridService").value;
const debridApiKey = document.getElementById("debridApiKey").value;
Expand All @@ -722,7 +731,9 @@
return {
indexers: indexers,
maxResults: parseInt(maxResults),
maxResultsPerResolution: parseInt(maxResultsPerResolution),
maxSize: parseFloat(maxSize * 1073741824),
reverseResultOrder: reverseResultOrder,
resultFormat: selectedResultFormat,
resolutions: selectedResolutions,
languages: selectedLanguages,
Expand Down Expand Up @@ -773,17 +784,27 @@
}

function populateFormFromSettings(settings) {
document.getElementById("maxResults").value = settings.maxResults;
document.getElementById("maxSize").value = settings.maxSize / 1073741824; // Convert back from bytes to GB
document.getElementById("debridService").value = settings.debridService;
document.getElementById("debridApiKey").value = settings.debridApiKey;
document.getElementById("debridStreamProxyPassword").value = settings.debridStreamProxyPassword;
document.getElementById("indexers").value = settings.indexers;
if (settings.languages != "All")
if (settings.maxResults !== null)
document.getElementById("maxResults").value = settings.maxResults;
if (settings.reverseResultOrder !== null)
document.getElementById("reverseResultOrder").checked = settings.reverseResultOrder;
if (settings.maxResultsPerResolution !== null)
document.getElementById("maxResultsPerResolution").value = settings.maxResultsPerResolution;
if (settings.maxSize !== null)
document.getElementById("maxSize").value = settings.maxSize / 1073741824;
if (settings.debridService !== null)
document.getElementById("debridService").value = settings.debridService;
if (settings.debridApiKey !== null)
document.getElementById("debridApiKey").value = settings.debridApiKey;
if (settings.debridStreamProxyPassword !== null)
document.getElementById("debridStreamProxyPassword").value = settings.debridStreamProxyPassword;
if (settings.indexers !== null)
document.getElementById("indexers").value = settings.indexers;
if (settings.languages !== null && settings.languages != "All")
document.getElementById("languages").value = settings.languages;
if (settings.resolutions != "All")
if (settings.resolutions !== null && settings.resolutions != "All")
document.getElementById("resolutions").value = settings.resolutions;
if (settings.resultFormat != "All")
if (settings.resultFormat !== null && settings.resultFormat != "All")
document.getElementById("resultFormat").value = settings.resultFormat;
}

Expand Down
Loading

0 comments on commit 986c4be

Please sign in to comment.