Skip to content

Commit

Permalink
Merge pull request #3 from Schmoaaaaah/add-searchpathoverride
Browse files Browse the repository at this point in the history
Add searchpathoverride
  • Loading branch information
schmoaaaaah authored Jul 11, 2024
2 parents a533dc3 + de2f43f commit 4d50f4a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Requires yt-dlp as well as stashapp-tools.
You can install this package with pip:
```shell
python3 -m pip install -U https://github.com/schmoaaaaah/yt-dlp-stash/archive/master.zip
python3 -m pip install yt-dlp-stash
```

See [installing yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#installing-plugins) for the other methods this plugin package can be installed.
Expand All @@ -31,17 +32,26 @@ The apikey is optional and can be left out if you dont have authentication enabl
|---|---|---|---|
|scheme|http|x|scheme at which stash is available. either http or https|
|host|localhost|x|fqdn of the stash instance|
|port|9999|x| port on which stash is accessable|
|apikey||| api key which should be used
|port|9999|x|port on which stash is accessable|
|apikey|||api key which should be used
|sessioncookie|||sessioncookie which should be used|
|[searchpathoverride](#searchpathoverride)|||override the relative path for the search in stash
|[when](https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#post-processing-options)|||when postprocessor is called

if api key and sessioncookie are provided api key is preferred.
#### apikey & sessioncookie
if api key and **sessioncookie** are provided api key is preferred.

#### searchpathoverride
if you set the **searchpathoverride** the relative path of the downloaded file will be overriden when interacting with stash.
so if you define `yt-dlp -o ./media/video.mp4` and set **searchpathoverride** to `/mnt/nas` then stash will look for `/mnt/nas/media/video.mp4`.
> special case `/`:
> if you define `yt-dlp -o ./media/video.mp4` and set **searchpathoverride** to `/` then stash will look for `/media/video.mp4`.
by default the Processor expects the same path for the media in stash as it is downloaded.

#### when
You might need to change `after_video` to `playlist` if you are downloading a playlist.
I haven't tested this yet.

The Processor expects the same path for the media in stash as it is downloaded.

## Development

See the [Plugin Development](https://github.com/yt-dlp/yt-dlp/wiki/Plugin-Development) section of the yt-dlp wiki.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "yt-dlp-stash"
version = "1.1.0"
version = "1.2.0"
readme = "README.md"
authors = [
{ name="Schmoaaaaah", email="schmoaaaaah@r4nd0.com" },
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = yt-dlp-stash
version = 1.1.0
version = 1.2.0

[options]
packages = find_namespace:
16 changes: 12 additions & 4 deletions yt_dlp_plugins/postprocessor/stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import stashapi.log as log
from stashapi.stashapp import StashInterface
from time import sleep
from pathlib import Path

# ℹ️ See the docstring of yt_dlp.postprocessor.common.PostProcessor

# ⚠ The class name must end in "PP"


class StashPP(PostProcessor):
def __init__(self, downloader=None, scheme: str='http', host: str='localhost', port: int=9999, apikey: str='', sessioncookie: str='', **kwargs):
def __init__(self, downloader=None, scheme: str='http', host: str='localhost', port: int=9999, apikey: str='', sessioncookie: str='', searchpathoverride: str='', **kwargs):
# ⚠ Only kwargs can be passed from the CLI, and all argument values will be string
# Also, "downloader", "when" and "key" are reserved names
super().__init__(downloader)
Expand All @@ -27,12 +28,19 @@ def __init__(self, downloader=None, scheme: str='http', host: str='localhost', p
elif sessioncookie:
stash_args["SessionCookie"] = sessioncookie
self.stash = StashInterface(stash_args)
self.searchpathoverride = searchpathoverride

# ℹ️ See docstring of yt_dlp.postprocessor.common.PostProcessor.run
def run(self, info):
self.to_screen("Scanning metadata on path: " + info['requested_downloads'][0]['__finaldir'])
if self.searchpathoverride != '':
filepath = (self.searchpathoverride + info['requested_downloads'][0]['filename'][1:]).replace("//","/")
dirpath = "/".join(filepath.split("/")[0:-1])
else:
filepath = info['requested_downloads'][0]['filepath']
dirpath = info['requested_downloads'][0]['__finaldir']
self.to_screen("Scanning metadata on path: " + dirpath)
try:
stash_meta_job = self.stash.metadata_scan(paths=info['requested_downloads'][0]['__finaldir'],flags={
stash_meta_job = self.stash.metadata_scan(paths=dirpath,flags={
"scanGenerateCovers": False,
"scanGeneratePreviews":False,
"scanGenerateImagePreviews": False,
Expand All @@ -46,7 +54,7 @@ def run(self, info):
return [], info
while self.stash.find_job(stash_meta_job)["status"] != "FINISHED":
sleep(0.5)
scene = self.stash.find_scenes({"path": {"modifier": "EQUALS", "value": info['requested_downloads'][0]['filepath']}})
scene = self.stash.find_scenes({"path": {"modifier": "EQUALS", "value": filepath}})
self.to_screen("Found scene with id: " + scene[0]["id"])
self.tag = self.stash.find_tags({"name": {"modifier": "EQUALS", "value": "scrape"}})
if len(self.tag) == 0:
Expand Down

0 comments on commit 4d50f4a

Please sign in to comment.