2017-01-09 14:21:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-01-09 14:08:18 +00:00
|
|
|
import pytest
|
2017-01-31 00:02:22 +00:00
|
|
|
from plexapi.exceptions import NotFound
|
2020-04-14 20:13:30 +00:00
|
|
|
|
2017-04-23 05:18:53 +00:00
|
|
|
from . import conftest as utils
|
2017-01-09 14:08:18 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_section(plex):
|
|
|
|
sections = plex.library.sections()
|
2017-04-29 05:47:21 +00:00
|
|
|
assert len(sections) >= 3
|
2020-04-14 20:13:30 +00:00
|
|
|
section_name = plex.library.section("TV Shows")
|
|
|
|
assert section_name.title == "TV Shows"
|
2017-01-31 00:02:22 +00:00
|
|
|
with pytest.raises(NotFound):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert plex.library.section("cant-find-me")
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-05-02 03:26:27 +00:00
|
|
|
def test_library_Library_sectionByID_is_equal_section(plex, movies):
|
2017-01-31 00:02:22 +00:00
|
|
|
# test that sctionmyID refreshes the section if the key is missing
|
|
|
|
# this is needed if there isnt any cached sections
|
2017-05-02 03:26:27 +00:00
|
|
|
assert plex.library.sectionByID(movies.key).uuid == movies.uuid
|
|
|
|
|
|
|
|
|
|
|
|
def test_library_sectionByID_with_attrs(plex, movies):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert movies.agent == "com.plexapp.agents.imdb"
|
|
|
|
# This seems to fail for some reason.
|
|
|
|
# my account alloew of sync, didnt find any about settings about the library.
|
|
|
|
# assert movies.allowSync is ('sync' in plex.ownerFeatures)
|
|
|
|
assert movies.art == "/:/resources/movie-fanart.jpg"
|
|
|
|
assert utils.is_metadata(
|
|
|
|
movies.composite, prefix="/library/sections/", contains="/composite/"
|
|
|
|
)
|
2017-05-02 03:26:27 +00:00
|
|
|
assert utils.is_datetime(movies.createdAt)
|
2020-04-14 20:13:30 +00:00
|
|
|
assert movies.filters == "1"
|
|
|
|
assert movies._initpath == "/library/sections"
|
2017-05-02 03:26:27 +00:00
|
|
|
assert utils.is_int(movies.key)
|
2020-04-14 20:13:30 +00:00
|
|
|
assert movies.language == "en"
|
2017-05-02 03:26:27 +00:00
|
|
|
assert len(movies.locations) == 1
|
|
|
|
assert len(movies.locations[0]) >= 10
|
|
|
|
assert movies.refreshing is False
|
2020-04-14 20:13:30 +00:00
|
|
|
assert movies.scanner == "Plex Movie Scanner"
|
2017-05-02 03:26:27 +00:00
|
|
|
assert movies._server._baseurl == utils.SERVER_BASEURL
|
2020-04-14 20:13:30 +00:00
|
|
|
assert movies.thumb == "/:/resources/movie.png"
|
|
|
|
assert movies.title == "Movies"
|
|
|
|
assert movies.type == "movie"
|
2017-05-02 03:26:27 +00:00
|
|
|
assert utils.is_datetime(movies.updatedAt)
|
|
|
|
assert len(movies.uuid) == 36
|
2017-04-15 00:47:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_library_section_get_movie(plex):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert plex.library.section("Movies").get("Sita Sings the Blues")
|
2017-04-15 00:47:59 +00:00
|
|
|
|
|
|
|
|
2020-04-26 19:18:52 +00:00
|
|
|
def test_library_section_movies_all(movies):
|
|
|
|
# size should always be none unless pagenation is being used.
|
|
|
|
assert movies.totalSize == 4
|
|
|
|
assert len(movies.all(container_start=0, container_size=1)) == 1
|
|
|
|
|
|
|
|
|
2017-10-28 23:29:58 +00:00
|
|
|
def test_library_section_delete(movies, patched_http_call):
|
|
|
|
movies.delete()
|
2017-02-10 23:16:23 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_fetchItem(plex, movie):
|
2020-04-14 20:13:30 +00:00
|
|
|
item1 = plex.library.fetchItem("/library/metadata/%s" % movie.ratingKey)
|
2017-04-15 00:47:59 +00:00
|
|
|
item2 = plex.library.fetchItem(movie.ratingKey)
|
2020-04-14 20:13:30 +00:00
|
|
|
assert item1.title == "Elephants Dream"
|
2017-04-15 00:47:59 +00:00
|
|
|
assert item1 == item2 == movie
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
|
2018-09-14 18:03:23 +00:00
|
|
|
def test_library_onDeck(plex, movie):
|
|
|
|
movie.updateProgress(movie.duration * 1000 / 10) # set progress to 10%
|
2017-04-15 00:47:59 +00:00
|
|
|
assert len(list(plex.library.onDeck()))
|
2018-09-14 18:03:23 +00:00
|
|
|
movie.markUnwatched()
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_recentlyAdded(plex):
|
|
|
|
assert len(list(plex.library.recentlyAdded()))
|
2017-01-09 14:21:54 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_add_edit_delete(plex):
|
|
|
|
# Dont add a location to prevent scanning scanning
|
2020-04-14 20:13:30 +00:00
|
|
|
section_name = "plexapi_test_section"
|
|
|
|
plex.library.add(
|
|
|
|
name=section_name,
|
|
|
|
type="movie",
|
|
|
|
agent="com.plexapp.agents.imdb",
|
|
|
|
scanner="Plex Movie Scanner",
|
|
|
|
language="en",
|
|
|
|
)
|
2017-05-02 03:26:27 +00:00
|
|
|
assert plex.library.section(section_name)
|
2020-04-14 20:13:30 +00:00
|
|
|
edited_library = plex.library.section(section_name).edit(
|
|
|
|
name="a renamed lib", type="movie", agent="com.plexapp.agents.imdb"
|
|
|
|
)
|
|
|
|
assert edited_library.title == "a renamed lib"
|
|
|
|
plex.library.section("a renamed lib").delete()
|
2017-02-27 22:16:02 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_cleanBundle(plex):
|
|
|
|
plex.library.cleanBundles()
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_optimize(plex):
|
|
|
|
plex.library.optimize()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_emptyTrash(plex):
|
|
|
|
plex.library.emptyTrash()
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def _test_library_Library_refresh(plex):
|
|
|
|
# TODO: fix mangle and proof the sections attrs
|
|
|
|
plex.library.refresh()
|
2017-02-02 04:47:22 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_update(plex):
|
|
|
|
plex.library.update()
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_cancelUpdate(plex):
|
|
|
|
plex.library.cancelUpdate()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-02-18 21:15:49 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_Library_deleteMediaPreviews(plex):
|
|
|
|
plex.library.deleteMediaPreviews()
|
2017-02-18 21:15:49 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-10-28 23:29:58 +00:00
|
|
|
def test_library_Library_all(plex):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert len(plex.library.all(title__iexact="The 100"))
|
2017-10-28 23:29:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_library_Library_search(plex):
|
2020-04-14 20:13:30 +00:00
|
|
|
item = plex.library.search("Elephants Dream")[0]
|
|
|
|
assert item.title == "Elephants Dream"
|
|
|
|
assert len(plex.library.search(libtype="episode"))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_update(movies):
|
|
|
|
movies.update()
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
|
2017-10-28 23:29:58 +00:00
|
|
|
def test_library_ShowSection_all(tvshows):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert len(tvshows.all(title__iexact="The 100"))
|
2017-10-28 23:29:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_library_MovieSection_refresh(movies, patched_http_call):
|
|
|
|
movies.refresh()
|
|
|
|
|
|
|
|
|
2017-10-25 21:43:23 +00:00
|
|
|
def test_library_MovieSection_search_genre(movie, movies):
|
2020-04-14 20:13:30 +00:00
|
|
|
animation = [i for i in movie.genres if i.tag == "Animation"]
|
2017-11-01 22:18:18 +00:00
|
|
|
assert len(movies.search(genre=animation[0])) > 1
|
2017-10-25 21:43:23 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_cancelUpdate(movies):
|
|
|
|
movies.cancelUpdate()
|
2017-02-18 21:15:49 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_librarty_deleteMediaPreviews(movies):
|
|
|
|
movies.deleteMediaPreviews()
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
|
2018-09-14 18:03:23 +00:00
|
|
|
def test_library_MovieSection_onDeck(movie, movies, tvshows, episode):
|
|
|
|
movie.updateProgress(movie.duration * 1000 / 10) # set progress to 10%
|
|
|
|
assert movies.onDeck()
|
|
|
|
movie.markUnwatched()
|
2018-09-15 08:42:42 +00:00
|
|
|
episode.updateProgress(episode.duration * 1000 / 10)
|
2018-09-14 18:03:23 +00:00
|
|
|
assert tvshows.onDeck()
|
|
|
|
episode.markUnwatched()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_recentlyAdded(movies):
|
|
|
|
assert len(movies.recentlyAdded())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MovieSection_analyze(movies):
|
|
|
|
movies.analyze()
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_ShowSection_searchShows(tvshows):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert tvshows.searchShows(title="The 100")
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_ShowSection_searchEpisodes(tvshows):
|
2020-04-14 20:13:30 +00:00
|
|
|
assert tvshows.searchEpisodes(title="Winter Is Coming")
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_ShowSection_recentlyAdded(tvshows):
|
|
|
|
assert len(tvshows.recentlyAdded())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MusicSection_albums(music):
|
|
|
|
assert len(music.albums())
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MusicSection_searchTracks(music):
|
2020-04-29 21:23:22 +00:00
|
|
|
assert len(music.searchTracks(title="As Colourful As Ever"))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_MusicSection_searchAlbums(music):
|
2020-04-29 21:23:22 +00:00
|
|
|
assert len(music.searchAlbums(title="Layers"))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-23 05:54:53 +00:00
|
|
|
def test_library_PhotoSection_searchAlbums(photos, photoalbum):
|
|
|
|
title = photoalbum.title
|
|
|
|
albums = photos.searchAlbums(title)
|
2017-01-31 00:02:22 +00:00
|
|
|
assert len(albums)
|
|
|
|
|
|
|
|
|
2017-04-23 05:54:53 +00:00
|
|
|
def test_library_PhotoSection_searchPhotos(photos, photoalbum):
|
|
|
|
title = photoalbum.photos()[0].title
|
|
|
|
assert len(photos.searchPhotos(title))
|
2017-01-31 00:02:22 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_library_and_section_search_for_movie(plex):
|
2020-04-14 20:13:30 +00:00
|
|
|
find = "16 blocks"
|
2017-04-15 00:47:59 +00:00
|
|
|
l_search = plex.library.search(find)
|
2020-04-14 20:13:30 +00:00
|
|
|
s_search = plex.library.section("Movies").search(find)
|
2017-01-09 14:21:54 +00:00
|
|
|
assert l_search == s_search
|
|
|
|
|
|
|
|
|
2020-04-15 22:30:00 +00:00
|
|
|
def test_library_Collection_modeUpdate(collection):
|
|
|
|
mode_dict = {"default": "-2", "hide": "0", "hideItems": "1", "showItems": "2"}
|
|
|
|
for key, value in mode_dict.items():
|
|
|
|
collection.modeUpdate(key)
|
|
|
|
collection.reload()
|
|
|
|
assert collection.collectionMode == value
|
2019-07-31 18:51:51 +00:00
|
|
|
|
|
|
|
|
2019-09-14 02:31:38 +00:00
|
|
|
def test_library_Colletion_sortAlpha(collection):
|
2020-04-14 20:13:30 +00:00
|
|
|
collection.sortUpdate(sort="alpha")
|
2019-07-31 18:51:51 +00:00
|
|
|
collection.reload()
|
2020-04-14 20:13:30 +00:00
|
|
|
assert collection.collectionSort == "1"
|
2019-07-31 18:51:51 +00:00
|
|
|
|
|
|
|
|
2019-09-14 02:31:38 +00:00
|
|
|
def test_library_Colletion_sortRelease(collection):
|
2020-04-14 20:13:30 +00:00
|
|
|
collection.sortUpdate(sort="release")
|
2019-07-31 18:51:51 +00:00
|
|
|
collection.reload()
|
2020-04-14 20:13:30 +00:00
|
|
|
assert collection.collectionSort == "0"
|
2019-07-31 18:51:51 +00:00
|
|
|
|
2019-10-03 01:08:27 +00:00
|
|
|
|
2020-04-15 22:30:00 +00:00
|
|
|
def test_search_with_weird_a(plex):
|
|
|
|
ep_title = "Coup de Grâce"
|
|
|
|
result_root = plex.search(ep_title)
|
|
|
|
result_shows = plex.library.section("TV Shows").searchEpisodes(title=ep_title)
|
2017-02-07 07:14:49 +00:00
|
|
|
assert result_root
|
2017-01-09 14:21:54 +00:00
|
|
|
assert result_shows
|
2017-02-07 07:14:49 +00:00
|
|
|
assert result_root == result_shows
|
2017-01-09 14:08:18 +00:00
|
|
|
|
|
|
|
|
2017-04-15 00:47:59 +00:00
|
|
|
def test_crazy_search(plex, movie):
|
2020-04-14 20:13:30 +00:00
|
|
|
movies = plex.library.section("Movies")
|
|
|
|
assert movie in movies.search(
|
|
|
|
actor=movie.actors[0], sort="titleSort"
|
|
|
|
), "Unable to search movie by actor."
|
|
|
|
assert movie in movies.search(
|
|
|
|
director=movie.directors[0]
|
|
|
|
), "Unable to search movie by director."
|
|
|
|
assert movie in movies.search(
|
|
|
|
year=["2006", "2007"]
|
|
|
|
), "Unable to search movie by year."
|
|
|
|
assert movie not in movies.search(year=2007), "Unable to filter movie by year."
|
2017-02-08 07:00:43 +00:00
|
|
|
assert movie in movies.search(actor=movie.actors[0].tag)
|
2020-04-27 18:43:35 +00:00
|
|
|
assert len(movies.search(container_start=2, maxresults=1)) == 1
|
|
|
|
assert len(movies.search(container_size=None)) == 4
|
|
|
|
assert len(movies.search(container_size=1)) == 4
|
2020-04-29 11:42:19 +00:00
|
|
|
assert len(movies.search(container_start=9999, container_size=1)) == 0
|
|
|
|
assert len(movies.search(container_start=2, container_size=1)) == 2
|