TV-Series
TV-Series operations follow the same steps as those of movies, with the slight difference being the consideration of season and episode numbers, from the extraction of specific item details all the way to initiating the download process.
Series Search¶
The only thing that changes from movies search is the subject_type value:
from moviebox_api.v1.core import Search, Session, SubjectType
async def search_tv_series():
client_session = Session()
search = Search(
client_session, query="Merlin", subject_type=SubjectType.TV_SERIES
)
search_results = await search.get_content()
print(type(search_results)) # (1)
modelled_search_results = await search.get_content_model()
print(type(modelled_search_results)) # (2)
if __name__ == "__main__":
import asyncio
asyncio.run(search_tv_series())
<class 'dict'>access individual search result items fromsearch_results["items"]<class 'moviebox_api.v1.models.SearchResultsModel'>access individual search result items fromsearch_results.items
from moviebox_api.v1.core import Search, Session, SubjectType
def search_tv_series():
client_session = Session()
search = Search(
client_session, query="Merlin", subject_type=SubjectType.TV_SERIES
)
search_results = search.get_content_sync()
print(type(search_results)) # (1)
modelled_search_results = search.get_content_model_sync()
print(type(modelled_search_results)) # (2)
if __name__ == "__main__":
search_tv_series()
<class 'dict'>access individual search result items fromsearch_results["items"]<class 'moviebox_api.v1.models.SearchResultsModel'>access individual search result items fromsearch_results.items
Search Results Navigation
It uses the same approach as movies navigation.
TV-Series Details¶
This involves exploring a particular TV series and getting more information such as the number of episodes per season, available video resolutions, casts, etc.
There are 2 ways of going about this, just like in movies:
1. Using Search Results Item¶
from moviebox_api.v1 import (
Search,
Session,
SubjectType,
TVSeriesDetails,
)
async def tv_series_details_using_search_results_item():
client_session = Session()
search = Search(
client_session, query="Merlin", subject_type=SubjectType.TV_SERIES
)
search_results = await search.get_content_model()
target_item = search_results.first_item # (1)
details_inst = TVSeriesDetails(
target_item,
session=client_session,
)
series_details = await details_inst.get_content_model()
print(type(series_details)) # (2)
if __name__ == "__main__":
import asyncio
asyncio.run(tv_series_details_using_search_results_item())
- Shortcut for
search_results.items[0] - Output:
<class 'moviebox_api.v1.extractor.models.json.ItemJsonDetailsModel'>
from moviebox_api.v1 import (
Search,
Session,
SubjectType,
TVSeriesDetails,
)
def tv_series_details_using_search_results_item():
client_session = Session()
search = Search(
client_session, query="Merlin", subject_type=SubjectType.TV_SERIES
)
search_results = search.get_content_model_sync()
target_item = search_results.first_item # (1)
details_inst = TVSeriesDetails(
target_item,
session=client_session,
)
series_details = details_inst.get_content_model_sync()
print(type(series_details)) # (2)
if __name__ == "__main__":
tv_series_details_using_search_results_item()
- Shortcut for
search_results.items[0] - Output:
<class 'moviebox_api.v1.extractor.models.json.ItemJsonDetailsModel'>
2. Using Item Page URL¶
The page URL is obtained from target_item.page_url.
from moviebox_api.v1 import (
Search,
Session,
SubjectType,
TVSeriesDetails,
)
async def tv_series_details_using_item_page_url():
page_url = "/detail/merlin-sMxCiIO6fZ9?id=8382755684005333552" # (2)
client_session = Session()
details_inst = TVSeriesDetails(
page_url,
session=client_session,
)
series_details = await details_inst.get_content_model()
print(type(series_details)) # (1)
if __name__ == "__main__":
tv_series_details_using_item_page_url()
- Output:
<class 'moviebox_api.v1.extractor.models.json.ItemJsonDetailsModel'> - The URL is obtained from
target_item.page_url. It makes more sense when loaded from cache.
from moviebox_api.v1 import (
Search,
Session,
SubjectType,
TVSeriesDetails,
)
def tv_series_details_using_item_page_url():
page_url = "/detail/merlin-sMxCiIO6fZ9?id=8382755684005333552" # (2)
client_session = Session()
details_inst = TVSeriesDetails(
page_url,
session=client_session,
)
series_details = details_inst.get_content_model_sync()
print(type(series_details)) # (1)
if __name__ == "__main__":
tv_series_details_using_item_page_url()
- Output:
<class 'moviebox_api.v1.extractor.models.json.ItemJsonDetailsModel'> - The URL is obtained from
target_item.page_url. It makes more sense when loaded from cache.
Downloadable Files Detail¶
This follows the same principles as outlined in movies.
from moviebox_api.v1 import (
DownloadableTVSeriesFilesDetail,
Search,
Session,
SubjectType,
TVSeriesDetails,
)
async def downloadable_tv_series_file_details():
client_session = Session()
search = Search(client_session, "Merlin", subject_type=SubjectType.TV_SERIES)
search_results = await search.get_content_model()
target_series = search_results.first_item
target_series_details_instance = TVSeriesDetails(
target_series, client_session
)
target_series_details_model = (
await target_series_details_instance.get_content_model()
)
downloadable_files = DownloadableTVSeriesFilesDetail(
client_session, target_series_details_model
)
downloadable_files_detail = await downloadable_files.get_content_model(
season=1, episode=1
)
print(type(downloadable_files_detail)) # (1)
subtitles = downloadable_files_detail.captions
videos = downloadable_files_detail.downloads
if __name__ == "__main__":
import asyncio
asyncio.run(downloadable_tv_series_file_details())
- Output:
<class 'moviebox_api.v1.models.DownloadableFilesMetadata'>
from moviebox_api.v1 import (
DownloadableTVSeriesFilesDetail,
Search,
Session,
SubjectType,
TVSeriesDetails,
)
def downloadable_tv_series_file_details():
client_session = Session()
search = Search(client_session, "Merlin", subject_type=SubjectType.TV_SERIES)
search_results = search.get_content_model_sync()
target_series = search_results.first_item
target_series_details_instance = TVSeriesDetails(
target_series, client_session
)
target_series_details_model = (
target_series_details_instance.get_content_model_sync()
)
downloadable_files = DownloadableTVSeriesFilesDetail(
client_session, target_series_details_model
)
downloadable_files_detail = downloadable_files.get_content_model_sync(
season=1, episode=1
)
print(type(downloadable_files_detail)) # (1)
subtitles = downloadable_files_detail.captions
videos = downloadable_files_detail.downloads
if __name__ == "__main__":
downloadable_tv_series_file_details()
- Output:
<class 'moviebox_api.v1.models.DownloadableFilesMetadata'>
Download Files¶
These are video and subtitle files.
Download Video¶
from moviebox_api.v1 import (
DownloadableTVSeriesFilesDetail,
Search,
Session,
SubjectType,
TVSeriesDetails,
)
from moviebox_api.v1.download import MediaFileDownloader
async def download_tv_series_video_file():
client_session = Session()
search = Search(client_session, "Merlin", subject_type=SubjectType.TV_SERIES)
search_results = await search.get_content_model()
target_series = search_results.first_item
target_series_details_instance = TVSeriesDetails(
target_series, client_session
)
target_series_details_model = (
await target_series_details_instance.get_content_model()
)
downloadable_files = DownloadableTVSeriesFilesDetail(
client_session, target_series_details_model
)
downloadable_files_detail = await downloadable_files.get_content_model(
season=1, episode=1
)
target_media_file = downloadable_files_detail.best_media_file # (1)
media_file_downloader = MediaFileDownloader()
downloaded_file = await media_file_downloader.run(
target_media_file, filename=target_series, season=1, episode=1
)
print(downloaded_file.saved_to)
if __name__ == "__main__":
import asyncio
asyncio.run(download_tv_series_video_file())
- Shortcut for
downloadable_files_detail.downloads[0]
from moviebox_api.v1 import (
DownloadableTVSeriesFilesDetail,
Search,
Session,
SubjectType,
TVSeriesDetails,
)
from moviebox_api.v1.download import MediaFileDownloader
def download_tv_series_video_file():
client_session = Session()
search = Search(client_session, "Merlin", subject_type=SubjectType.TV_SERIES)
search_results = search.get_content_model_sync()
target_series = search_results.first_item
target_series_details_instance = TVSeriesDetails(
target_series, client_session
)
target_series_details_model = (
target_series_details_instance.get_content_model_sync()
)
downloadable_files = DownloadableTVSeriesFilesDetail(
client_session, target_series_details_model
)
downloadable_files_detail = downloadable_files.get_content_model_sync(
season=1, episode=1
)
target_media_file = downloadable_files_detail.best_media_file # (1)
media_file_downloader = MediaFileDownloader()
downloaded_file = media_file_downloader.run_sync(
target_media_file, filename=target_series, season=1, episode=1
)
print(downloaded_file.saved_to)
if __name__ == "__main__":
download_tv_series_video_file()
- Shortcut for
downloadable_files_detail.downloads[0]
Download Subtitle¶
from moviebox_api.v1 import (
DownloadableTVSeriesFilesDetail,
Search,
Session,
SubjectType,
TVSeriesDetails,
)
from moviebox_api.v1.download import CaptionFileDownloader
async def download_tv_series_subtitle_file():
client_session = Session()
search = Search(client_session, "Merlin", subject_type=SubjectType.TV_SERIES)
search_results = await search.get_content_model()
target_series = search_results.first_item
target_series_details_instance = TVSeriesDetails(
target_series, client_session
)
target_series_details_model = (
await target_series_details_instance.get_content_model()
)
downloadable_files = DownloadableTVSeriesFilesDetail(
client_session, target_series_details_model
)
downloadable_files_detail = await downloadable_files.get_content_model(
season=1, episode=1
)
target_media_file = downloadable_files_detail.english_subtitle_file
caption_file_downloader = CaptionFileDownloader()
downloaded_file = await caption_file_downloader.run(
target_media_file, filename=target_series, season=1, episode=1
)
print(downloaded_file.saved_to)
if __name__ == "__main__":
import asyncio
asyncio.run(download_tv_series_subtitle_file())
from moviebox_api.v1 import (
DownloadableTVSeriesFilesDetail,
Search,
Session,
SubjectType,
TVSeriesDetails,
)
from moviebox_api.v1.download import CaptionFileDownloader
def download_tv_series_subtitle_file():
client_session = Session()
search = Search(client_session, "Merlin", subject_type=SubjectType.TV_SERIES)
search_results = search.get_content_model_sync()
target_series = search_results.first_item
target_series_details_instance = TVSeriesDetails(
target_series, client_session
)
target_series_details_model = (
target_series_details_instance.get_content_model_sync()
)
downloadable_files = DownloadableTVSeriesFilesDetail(
client_session, target_series_details_model
)
downloadable_files_detail = downloadable_files.get_content_model_sync(
season=1, episode=1
)
target_media_file = downloadable_files_detail.english_subtitle_file
caption_file_downloader = CaptionFileDownloader()
downloaded_file = caption_file_downloader.run_sync(
target_media_file, filename=target_series, season=1, episode=1
)
print(downloaded_file.saved_to)
if __name__ == "__main__":
download_tv_series_subtitle_file()