Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMBY, PLEX, JELLYFIN SCRAPERS [request] #918

Open
daveftw84 opened this issue Jun 14, 2023 · 0 comments
Open

EMBY, PLEX, JELLYFIN SCRAPERS [request] #918

daveftw84 opened this issue Jun 14, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@daveftw84
Copy link

daveftw84 commented Jun 14, 2023

`import requests
import logging

class EmbyScraper:
def init(self, base_url, api_key):
self.base_url = base_url
self.api_key = api_key
self.session = requests.Session()
self.session.headers.update({"X-MediaBrowser-Token": self.api_key})

def get_item(self, item_id):
    url = f"{self.base_url}/Items/{item_id}"
    response = self.session.get(url)
    return response.json()

def search_item(self, name, year=None):
    logging.info(f"EmbyScraper is searching for {name}, {year}")
    params = {"SearchTerm": name, "IncludeItemTypes": "Movie,Series"}
    if year:
        params["Years"] = year
    url = f"{self.base_url}/Items"
    response = self.session.get(url, params=params)
    return response.json()

def get_movie(self, title, year=None):
    return self.search_item(title, year)

def get_tvshow(self, title):
    return self.search_item(title)

def get_season(self, tvshow_id):
    params = {"ParentId": tvshow_id, "IncludeItemTypes": "Season"}
    url = f"{self.base_url}/Users/{self.user_id}/Items"
    response = self.session.get(url, params=params)
    return response.json()

def get_episode(self, season_id):
    params = {"ParentId": season_id, "IncludeItemTypes": "Episode"}
    url = f"{self.base_url}/Users/{self.user_id}/Items"
    response = self.session.get(url, params=params)
    return response.json()

Initialize EmbyScraper

scraper = EmbyScraper(base_url="insert your emby url", api_key="insert your emby api")

def sources(item):
if item['type'] == 'movie':
results = scraper.get_movie(item['title'], item.get('year'))
elif item['type'] == 'episode':
show_results = scraper.get_tvshow(item['show_title'])
for show_result in show_results:
season_results = scraper.get_season(show_result['Id'])
for season_result in season_results:
if season_result['IndexNumber'] == item['season_number']:
results = scraper.get_episode(season_result['Id'])
break
else:
results = []

sources = []
for result in results:
    if item['type'] == 'episode' and result['IndexNumber'] != item['episode_number']:
        continue

    source = {
        'url': result['Path'],
        'quality': 'HD',  # Adjust this based on your own criteria
        'language': 'en',  # Adjust this based on your own criteria
        'provider': 'Emby',  # Adjust this as needed
    }
    sources.append(source)

return sources

def search(item):
return sources(item)
`

@daveftw84 daveftw84 added the enhancement New feature or request label Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant