# Create Smart Collection based on file location

**URL:** <https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438>\
**Category:** Metadata & Adding Files\
**Tags:** server-linux, tivo\
**Created:** [November 9, 2021, 1:29am UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438 "2021-11-09T01:29:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![crakerjac21](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@crakerjac21](https://forums.plex.tv/u/crakerjac21)\
**Post date:** [November 9, 2021, 1:29am UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/1 "2021-11-09T01:29:35Z")

</div>

Server Version#: Linux 1.24.5.5173  
Player Version#: NA

Is there a way to create a ‘Smart Collection’ based on file location?

I use Plex to host shows off my TiVo. Shows I record go into a folder /media/tivo/recordings. Tivo suggestions (shows tivo records to ensure there is always something to watch based on my watching habits… Essentially re-runs of old favorites) get saved to /media/tivo/suggestions. Until this point, these have been 2 separate libraries. I would like to combine these into a single library and use the smart collections feature. This way, if I want to find a family friendly show for the kids, I can search by genre and not necessarily care if it’s a recording or suggestion. However, if I want to look at my list of recordings/suggestions, I can filter by collection… Without having to update tags manually… For every recording.

Is this possible? Or is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![crakerjac21](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@crakerjac21](https://forums.plex.tv/u/crakerjac21)\
**Post date:** [November 24, 2021, 3:05pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/2 "2021-11-24T15:05:03Z")

</div>

Anybody? Where can I request a feature? I’d like to create a ‘Smart Collection’ based on file location.

I have my TV shows broken down into 3 logical folders on my hard drive. I’d like to combine them into a single Plex library so if the kids want to watch say ‘Sesame Street’, they don’t care if it’s a new episode or a re-run. However, if I want to watch something, I may only care about ‘new’ episodes in the Recordings folder (hence Smart Collection).

 ![image](https://global.discourse-cdn.com/plex/original/4X/c/c/e/cce2083d7e56f3a807feb9d685305bad09575836.png)

---

<div class="post-metadata">

**Author:** ![tom80H](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tom80h/32/19753_2.png) [@tom80H](https://forums.plex.tv/u/tom80H)\
**Post date:** [November 24, 2021, 3:32pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/3 "2021-11-24T15:32:00Z")

</div>

There’s currently no such option.  
There is an open feature suggestion asking for an option to filter items by their path (or segments of their path). Though it’s a bit older and hasn’t gotten a lot of attention / interest from the community.

> [@Feature Request: File Path filter // Automatic dynamic Full Pathname tags & associated Filter](https://forums.plex.tv/t/feature-request-file-path-filter-automatic-dynamic-full-pathname-tags-associated-filter/47053):
>
> We have other requests that are similar to this but not the same. What I would like is to have a class of user tags for all media files that would be dynamically and automatically created based on the full pathname of the media object and to add a filter option for selecting these dynamic tags in all the players. So every path name Text for a media object and it is the full path including folder and all nested sub folder names and file names, plex media server would break up into discrete wor…

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 24, 2021, 4:15pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/4 "2021-11-24T16:15:24Z")

</div>

there are tools you can use for flagging/tagging that uses plex’s own API if you are programing mindset.

---

<div class="post-metadata">

**Author:** ![crakerjac21](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@crakerjac21](https://forums.plex.tv/u/crakerjac21)\
**Post date:** [November 24, 2021, 4:47pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/5 "2021-11-24T16:47:33Z")

</div>

Linky? I was not aware of any such tools. I have no problem creating a bash script to tag each file based on path. That would actually be very helpful.

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 24, 2021, 4:54pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/6 "2021-11-24T16:54:40Z")

</div>

I use python and the [PlexAPI · PyPI](https://pypi.org/project/PlexAPI/) package. Little more complex than a simple bash script

---

<div class="post-metadata">

**Author:** ![crakerjac21](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@crakerjac21](https://forums.plex.tv/u/crakerjac21)\
**Post date:** [November 24, 2021, 4:57pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/7 "2021-11-24T16:57:07Z")

</div>

Python works too. Thanks @dbirch !

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 24, 2021, 5:01pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/8 "2021-11-24T17:01:58Z")

</div>

Im using an older version of that package, but Ill post a couple useful snipits.

```
    video.addLabel('TAG')

```

* * *

```
    account = MyPlexAccount('<username>', '<password>')
    plex = account.resource('<servername>').connect()

```

* * *

```
    places = ['<show library name>']
    for place in places:
      tv_shows = plex.library.section(place)
      for show in tv_shows.all():

```

* * *

```
    episodes = None
    error_count = 0
    while not episodes:
      try:
        episodes = show.episodes()
      except:
        error_count +=1
        pass
      if error_count > 10:
        episodes = show.episodes()
      time.sleep(2)
    for video in episodes:
      for part in video.iterParts():
        filename = part.file
      if not re.search(ur'<path fragment>',filename,flags=re.I):
```

---

<div class="post-metadata">

**Author:** ![crakerjac21](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@crakerjac21](https://forums.plex.tv/u/crakerjac21)\
**Post date:** [November 24, 2021, 9:21pm UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/9 "2021-11-24T21:21:29Z")

</div>

So I found a way to iterate through all my shows, but it looks like there is a limitation I’m hitting with Plex. I can add a Genre or Label to a show, but not an episode… I may have a show that I actively record show up in the ‘Recordings’ bucket, but re-runs get tossed in the ‘Suggestions’ bucket. Same show, but I’d like each episode to have a respective ‘filter’ I can apply…

Any ideas on a filter I can apply at the episode level?

```auto
def main():
    plex = PlexServer(baseurl, token)

    alltvshows = plex.library.section('02 - All TV Shows')
    for tvshow in alltvshows.all():
        for episode in tvshow.episodes():
            for locstring in episode.locations:
                if "Tivo/Recordings" in locstring:
                    print("Recording")
                    episode.addLabel("Recording") # addLabel doesn't exist for show....
                elif "Tivo/Suggestions" in locstring:
                    print("Suggestion")
                    episode.addLabel("Suggestion") # addLabel doesn't exist for show....
                elif "Chromecast/TV Shows" in locstring:
                    print("Archive")
                    episode.addLabel("Archive") # addLabel doesn't exist for show....

```

---

<div class="post-metadata">

**Author:** ![crakerjac21](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@crakerjac21](https://forums.plex.tv/u/crakerjac21)\
**Post date:** [November 25, 2021, 12:30am UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/10 "2021-11-25T00:30:43Z")

</div>

Ended up just tagging each show instead of each episode. Some shows/episodes will show up in multiple buckets, but I think I can work with that.

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 25, 2021, 12:37am UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/11 "2021-11-25T00:37:17Z")

</div>

if you wanna do it kinda hacky use addCollection(“re-run”) instead of addLabel

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [February 23, 2022, 12:37am UTC](https://forums.plex.tv/t/create-smart-collection-based-on-file-location/756438/12 "2022-02-23T00:37:44Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
