Commit 10ad1dfd40
Unsigned
Layout: unified · split
anilist.py +58 −32
| @@ -39,44 +39,70 @@ def get_user_data(): | |||
| 39 | # Print the response | 39 | # Print the response |
| 40 | return response.json() | 40 | return response.json() |
| 41 | 41 | ||
| 42 | def load_json_file(file_path): | ||
| 43 | with open(file_path, 'r', encoding='utf-8') as file: | ||
| 44 | return json.load(file) | ||
| 42 | 45 | ||
| 43 | def search_anime_by_title(json_data, search_title): | 46 | def search_anime_by_title(json_data, search_title): |
| 44 | """ | 47 | results = [] |
| 45 | Search for an anime by its title in the giv en JSON data and return its ID. | 48 | if search_title=="1P": |
| 49 | search_title = "ONE PIECE" | ||
| 50 | for list_item in json_data['data']['MediaListCollection']['lists']: | ||
| 51 | for entry in list_item['entries']: | ||
| 52 | media = entry['media'] | ||
| 53 | romaji_title = media['title']['romaji'] | ||
| 54 | english_title = media['title']['english'] | ||
| 55 | try: | ||
| 56 | if search_title.lower() in romaji_title.lower() or search_title.lower() in english_title.lower(): | ||
| 57 | results.append({ | ||
| 58 | 'id': media['id'], | ||
| 59 | 'progress': entry['progress'], | ||
| 60 | 'romaji_title': romaji_title, | ||
| 61 | 'english_title': english_title | ||
| 62 | }) | ||
| 63 | except: | ||
| 64 | pass | ||
| 65 | |||
| 66 | return results | ||
| 67 | |||
| 68 | def main(): | ||
| 69 | # Load the JSON file | ||
| 70 | json_file_path = 'response.json' # Replace with the path to your JSON file | ||
| 71 | json_data = load_json_file(json_file_path) | ||
| 72 | |||
| 73 | # Ask for the title to search | ||
| 74 | # search_title = input("Enter the anime title to search (Romaji or English): ") | ||
| 46 | 75 | ||
| 47 | :param json_data: The JSON data as a dictionary. | 76 | search_title = "1P" |
| 48 | :param search_title: The title of the anime to search for. | ||
| 49 | :return: The ID of the anime if found, otherwise None. | ||
| 50 | """ | ||
| 51 | # Navigate to the list of entries | ||
| 52 | anime_list = json_data['data']['MediaListCollection']['lists'][0]['entries'] | ||
| 53 | 77 | ||
| 54 | # Search for the anime with the given title | 78 | # Search for the anime |
| 55 | for entry in anime_list: | 79 | results = search_anime_by_title(json_data, search_title) |
| 56 | media = entry['media'] | ||
| 57 | title_romaji = media['title']['romaji'] | ||
| 58 | title_english = media['title']['english'] | ||
| 59 | |||
| 60 | # Check if either title matches the search title | ||
| 61 | if search_title.lower() in title_romaji.lower() or search_title.lower() in title_english.lower(): | ||
| 62 | return media['id'] | ||
| 63 | 80 | ||
| 64 | # If not found, return None | 81 | # Print the results |
| 65 | return None | 82 | if results: |
| 83 | for result in results: | ||
| 84 | print(f"Anime ID: {result['id']}, Progress: {result['progress']}, " | ||
| 85 | f"Romaji Title: {result['romaji_title']}, English Title: {result['english_title']}") | ||
| 86 | else: | ||
| 87 | print("Anime not found.") | ||
| 88 | |||
| 89 | if __name__ == "__main__": | ||
| 90 | main() | ||
| 91 | |||
| 66 | 92 | ||
| 67 | if __name__ == '__main__': | 93 | # if __name__ == '__main__': |
| 68 | # Load JSON data from a file (replace 'your_file.json' with the actual file name) | 94 | # # Load JSON data from a file (replace 'your_file.json' with the actual file name) |
| 69 | with open('response.json', 'r') as file: | 95 | # with open('response.json', 'r') as file: |
| 70 | data = json.load(file) | 96 | # data = json.load(file) |
| 71 | 97 | ||
| 72 | # Define the title to search for | 98 | # # Define the title to search for |
| 73 | search_title = 'The Quintessential Quintuplets 2' # Replace with the actual title you're searching for | 99 | # search_title = 'Fullmetal Alchemist: Brotherhood' # Replace with the actual title you're searching for |
| 74 | 100 | ||
| 75 | # Search for the anime and get its ID | 101 | # # Search for the anime and get its ID |
| 76 | anime_id = search_anime_by_title(data, search_title) | 102 | # anime_id = search_anime_by_title(data, search_title) |
| 77 | 103 | ||
| 78 | # Print the result | 104 | # # Print the result |
| 79 | if anime_id: | 105 | # if anime_id: |
| 80 | print(f"Anime ID: {anime_id}") | 106 | # print(f"Anime ID: {anime_id}") |
| 81 | else: | 107 | # else: |
| 82 | print("Anime not found.") | 108 | # print("Anime not found.") |
curd.py +41 −15
| @@ -3,37 +3,63 @@ | |||
| 3 | # anime_id -> episode_list.sh | 3 | # anime_id -> episode_list.sh |
| 4 | # episode_number -> episdoe_url.sh -> tmp/links | 4 | # episode_number -> episdoe_url.sh -> tmp/links |
| 5 | 5 | ||
| 6 | import re | ||
| 6 | import os | 7 | import os |
| 7 | # from select_anime import main as select | 8 | import json |
| 9 | from anilist import search_anime_by_title | ||
| 8 | 10 | ||
| 9 | with open("scripts/tmp/query", "w") as file: | 11 | with open("scripts/tmp/query", "w") as file: |
| 10 | file.write(input("Enter the anime you want:\n")) | 12 | file.write(input("Enter the anime you want:\n")) |
| 11 | 13 | ||
| 12 | os.system("./scripts/anime_list.sh") | 14 | os.system("./scripts/anime_list.sh") |
| 13 | 15 | ||
| 14 | # with open("scripts/tmp/anime_list", "r") as anime_list: | ||
| 15 | # anime_id = str(anime_list.read()).split()[0] | ||
| 16 | |||
| 17 | import select_anime | 16 | import select_anime |
| 17 | |||
| 18 | with open("scripts/tmp/anime", "r") as anime: | ||
| 19 | anime_name = anime.read() | ||
| 20 | |||
| 21 | with open('response.json', 'r') as file: | ||
| 22 | data = json.load(file) | ||
| 23 | |||
| 24 | # Remove everything from the last '(' including the parentheses | ||
| 25 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() | ||
| 26 | |||
| 18 | # try: | 27 | # try: |
| 19 | # curses.wrapper(select) | 28 | result = search_anime_by_title(data, cleaned_text)[0] |
| 29 | print(result) | ||
| 30 | anime_id = result['id'] | ||
| 31 | progress = int(result['progress']) | ||
| 32 | title = result['english_title'] | ||
| 20 | # except: | 33 | # except: |
| 21 | # pass | 34 | # print("fucked up") |
| 35 | # anime_id = 98460 | ||
| 22 | 36 | ||
| 23 | # with open("scripts/tmp/id", "w") as id: | ||
| 24 | # id.write(anime_id) | ||
| 25 | 37 | ||
| 26 | os.system("./scripts/episode_list.sh") | 38 | os.system("./scripts/episode_list.sh") |
| 27 | 39 | ||
| 28 | with open("scripts/tmp/episode_list") as ep_list: | 40 | # with open("scripts/tmp/episode_list") as ep_list: |
| 29 | temp = ep_list.read() | 41 | # temp = ep_list.read() |
| 30 | temp = temp.split() | 42 | # temp = temp.split() |
| 31 | last_episode = temp[-1] | 43 | # last_episode = temp[-1] |
| 32 | ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") | 44 | # ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") |
| 45 | |||
| 46 | os.system("./scripts/episode_url.sh") | ||
| 47 | |||
| 48 | |||
| 49 | # Define the title to search for | ||
| 50 | # search_title = '' # Replace with the actual title you're searching for | ||
| 33 | 51 | ||
| 34 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | 52 | with open("scripts/tmp/ep_no", "w") as ep_no_file: |
| 35 | # ep_no.write("1") | 53 | # ep_no.write("1") |
| 36 | ep_no_file.write(ep_no) | 54 | # ep_no_file.write(ep_no) |
| 55 | ep_no_file.write(str(progress)) | ||
| 56 | |||
| 57 | # Search for the anime and get its ID | ||
| 58 | |||
| 59 | # Print the result | ||
| 60 | if anime_id: | ||
| 61 | print(f"Anime ID: {anime_id}") | ||
| 62 | else: | ||
| 63 | print("Anime not found.") | ||
| 37 | 64 | ||
| 38 | os.system("./scripts/episode_url.sh") | ||
| 39 | 65 | ||
requirements added +1
| @@ -0,0 +1 @@ | |||
| 1 | requests | ||
select_anime.py +3
| @@ -108,6 +108,9 @@ def main(stdscr): | |||
| 108 | 108 | ||
| 109 | # Print selected anime and its ID after exiting curses mode | 109 | # Print selected anime and its ID after exiting curses mode |
| 110 | print(f"Selected Anime: {selected_anime}, ID: {selected_id}") | 110 | print(f"Selected Anime: {selected_anime}, ID: {selected_id}") |
| 111 | with open("scripts/tmp/anime", "w") as anime_name: | ||
| 112 | anime_name.write(selected_anime) | ||
| 113 | |||
| 111 | with open("scripts/tmp/id", "w") as id: | 114 | with open("scripts/tmp/id", "w") as id: |
| 112 | id.write(selected_id) | 115 | id.write(selected_id) |
| 113 | 116 | ||
select_link.py added +68
| @@ -0,0 +1,68 @@ | |||
| 1 | import curses | ||
| 2 | import re | ||
| 3 | |||
| 4 | def load_links(filename): | ||
| 5 | links = [] | ||
| 6 | with open(filename, 'r') as file: | ||
| 7 | content = file.read() | ||
| 8 | # Regex to match the name and URL pairs | ||
| 9 | matches = re.findall(r'(\S+)\s*>\s*(https?://\S+)', content) | ||
| 10 | links = [(name, url) for name, url in matches] | ||
| 11 | return links | ||
| 12 | |||
| 13 | def display_links(stdscr, links): | ||
| 14 | curses.curs_set(0) # Hide the cursor | ||
| 15 | stdscr.clear() | ||
| 16 | h, w = stdscr.getmaxyx() | ||
| 17 | max_height = h - 1 | ||
| 18 | start = 0 | ||
| 19 | selected_index = 0 | ||
| 20 | |||
| 21 | while True: | ||
| 22 | stdscr.clear() | ||
| 23 | for i in range(start, min(start + max_height, len(links))): | ||
| 24 | if i == selected_index: | ||
| 25 | stdscr.attron(curses.A_REVERSE) # Highlight the selected item | ||
| 26 | stdscr.addstr(i - start, 0, links[i][0]) | ||
| 27 | if i == selected_index: | ||
| 28 | stdscr.attroff(curses.A_REVERSE) # Remove highlight after the line | ||
| 29 | stdscr.addstr(max_height, 0, "Use arrow keys to scroll, Enter to select, q to quit") | ||
| 30 | stdscr.refresh() | ||
| 31 | |||
| 32 | key = stdscr.getch() | ||
| 33 | |||
| 34 | if key == curses.KEY_DOWN: | ||
| 35 | if selected_index < len(links) - 1: | ||
| 36 | selected_index += 1 | ||
| 37 | if selected_index >= start + max_height: | ||
| 38 | start += 1 | ||
| 39 | elif key == curses.KEY_UP: | ||
| 40 | if selected_index > 0: | ||
| 41 | selected_index -= 1 | ||
| 42 | if selected_index < start: | ||
| 43 | start -= 1 | ||
| 44 | elif key == curses.KEY_ENTER or key == 10: # Enter key | ||
| 45 | stdscr.clear() | ||
| 46 | stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}") | ||
| 47 | # print("done") | ||
| 48 | with open("scripts/tmp/link", "w") as temp: | ||
| 49 | temp.write(links[selected_index][1]) | ||
| 50 | stdscr.refresh() | ||
| 51 | # stdscr.getch() # Wait for any key press to exit | ||
| 52 | return links[selected_index][1] | ||
| 53 | break | ||
| 54 | elif key == ord('q'): | ||
| 55 | break | ||
| 56 | |||
| 57 | def main(stdscr): | ||
| 58 | filename = 'scripts/tmp/links' # Replace with your file name | ||
| 59 | links = load_links(filename) | ||
| 60 | print("printed", display_links(stdscr, links)) | ||
| 61 | print("done") | ||
| 62 | |||
| 63 | # print(display_links(stdscr,links)) | ||
| 64 | # if __name__ == "__main__": | ||
| 65 | try: | ||
| 66 | curses.wrapper(main) | ||
| 67 | except: | ||
| 68 | pass\ No newline at end of file | ||
start_video.py added +50
| @@ -0,0 +1,50 @@ | |||
| 1 | import os | ||
| 2 | import json | ||
| 3 | import socket | ||
| 4 | |||
| 5 | os.system("mpv --input-ipc-server=/tmp/mpvsocket 'https://video.wixstatic.com/video/53f59c_bddcaac9d0b940c8b0238a429a47177e/1080p/mp4/file.mp4'") | ||
| 6 | # Path to the MPV socket | ||
| 7 | socket_path = '/tmp/mpvsocket' | ||
| 8 | |||
| 9 | # Connect to the MPV IPC socket | ||
| 10 | client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 11 | client.connect(socket_path) | ||
| 12 | |||
| 13 | def send_command(command): | ||
| 14 | """Send a command to MPV and return the response.""" | ||
| 15 | client.send((json.dumps(command) + '\n').encode('utf-8')) | ||
| 16 | response = client.recv(1024) | ||
| 17 | return json.loads(response.decode('utf-8')) | ||
| 18 | |||
| 19 | def get_time_pos(): | ||
| 20 | """Get the current playback time position.""" | ||
| 21 | command = {"command": ["get_property", "time-pos"]} | ||
| 22 | response = send_command(command) | ||
| 23 | return response.get('data', 0) | ||
| 24 | |||
| 25 | def pause(): | ||
| 26 | """Pause the playback.""" | ||
| 27 | command = {"command": ["set_property", "pause", True]} | ||
| 28 | send_command(command) | ||
| 29 | |||
| 30 | def play(): | ||
| 31 | """Resume the playback.""" | ||
| 32 | command = {"command": ["set_property", "pause", False]} | ||
| 33 | send_command(command) | ||
| 34 | |||
| 35 | def stop(): | ||
| 36 | """Stop the playback.""" | ||
| 37 | command = {"command": ["quit"]} | ||
| 38 | send_command(command) | ||
| 39 | |||
| 40 | try: | ||
| 41 | while True: | ||
| 42 | time_pos = get_time_pos() | ||
| 43 | print(f"Current Time: {time_pos:.2f} seconds") | ||
| 44 | # Add any control commands here, for example, to pause or resume | ||
| 45 | # pause() or play() or stop() | ||
| 46 | time.sleep(1) | ||
| 47 | except KeyboardInterrupt: | ||
| 48 | stop() | ||
| 49 | finally: | ||
| 50 | client.close() | ||