Ejemplo n.º 1
0
def create_episode(
    db: Session,
    podcast_id: int,
    title: str,
    subtitle: str,
    summary: str,
    long_summary: str,
    duration: timedelta,
    upload_file: UploadFile,
) -> models.Episode:
    db_episode = models.Episode(
        summary=summary,
        long_summary=long_summary,
        title=title,
        subtitle=subtitle,
        url="",
        size=0,
        duration=duration,
        podcast_id=podcast_id,
    )
    db.add(db_episode)
    db.commit()
    db.refresh(db_episode)

    filename = upload_file.filename

    upload_dir = Path(UPLOAD_DIR) / f"podcast_{podcast_id}" / f"episode_{db_episode.id}"
    upload_path = upload_dir / filename
    if not upload_dir == upload_path.parent:
        raise HTTPException(status_code=404, detail="Invalid filename")

    try:
        upload_dir.mkdir(parents=True, exist_ok=True)
        with upload_path.open("wb") as buffer:
            shutil.copyfileobj(upload_file.file, buffer)
    except OSError as e:
        db.delete(db_episode)
        upload_file.file.close()
        logging.exception("Unable to store upload to disk. %s", e)
        raise HTTPException(500, "Unable to store upload to disk. " + str(e))
    finally:
        upload_file.file.close()

    db_episode.url = "%s/download/podcast_%d/episode_%d/%s" % (
        PUBLIC_URL,
        podcast_id,
        db_episode.id,
        quote(filename),
    )
    db_episode.size = os.path.getsize(str(upload_path))
    db.commit()
    db.refresh(db_episode)

    return db_episode
    def __init__(self, anime_url: str):
        """
        Constructor for AnimeScraper.
        Scrapes some information about anime, which is used later for further
        scraping and downloading.

        :param anime_url: Anime URL
        """
        # Soup object for scraping
        anime_soup = BeautifulSoup(
            requests.get(anime_url, headers=settings.REQUEST_HEADERS).text,
            "html.parser",
        )

        # GET request parameters for ajax URL
        id_ = anime_soup.find(id="movie_id")["value"]
        alias = anime_soup.find(id="alias_anime")["value"]
        last_ep = anime_soup.find(
            id="episode_page").find_all("a")[-1]["ep_end"]

        # We collect the list of all episodes and their links using this URL
        ajax_url = (
            "https://ajax.gogocdn.net/ajax/load-list-episode?ep_start=0&default_ep=0"
            f"&ep_end={last_ep}&id={id_}&alias={alias}")

        # Remove bad characters from anime title
        t = anime_soup.title.text.replace("at Gogoanime",
                                          "").replace("Watch ", "").strip()
        t = re.sub('[<>?":/|]', "", t)
        # Model object for anime. Episodes will be scraped and added to it
        self.anime = mdl.Anime(title=t, url=anime_url, episodes=[])

        ajax_soup = BeautifulSoup(
            requests.get(ajax_url, headers=settings.REQUEST_HEADERS).text,
            "html.parser",
        )

        # Collect information of all episodes for further scraping later
        for li in reversed(ajax_soup.find_all("li")):
            # Remove bad characters from scarped episode title
            ep_title = re.sub('[<>?":/|]', "", " ".join(li.text.split()))

            # Episode model object. Video data attribute will be set after scraping
            # the specified range of episodes.
            ep = mdl.Episode(title=f"{self.anime.title} - {ep_title}",
                             url="https://www.gogoanime.so{}".format(
                                 li.find("a")["href"].strip()))

            # Append to list of episodes in anime model object
            self.anime.episodes.append(ep)
Ejemplo n.º 3
0
def test_episode_insert(db):
    test_episode = {
        "name": "TestEpisode",
        "season": "3",
        "nr": "1002",
        "predecessor": "TestPrevEp",
        "successor": "TestNextEp",
        "imageLink": "-"
    }

    ep = models.Episode(**test_episode)
    db.session.add(ep)
    result = db.session.query(
        models.Episode).filter(models.Episode.name == "TestEpisode").first()

    TESTOR.assertEqual(result.season, "3")
    TESTOR.assertEqual(result.nr, "1002")
    TESTOR.assertEqual(result.predecessor, "TestPrevEp")
    TESTOR.assertEqual(result.successor, "TestNextEp")
