Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Some new Plugins #36

Open
wants to merge 6 commits into
base: sql-extended
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<a href="https://t.me/userbotindo"> <img src="https://img.shields.io/badge/telegram-Support_Group-blue?style=social&logo=telegram" alt="Support" /></a>
</p>

![logo](https://i.ibb.co/02QVkHC/headersmina.jpg)
![logo](#)

```
#include <std/disclaimer.h>
Expand Down Expand Up @@ -72,4 +72,4 @@ and many more people who aren't mentioned here, but may be found in [Contributor

## License

This userbot licensed on [Raphielscape Public License](https://github.com/MoveAngel/One4uBot/blob/sql-extended/LICENSE) - Version 1.d, February 2020
This userbot licensed on [Raphielscape Public License](https://github.com/MoveAngel/One4uBot/blob/sql-extended/LICENSE) - Version 1.d, February 2020
330 changes: 330 additions & 0 deletions tmdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
# (c) @Avishkarpatil

"""
TheMovieDB
====================================
It contains Movie & TvShows class, a synchronous themoviedb wrapper.
"""


from abc import ABC, abstractmethod
from typing import Optional, Dict, Any
from requests import get
from .excs import TmdbApiError, ZeroResultsFound


class AbsMovieDB(ABC):
"""Abstract class for tmdb"""

def __init__(self, api_key):
"""
:param api_key :type str themoviedb API key.
"""
self.api_key = api_key
self.base_url = "https://api.themoviedb.org/3"

@abstractmethod
def search(self):
pass


############################## Movies class ##############################


class Movie(AbsMovieDB):
"""This class handles all movie related tasks"""

def search(
self,
query: str,
language: str = "en",
page: Optional[int] = 1,
include_adult: Optional[str] = "true",
) -> Dict[str, Any]:
"""
search for the query and return data in json format
"""

payload = {
"api_key": self.api_key,
"language": language,
"query": query,
"page": page,
"include_adult": include_adult,
}

resp = get(self.base_url + "/search/movie", params=payload)

if resp.status_code == 200:

check_res = resp.json()["results"]
if len(check_res) <= 0:
raise ZeroResultsFound(resp.text)
return resp.json()

raise TmdbApiError(resp.text)

def searchid(
self,
movie_id: int,
language: str = "en",
append_to_response: Optional[str] = "videos",
) -> Dict[str, Any]:
"""
returns movie detais for the movie_id in json format
"""

payload = {
"api_key": self.api_key,
"language": language,
"append_to_response": append_to_response,
}

resp = get(self.base_url + f"/movie/{movie_id}", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def recommendations(
self, movie_id: int, language: str = "en", page: Optional[int] = 1
) -> Dict[str, Any]:
"""
returns recommendations data for the movie_id in json format
"""

payload = {"api_key": self.api_key, "language": language, "page": page}

resp = get(self.base_url + f"/movie/{movie_id}/recommendations", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def trending(self, time_win: str = "week") -> Dict[str, Any]:
"""
returns trending movies for time_win (day / week) in json format
"""
payload = {"api_key": self.api_key}

resp = get(self.base_url + f"/trending/movie/{time_win}", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def certification(self) -> Dict[str, Any]:
"""
Get an up to date list of the officially
supported movie certifications on TMDb.
"""

payload = {"api_key": self.api_key}

resp = get(self.base_url + "/certification/movie/list", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def genre(self, language: str = "en") -> Dict[str, Any]:
"""
Get the list of official genres for movies.
"""
payload = {"api_key": self.api_key, "language": language}

resp = get(self.base_url + "/genre/movie/list", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def alternative_titles(
self, movie_id: int, country: Optional[str] = None
) -> Dict[str, Any]:
"""
Get all of the alternative titles for a movie.
"""

payload = {"api_key": self.api_key, "country": country}

resp = get(
self.base_url + f"/movie/{movie_id}/alternative_titles", params=payload
)

if resp.status_code == 200:

check_res = resp.json()["titles"]
if len(check_res) <= 0:
raise ZeroResultsFound(resp.text)
return resp.json()

raise TmdbApiError(resp.text)

def collection(self, collection_id: int, language: str = "en") -> Dict[str, Any]:
"""
Get collection details by id.
"""

payload = {"api_key": self.api_key, "language": language}

resp = get(self.base_url + f"/collection/{collection_id}", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def search_collection(
self, query: str, language: str = "en", page: Optional[int] = 1
) -> Dict[str, Any]:
"""
Search for collections.
"""

payload = {
"api_key": self.api_key,
"language": language,
"query": query,
"page": page,
}

resp = get(self.base_url + "/search/collection", params=payload)

if resp.status_code == 200:

check_res = resp.json()["results"]
if len(check_res) <= 0:
raise ZeroResultsFound(resp.text)
return resp.json()

raise TmdbApiError(resp.text)


############################## TvShows class ##############################


class TvShows(AbsMovieDB):
"""This class handles all tv related tasks"""

def search(
self,
query: str,
language: str = "en",
page: Optional[int] = 1,
include_adult: Optional[str] = "true",
) -> Dict[str, Any]:
"""
search for the query and return data in json format
"""

payload = {
"api_key": self.api_key,
"language": language,
"query": query,
"page": page,
"include_adult": include_adult,
}

resp = get(self.base_url + "/search/tv", params=payload)

if resp.status_code == 200:

check_res = resp.json()["results"]
if len(check_res) <= 0:
raise ZeroResultsFound(resp.text)
return resp.json()

raise TmdbApiError(resp.text)

def searchid(
self,
tv_id: int,
language: str = "en",
append_to_response: Optional[str] = "videos",
) -> Dict[str, Any]:
"""
returns tv detais for the tv_id in json format
"""

payload = {
"api_key": self.api_key,
"language": language,
"append_to_response": append_to_response,
}

resp = get(self.base_url + f"/tv/{tv_id}", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def recommendations(
self, tv_id: int, language: str = "en", page: Optional[int] = 1
) -> Dict[str, Any]:
"""
returns recommendations data for the tv_id in json format
"""

payload = {"api_key": self.api_key, "language": language, "page": page}

resp = get(self.base_url + f"/tv/{tv_id}/recommendations", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def trending(self, time_win: str = "week") -> Dict[str, Any]:
"""
returns trending tvshows for time_win (day / week) in json format
"""
payload = {"api_key": self.api_key}

resp = get(self.base_url + f"/trending/tv/{time_win}", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def certification(self) -> Dict[str, Any]:
"""
Get an up to date list of the officially
supported TV show certifications on TMDb.
"""

payload = {"api_key": self.api_key}

resp = get(self.base_url + "/certification/tv/list", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def genre(self, language: str = "en") -> Dict[str, Any]:
"""
Get the list of official genres for TV shows.
"""
payload = {"api_key": self.api_key, "language": language}

resp = get(self.base_url + "/genre/tv/list", params=payload)

if resp.status_code == 200:
return resp.json()
raise TmdbApiError(resp.text)

def alternative_titles(self, tv_id: int, language: str = "en") -> Dict[str, Any]:
"""
Returns all of the alternative titles for a TV show.
"""

payload = {"api_key": self.api_key, "language": language}

resp = get(self.base_url + f"/tv/{tv_id}/alternative_titles", params=payload)

if resp.status_code == 200:

check_res = resp.json()["results"]
if len(check_res) <= 0:
raise ZeroResultsFound(resp.text)
return resp.json()

raise TmdbApiError(resp.text)
28 changes: 28 additions & 0 deletions userbot/modules/about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ported from other Telegram UserBots for TeleBot//Made for TeleBot
# Kangers, don't remove this line
# @its_xditya
"""Available Commands:
.info
"""
import asyncio

from userbot.utils import admin_cmd


@borg.on(admin_cmd("infowho"))
async def _(event):
if event.fwd_from:
return
animation_interval = 0.1
animation_ttl = range(0, 36)
# input_str = event.pattern_match.group(1)
# if input_str == "Visit this page to know more about TeleBot.":
await event.edit("Thanks")
animation_chars = [
"**TeleBot**", "[More Info](https://telegra.ph/TeleBot-07-08)"
]

for i in animation_ttl:

await asyncio.sleep(animation_interval)
await event.edit(animation_chars[i % 18])
Loading