Exemplo n.º 1
0
def parse_tvdb(showName = "", useAbsoluteOrdering = False):
    """Parse a tvdb_api call"""
    try:
        import tvdb_api
    except Exception:
        print "Could not import 'tvdb_api' library"
        sys.exit()

    show = Show()
    try:
        show.title = showName
        tvdb = tvdb_api.Tvdb()
        episodes = tvdb[show.title]

        for sIndex in range(len(episodes)):
            for epIndex in range(len(episodes[sIndex])):
                # epIndex + 1 because the range is 0-indexed and the episodes are 1-indexed
                #print(episodes[sIndex][epIndex + 1]['seasonnumber'] + "x" + episodes[sIndex][epIndex + 1]['episodenumber'] + " - " + episodes[sIndex][epIndex + 1]['episodename'])
                if useAbsoluteOrdering == True:
                    show.episodes[(int(episodes[sIndex][epIndex + 1]['seasonnumber']), int(episodes[sIndex][epIndex + 1]['absolute_number']))] = {"title": episodes[sIndex][epIndex + 1]['episodename']}
                else:
                    show.episodes[(int(episodes[sIndex][epIndex + 1]['seasonnumber']), int(episodes[sIndex][epIndex + 1]['episodenumber']))] = {"title": episodes[sIndex][epIndex + 1]['episodename']}
    except Exception as showTitleException:
        print "Exception while finding show title: " + str(showTitleException)
        print "Could not find show title, cannot continue."
        sys.exit()
    return show
Exemplo n.º 2
0
def parse_epguides(showName = ""):
    """Parse an epguides page."""

    site = {"url": ["http://epguides.com/%s/"],
            "domain": "epguides.com",
            "urlparser": "epguides.com\/(.*?)\/",
           }

    page = get_page(site["url"][0] % showName)

    from BeautifulSoup import BeautifulSoup
    soup = BeautifulSoup(page)
    page = unicode(soup).replace("\n", "")
    show = Show()
    try:
        show.title = re.search("""<h1><a href="http://.*?">(.*?)</a></h1>""", page, re.IGNORECASE).groups()[0]
    except AttributeError:
        print "Could not find show title, cannot continue."
        sys.exit()
    episodes = re.findall("\d+. +(?P<season>\d+) *\- *(?P<episode>\d+).*?<a.*?>(?P<name>.*?)</a>", page)
    for season, episode, name in episodes:
        show.episodes[(int(season), int(episode))] = {"title": name}
    return show