Ejemplo n.º 4
0
def select_episodes():
	conn = None
	rows = None
	episodes = []
	try:
		conn = db.connect()
		cur = conn.cursor()
		cur.execute(SQL_SELECT_EPISODE_RECORDS)
		rows = cur.fetchall()
		cur.close()
	except (Exception, psycopg2.DatabaseError) as error:
		print(error)
		traceback.print_exc()
		# likely a duplicate?
	finally:
		if conn is not None:
			conn.close()
	for row in rows:
		episodes.append(models.Episode(row))
	return episodes
        soup = BeautifulSoup(response.text, "html.parser")

        text = [
            str(script) for script in soup.find_all("script")
            if ").innerHTML" in str(script)
        ][0]
        text = "".join(text.rstrip("</script>").lstrip("<script>").split())
        text = text.split("innerHTML=")[1].rstrip(";")
        text = "".join(
            [substr.strip('"').strip("'") for substr in text.split("+")])

        download_link = f"https:{text}"
    except Exception as e:
        print(e)
        return None

    return download_link


if __name__ == "__main__":
    # Example: https://streamtape.com/e/YqKyKxg23jivJDB/world-trigger-2nd-season-episode-10.mp4
    epis = mdl.Episode(title="Test title",
                       url="Test URL",
                       video_data={
                           "embed-servers": {
                               "streamtape":
                               input("Enter streamtape embed URL: ")
                           }
                       })
    print(get_download_link(epis))
Ejemplo n.º 6
0
            if re.match("s\d+$", s) or re.match("www\d+$", s)
        ]
        w3str = "www"
        if len(w3str_possibles_list) != 0:
            w3str = max(w3str_possibles_list, key=len)

        download_link = "https://{}.mp4upload.com:{}/d/{}/video.mp4".format(
            w3str, eval_items[eval_items.index(video_id) + 1], video_id)
    except Exception as e:
        print(e)
        return None

    return download_link


# A sample Mp4Upload embedded URL: https://www.mp4upload.com/embed-99r0hr81zk9k.html
if __name__ == "__main__":
    print("\t\t=====================")
    print("\t\t Mp4Upload Generator")
    print("\t\t=====================")
    epis = mdl.Episode(title="Test title",
                       url="Test URL",
                       video_data={
                           "embed-servers": {
                               "mp4upload":
                               input("\t- Enter Mp4Upload Embed URL: ")
                           }
                       })
    d = get_download_link(epis)
    print(f"- The generated download link: {d}")
    :param ep: Episode model object
    :return: Download link of video
    """
    embed_url = ep.video_data.get("vidcdn")
    if not embed_url:
        return None

    try:
        soup = BeautifulSoup(
            requests.get(embed_url, headers=settings.REQUEST_HEADERS).text,
            "html.parser")
        js_text = str(soup.find("div", class_="videocontent"))
        download_link = re.findall("file: '(.+?)'", js_text)[0]
    except Exception as e:
        print(e)
        return None

    return download_link


# Example: https://vidstreaming.io/load.php?id=OTc2MzI=&title=Boruto%3A+Naruto+Next+Generations+Episode+1
if __name__ == "__main__":
    epis = mdl.Episode(title="Test title",
                       url="Test URL",
                       video_data={
                           "embed-servers": {
                               "vidcdn": input("Enter vidcdn embed URL: ")
                           }
                       })
    print(get_download_link(epis))
        response = requests.get(embed_url, headers=settings.REQUEST_HEADERS)

        # Return None if video server is not available
        if "tb error" in response.text:
            return None

        video_details = re.findall("MDCore\|\|.+\|poster",
                                   response.text)[0].split("|")
        # Example:
        # //s-delivery14.mxdcontent.net/v/59f0fcbf63176bff9792eb2b2c5218dd.mp4?
        # s=dZk3d430Oi1bSCD5HfvMbA&e=1616377672&_t=1616359487
        download_link = "https://{2}-{3}.{6}.{7}/v/{4}.{5}?{2}={9}&e={17}&{16}={18}".format(
            *video_details)
    except Exception as e:
        print(e)
        return None

    return download_link


if __name__ == "__main__":
    # Example: https://mixdrop.co/e/7rgov1qpuk4rq7
    epis = mdl.Episode(title="Test episode",
                       url="Test URL",
                       video_data={
                           "embed-servers": {
                               "mixdrop": input("Enter mixdrop embed URL: ")
                           }
                       })
    print(get_download_link(epis))