Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshikuniii committed Nov 9, 2022
1 parent 83b8a3f commit c600b10
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 63 deletions.
49 changes: 31 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,27 @@ The project is a work in progress, not finished yet. But, the code works well, f
* After login, open Web Developer Tools (CTRL + SHIFT +I)
* Go to Storage Inspector
* Look for Auth and Gogoanime cookies
> You can use this library without getting GoGoAnime cookies/token, this cookies/token necessary for only getting [download links](https://github.com/yoshiumikuni/pynime#get-download-link), otherwise no need.

### Example Usage of API
###
### Authorize the API
First, you need to initialize the PyNime class.
#### Authorize the API
First, you need to initialize the PyNime class.

```python
from pynimeapi import PyNime
api = PyNime(
auth = "your auth code from cookie",
gogoanime = "your gogoanime code from cookie",
base_url = "https://gogoanime.dk")
```
###

>**Note:** GoGoAnime often change their domain, you can change the `base_url` if they change it. Otherwise, leave it blank. The default URL will refer to https://gogoanime.dk

### Search an Anime
#### Search an Anime
You can search anime by title using `search_anime`. It will print anime that found and return result as `SearchResultObj` which contains two argument `title` and `url`.

```python
from pynimeapi import PyNime
api = PyNime(
Expand All @@ -51,19 +54,21 @@ for i in search_result:
print(i.title) # or
print(i.url)
```
###

>**Note:** `.url` is an URL to anime category/details page.

### Get Anime Details
#### Get Anime Details
You can get a basic details of anime using `get_details`. It will return anime details as `AnimeDetailsObj`.
Details of anime contains :
* title
* season
* synopsis
* genres
* released
* status
* image_url

```python
from pynimeapi import PyNime
api = PyNime(
Expand All @@ -73,15 +78,17 @@ api = PyNime(

search_result = api.search_anime("yofukashi no uta")

details = api.get_details(search_result[0].url)
details = api.get_anime_details(search_result[0].url)
print(details.genres)
print(details.status) # and more...
```
>**Note:** `get_details` input argument is `anime_category_link` which need anime category/details page URL, it will return `AnimeDetailsObj`.

>**Note:** `get_anime_details` input argument is `anime_category_link` which need anime category/details page URL, it will return `AnimeDetailsObj`.

### Get Anime Episode Links
Get total of anime episode available and links per episode using `get_eps_links` and return list of URLs.
#### Get Anime Episode Links
Get total of anime episode available and links per episode using `get_episode_urls` and return list of URLs.

```python
from pynimeapi import PyNime
api = PyNime(
Expand All @@ -91,20 +98,22 @@ api = PyNime(

search_result = api.search_anime("yofukashi no uta")

episode_links = api.get_eps_links(search_result[0].url)
episode_links = api.get_episode_urls(search_result[0].url)
print(episode_links[0]) # link to episode 1
print(episode_links[1]) # link to episode 2
# and more... (array start from 0 btw)
```


### Get Download Link
You can simply get the streamable and downloadable links of a specific episode of an Anime by it's episode URL (get it using `get_eps_links`). This function will return `DownloadLinkObj`.
#### Get Download Link
You can simply get the streamable and downloadable links of a specific episode of an Anime by it's episode URL (get it using `get_episode_urls`). This function will return `DownloadLinkObj`.
`DownloadLinkObj` has following arguments.

* link_360
* link_480
* link_720
* link_1080

```python
from pynimeapi import PyNime
api = PyNime(
Expand All @@ -114,7 +123,7 @@ api = PyNime(

search_result = api.search_anime("yofukashi no uta")

episode_links = api.get_eps_links(search_result[0].url)
episode_links = api.get_episode_urls(search_result[0].url)
print(episode_links[0]) # link to episode 1

eps_one_download = api.get_download_link(episode_links[0])
Expand All @@ -124,23 +133,26 @@ print(eps_one_download.link_480)
```


### Fast Query!
For `fast_query`, this function will return a download link based on the input. This will simplfy all of function above.
#### Quickly Grab Download Link
For `grab_download`, this function will return a download link based on the input. This will simplfy all of function above.

```python
from pynimeapi import PyNime
api = PyNime(
auth = "your auth code from cookie",
gogoanime = "your gogoanime code from cookie",
base_url = "https://gogoanime.dk")

result = api.fast_query("yofukashi no uta", episode = 12, resolution = 480)
result = api.grab_download("yofukashi no uta", episode = 12, resolution = 480)
print(result)
```

>**Note:** Function will print the possible anime search results (default selection is result number 1) and will return download/streamable link for desired episode and resolution. If desired resolution or episode not available, it will return `None`.

### Get Schedule
Get the schedule from today to a week ahead.

```python
import time
from pynimeapi import PyNime
Expand All @@ -153,4 +165,5 @@ current_time = int(time.time())

api.get_schedule(current_time) # just simple call
```

>**Note:** Need UNIX in integer. Return nothing, this funtion only print the schedule. Will fix later.
7 changes: 4 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@


# Downloading a video
file_name = f'{anime_details.title} - Episode {episode_selection + 1}' # You can edit this
# Uncomment code below to test download function
# file_name = f'{anime_details.title} - Episode {episode_selection}' # You can customize the filename ouput
# api.download_video(download_link.link_360, file_name) # Downloading 360p video

## or just use grab_download fucntion for fastest query
## it will return download link in string type
download_link = api.grab_download(anime_title, episode_selection, 1080)
download_link = api.grab_download(anime_details.title, episode_selection, 1080)
print(download_link)

## and.... or grab_stream for get streaming url
stream_url = api.grab_stream(anime_title, episode_selection, 1080)
stream_url = api.grab_stream(anime_details.title, episode_selection, 1080)
print(stream_url)

# Get Schedule
Expand Down
8 changes: 2 additions & 6 deletions pynimeapi/downloader/http_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def check_if_exists(self, source, saved_filename):
return True # skipping download

except Exception as e:
raise e
finally:
pass
print(e)


def download(self, source, save_filename):
Expand Down Expand Up @@ -83,8 +81,6 @@ def download(self, source, save_filename):

return download_filename
except Exception as e:
raise e
except TypeError as e:
raise e
print(e)
finally:
print("\n[!] Download finished.")
22 changes: 8 additions & 14 deletions pynimeapi/pynime.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def search_anime(self, anime_title: str) -> SearchResultObj:
else:
return anime_result

except requests.exceptions.ConnectionError:
print("Network Error.")
except Exception as e:
print(e)


def get_anime_details(self, anime_category_url: str):
Expand Down Expand Up @@ -95,10 +95,8 @@ def get_anime_details(self, anime_category_url: str):

return anime_info

except AttributeError:
print("Invalid argument given!")
except requests.exceptions.ConnectionError:
print("Network Error.")
except Exception as e:
print(e)


def get_episode_urls(self, anime_category_url: str) -> list:
Expand All @@ -125,10 +123,8 @@ def get_episode_urls(self, anime_category_url: str) -> list:

return eps_list

except AttributeError:
print("Invalid argument given!")
except requests.exceptions.ConnectionError:
print("Network Error.")
except Exception as e:
print(e)


def get_download_link(self, anime_episode_url: str) -> DownloadLinkObj:
Expand Down Expand Up @@ -171,10 +167,8 @@ def get_download_link(self, anime_episode_url: str) -> DownloadLinkObj:

return download_links

except AttributeError:
print("Invalid argument given!")
except requests.exceptions.ConnectionError:
print("Network Error.")
except Exception as e:
print(e)


def grab_download(self, anime_title: str, episode: int, resolution: int):
Expand Down
47 changes: 25 additions & 22 deletions pynimeapi/streaming/playlist_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ def __init__(self):
self.regex_pattern = r"x[0-9]+"

def parser(self, playlist_url: str):
playlist = m3u8.load(playlist_url)
playlist_string = playlist.dumps()

if playlist.is_variant:
# find available resolution
find_resolution = re.findall(self.regex_pattern, playlist_string)
find_resolution = [i.replace("x","") for i in find_resolution]

# get uri base
url_parse = urlparse(playlist_url)
uri_base = os.path.dirname(
f"{url_parse.scheme}://{url_parse.netloc}{url_parse.path}"
)

stream = {}
for index, resolution in enumerate(find_resolution):
stream[resolution] = f"{uri_base}/{playlist.playlists[index].uri}"

return stream

else:
return playlist_url
try:
playlist = m3u8.load(playlist_url)
playlist_string = playlist.dumps()

if playlist.is_variant:
# find available resolution
find_resolution = re.findall(self.regex_pattern, playlist_string)
find_resolution = [i.replace("x","") for i in find_resolution]

# get uri base
url_parse = urlparse(playlist_url)
uri_base = os.path.dirname(
f"{url_parse.scheme}://{url_parse.netloc}{url_parse.path}"
)

stream = {}
for index, resolution in enumerate(find_resolution):
stream[resolution] = f"{uri_base}/{playlist.playlists[index].uri}"

return stream

else:
return playlist_url
except Exception as e:
print(e)

0 comments on commit c600b10

Please sign in to comment.