Skip to content

Commit

Permalink
Merge pull request #64 from shininome/shino_aio
Browse files Browse the repository at this point in the history
fix dmhy torrent hash
  • Loading branch information
shininome authored Oct 27, 2024
2 parents a3e56f5 + 0700b0e commit fff1991
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions backend/src/module/utils/bangumi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
def get_hash(torrent_url: str) -> str | None:
hash_pattern_dict = {
"magnet_hash_pattern": re.compile(r"urn:btih:([a-fA-F0-9]{40})"),
"torrent_hash_pattern": re.compile(r"/([a-fA-F0-9]{40})\.torrent"),
"nyaa_hash_pattern": re.compile(r"([0-9]+).torrent"),
"torrent_hash_pattern": re.compile(r"/([a-fA-F0-9]{7,40})\.torrent"),
"dmhy_hash_pattern": re.compile(r"urn:btih:([A-Z0-9]{32})"),
}
for hash_pattern in hash_pattern_dict.values():
ans = re.search(hash_pattern, torrent_url)
if ans:
return ans[1]


if __name__ == "__main__":
test_url = r"https://nyaa.land/download/1864806.torrent"
test_url = "magnet:?xt=urn:btih:R5NMZKCR2GYMZJRYO6AUGPKZPTQPAFDM"
print(get_hash(test_url))

0 comments on commit fff1991

Please sign in to comment.