-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvMazeAPI.py
executable file
Β·128 lines (103 loc) Β· 3.4 KB
/
tvMazeAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import requests
import re
tvMazeBaseUrl="https://api.tvmaze.com/"
tvMazeShowsUrl=tvMazeBaseUrl+"shows/"
########################
# make the query
#return info of a single tv show
def getInfo(nameShow):
#remove points and punctuaction that can bring us wrong results
info = re.sub('[^A-Za-z0-9]+', '-', nameShow)
info = requests.get(tvMazeBaseUrl+'singlesearch/shows?q='+nameShow)
info = info.json()
return info
#return an array with all the tv shows that match the name provided.
def getShowsResults(nameShow):
info = re.sub('[^A-Za-z0-9]+', ' ', nameShow)
info = requests.get(tvMazeBaseUrl+"search/shows?q="+nameShow)
info = info.json()
return info
########################
#single episode
#return the title of a single episode
def getTitleEpisode(info, season, numberEpisode):
try:
url =tvMazeShowsUrl+str(info.get("id"))+'/episodebynumber?season='+season+'&number='+str(numberEpisode)
title = requests.get(url)
return title.json().get("name")
except Exception as e:
return "info not found"
#return minutes of the duration of the episode
def getRuntimeEpisode(info, season, numberEpisode):
try:
url =tvMazeShowsUrl+str(info.get("id"))+'/episodebynumber?season='+season+'&number='+str(numberEpisode)
title = requests.get(url)
return title.json().get("runtime")
except Exception as e:
return "info not found"
def getSummaryEpisode(info,season,numberEpisode):
try:
url =tvMazeShowsUrl+str(info.get("id"))+'/episodebynumber?season='+season+'&number='+str(numberEpisode)
title = requests.get(url)
return title.json().get("summary")
except Exception as e:
return "info not found"
#return the date of the next episode
def getNextEpisode(info):
try:
nextEpisodeLink = info.get("_links").get("nextepisode").get("href")
nextEpisode = requests.get(nextEpisodeLink).json().get("airdate")
if (nextEpisode != None):
return nextEpisode
except Exception as e:
return "No info yet"
#return the date of the last episode
def getDateLastEpisode(info):
seasons= requests.get(tvMazeShowsUrl+str(info.get("id"))+"/seasons")
seasons = seasons.json()
lastEpisode=""
#we have to get the greatest date, not the date of the last episode (it couldn't be determined yet)
for i in range(0,len(seasons)):
if(seasons[i].get("endDate"))!=None:
lastEpisode=seasons[i].get("endDate")
return str(lastEpisode)
#return the number of seasons
def getNumberOfSeasons(info):
seasons= requests.get(tvMazeShowsUrl+str(info.get("id"))+"/seasons")
seasons = seasons.json()
return str(len(seasons))
##############################
#return the status (still running or termined or something)
def getStatus(info):
return info.get("status")
#return the generes
def getGenres(info):
return info.get("genres")
def getRating(info):
return str(info.get("rating").get("average"))
def getLinkImage(info):
return info.get("image").get("medium")
def getSummary(info):
return info.get("summary")
def getUrlImage(info):
return info.get("image").get("original")
#return an emoji related to the genere
def getEmojiByGenre(info):
genre = getGenres(info)
strRes =""
if ("Drama" in genre):
strRes += "π"
if("Action" in genre):
strRes +="π₯"
if("Crime" in genre):
strRes +="πͺ"
if("Comedy" in genre):
strRes +="π"
if("Romance" in genre):
strRes +="π«"
if("Science-Fiction" in genre):
strRes +="π§ͺπ"
return strRes
#return the title of the tv show
def getName(info):
return info.get("name")+getEmojiByGenre(info)