Skip to content

Instantly share code, notes, and snippets.

@okiwan
Created May 20, 2022 11:53
Show Gist options
  • Save okiwan/5b4fd0c37cddfcb94a07c06e09eeaff2 to your computer and use it in GitHub Desktop.
Save okiwan/5b4fd0c37cddfcb94a07c06e09eeaff2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
detected_season = None
detected_chapter = None
current_season = None
current_chapter = None
chapter_list = {}
def handle_starttag(self, tag, attrs):
if tag == 'h3':
self.detected_season = tag
if self.current_season and tag == 'tr':
self.detected_chapter = tag
self.current_chapter = []
def handle_endtag(self, tag):
self.detected_season = None
if tag == 'tr':
#print(f"TR: {' '.join(self.current_chapter)}")
temp_chapter = ' '.join(self.current_chapter)
title_index = temp_chapter.find('España : «') + 11
title_end = temp_chapter.find('»', title_index)
title = temp_chapter[title_index:title_end]
if temp_chapter[0] != "#":
self.chapter_list[self.current_season].append(title)
self.detected_chapter = None
self.current_chapter = None
def handle_data(self, data):
if self.detected_season == 'h3' and 'City Hunter' in data:
self.current_season = data
self.chapter_list[self.current_season] = []
if self.current_season and self.detected_chapter and 'th' not in data:
self.current_chapter.append(data)
handler = open("./source.html", "r")
data = handler.read()
parser = MyHTMLParser()
parser.feed(data)
print()
file_chapter_idx = 52
chapter_idx = 0
for idx, chapter in enumerate(parser.chapter_list["City Hunter 2"]):
#print(f"~/Downloads/City Hunter/Temporada 1/City Hunter - t02e{chapter_idx:02d} - {chapter}")
if os.path.exists(f"/Users/Sergio/Downloads/City Hunter/Temporada 2/CH 0{file_chapter_idx} [www.animemf.net] Seba_767.mp4"):
os.rename(f"/Users/Sergio/Downloads/City Hunter/Temporada 2/CH 0{file_chapter_idx} [www.animemf.net] Seba_767.mp4",
f"/Users/Sergio/Downloads/City Hunter/Temporada 2/City Hunter - t02e{chapter_idx:02d} - {chapter}.mp4")
file_chapter_idx = file_chapter_idx + 1
chapter_idx = chapter_idx + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment