Giter Site home page Giter Site logo

magatama's Introduction

Magatama

A python CLI utility that can give you a random anime or manga from a selected genre, you can then watch the fetched anime straight from the terminal using ani-cli. Made using InquirerPy and the Jikan API to pull data from MyAnimeList.

Demo

2023-09-13_16-44-39.mp4

Dependencies

Installation

Clone this repository, then download the dependencies.

git clone https://github.com/tsukki9696/magatama.git
cd magatama/
pip install -r requirements.txt

TODO: Package script to the AUR.

Usage

python magatama.py

Move up and down genres with the arrow keys, confirm with Enter/Return.

Limitations

Currently, the script is quite slow, and since the API requests from Jikan are fairly limited, I can only do so much optimisation, but improving the fetching speed is in my plans.

Credits

magatama's People

Contributors

slumberdemon avatar tsukki9696 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

magatama's Issues

shellscript "port"

i rewrote a more minimalistic version of this program in shell, for fun, thought i'd share it here:
the only dependencies are fzf and mpv (and a posix shell to run the script duh

#!/bin/sh

genre_id=$(curl -s "https://api.jikan.moe/v4/genres/anime" | tr '{' '\n' |
    sed -nE "s@.*\"mal_id\":([0-9]*).*\"name\":\"([^\"]*)\".*@\1\t\2@p" | fzf --with-nth 2.. | cut -f1)

page_number=$(shuf -i 1-9 -n1)
anime_name=$(curl -s "https://api.jikan.moe/v4/anime?page=${page_number}&genres=${genre_id}" | tr '{' '\n' |
    sed -nE "s@.*\"title\":\"([a-zA-Z0-9 ^\"]*)\".*@\1@p" | sort -u | shuf | head -1)
printf "\033[0;35m%s\033[0m\n" "Searching for $anime_name..."
query=$(printf "%s" "$anime_name" | tr ' ' '+')

choice=$(curl -s "https://yugenanime.tv/discover/?q=${query}" | sed -nE "s@.*href=\"([^\"]*)\" title=\"([^\"]*)\".*@\1\t\2@p" | head -1)
[ -z "$choice" ] && exit 1
anime_id=$(printf "%s" "$choice" | cut -f1)
anime_title=$(printf "%s" "$choice" | cut -f2)

tmp_episode_info=$(curl -s "https://yugenanime.tv${anime_id}watch/" | sed -nE "s@.*href=\"/([^\"]*)\" title=\"([^\"]*)\".*@\1\t\2@p" | head -1)
tmp_href=$(printf "%s" "$tmp_episode_info" | cut -f1)
ep_title=$(printf "%s" "$tmp_episode_info" | cut -f2)
yugen_id=$(curl -s "https://yugenanime.tv/$tmp_href" | sed -nE "s@.*id=\"main-embed\" src=\".*/e/([^/]*)/\".*@\1@p")
episode_info=$(printf "%s\t%s" "$yugen_id" "$ep_title")
[ -z "$episode_info" ] && exit 1

episode_id=$(printf "%s" "$episode_info" | cut -f1)
episode_title=$(printf "%s" "$episode_info" | cut -f2)
[ "$episode_id" = "$episode_title" ] && episode_title=""
"\033[0;35m%s\033[0m\n" "Playing $anime_title - Ep $episode_title"
json_data=$(curl -s 'https://yugenanime.tv/api/embed/' -X POST -H 'X-Requested-With: XMLHttpRequest' --data-raw "id=$episode_id&ac=0")
[ -z "$json_data" ] && exit 1

video_link=$(printf "%s" "$json_data" | tr '{}' '\n' | sed -nE "s@.*\"hls\": \[\"([^\"]*)\".*@\1@p")
# hls_link_2=$(printf "%s" "$json_data" | tr '{}' '\n' | sed -nE "s@.*hls.*, \"([^\"]*)\".\]*@\1@p")
# gogo_link=$(printf "%s" "$json_data" | tr '{}' '\n' | sed -nE "s@.*\"src\": \"([^\"]*)\", \"type\": \"embed.*@\1@p")

[ -z "$video_link" ] && exit 1
# printf "Playing %s - Ep %s\n" "$anime_title" "$episode_title"
# print the above in blue
printf "\033[0;34m%s\033[0m\n" "Playing $anime_title - Ep $episode_title"
mpv --force-media-title="$anime_title - Ep $episode_title" "$video_link"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.