Beispiel #1
0
    async def wrapped(self, *args, **kwargs):
        try:
            return await func(self, *args, **kwargs)
        except AuthenticationRequiredError as ex:
            logger.warning(f"Trying to use unauth access: {ex}")
            add_message(self.request, "LogIn to continue.")
            redirect(self.request, "sign_in")

        except BaseApplicationError as ex:
            message = getattr(ex, "message", None) or str(ex)
            details = getattr(ex, "details", None)
            if details:
                message = f"{message}: {details}"

            add_message(self.request, message, kind="error")
            raise web.HTTPFound(self.request.path)
Beispiel #2
0
 async def get(self):
     podcast: Podcast = await self._get_object()
     episodes = await podcast.get_episodes_async(self.request.app.objects,
                                                 self.user.id)
     await self._delete_files(podcast, episodes)
     await self.request.app.objects.delete(podcast, recursive=True)
     add_message(self.request, f'Podcast "{podcast.name}" was deleted')
     return redirect(self.request, "podcast_list")
Beispiel #3
0
 async def post(self):
     podcast = await self._get_object()
     cleaned_data = await self._validate()
     for key, value in cleaned_data.items():
         setattr(podcast, key, value)
     await self.request.app.objects.update(podcast)
     redirect_url = self.request.headers.get("Referer") or self.request.path
     return redirect(self.request, "podcast_details", url=redirect_url)
Beispiel #4
0
    async def post(self):
        """ Check email and login """
        cleaned_data = await self._validate()
        email = cleaned_data["email"]
        password = cleaned_data["password"]

        if not email:
            add_message(self.request, "Provide both email and password", kind="warning")
            redirect(self.request, "sign_in")

        try:
            user = await self.authenticate(email, password)
            self._login_and_redirect(user)
        except User.DoesNotExist:
            logger.info("Not found user with email [%s]", email)
            raise AuthenticationFailedError

        redirect(self.request, "sign_in")
Beispiel #5
0
 async def get(self):
     podcast_id = self.request.match_info.get("podcast_id")
     episode: Episode = await self._get_object()
     await self._delete_file(episode)
     await self.request.app.objects.delete(episode, recursive=True)
     await self._generate_rss(podcast_id)
     self.logger.info(f"Episode {episode} successful removed.")
     add_message(
         self.request,
         f"Episode for youtube ID {episode.source_id} was removed.")
     return redirect(self.request, "podcast_details", podcast_id=podcast_id)
Beispiel #6
0
 async def post(self):
     cleaned_data = await self._validate()
     podcast = await self.request.app.objects.create(
         Podcast,
         **dict(
             publish_id=Podcast.generate_publish_id(),
             name=cleaned_data["name"],
             description=cleaned_data.get("description", ""),
             created_by_id=self.user.id,
         ),
     )
     return redirect(self.request, "podcast_details", podcast_id=podcast.id)
Beispiel #7
0
 async def get(self):
     episode: Episode = await self._get_object()
     self.logger.info(f'Start download process for "{episode.watch_url}"')
     add_message(self.request,
                 f"Downloading for youtube {episode.source_id} started.")
     episode.status = Episode.STATUS_DOWNLOADING
     await self.request.app.objects.update(episode)
     await self._enqueue_task(
         tasks.download_episode,
         youtube_link=episode.watch_url,
         episode_id=episode.id,
     )
     return redirect(self.request, "progress")
Beispiel #8
0
    async def post(self):
        podcast_id = self.request.match_info.get("podcast_id")
        episode = await self._get_object()
        cleaned_data = await self._validate()
        for key, value in cleaned_data.items():
            setattr(episode, key, value)

        await self.request.app.objects.update(episode)
        return redirect(
            self.request,
            "episode_details",
            podcast_id=podcast_id,
            episode_id=episode.id,
        )
Beispiel #9
0
 async def wrapped(self, *args, **kwargs):
     if self.request.user is not None:
         add_message(self.request, "Please log-out to continue.")
         redirect(self.request, "index")
     return await func(self, *args, **kwargs)
Beispiel #10
0
 async def wrapped(self, *args, **kwargs):
     if self.request.user is None:
         add_message(self.request, "LogIn to continue.")
         redirect(self.request, "sign_in")
     return await func(self, *args, **kwargs)
Beispiel #11
0
 def _login_and_redirect(self, user, redirect_to="index"):
     self._login(user)
     redirect_to = "default_podcast_details" if is_mobile_app(self.request) else redirect_to
     redirect(self.request, redirect_to)
Beispiel #12
0
 async def get(self):
     self.request.session.pop("user")
     add_message(self.request, "You are logged out")
     redirect(self.request, "index")
Beispiel #13
0
    async def post(self):
        podcast_id = int(self.request.match_info.get("podcast_id"))
        podcast: Podcast = await self._get_object()
        cleaned_data = await self._validate()
        youtube_link = cleaned_data["youtube_link"].strip()

        video_id = get_video_id(youtube_link)
        if not video_id:
            add_message(self.request,
                        f"YouTube link is not correct: {youtube_link}")
            return redirect(self.request,
                            "podcast_details",
                            podcast_id=podcast_id)

        same_episodes: Iterable[
            Episode] = await self.request.app.objects.execute(
                Episode.select().where(Episode.source_id == video_id).order_by(
                    Episode.created_at.desc()))
        episode_in_podcast, last_same_episode = None, None
        for episode in same_episodes:
            last_same_episode = last_same_episode or episode
            if episode.podcast_id == podcast_id:
                episode_in_podcast = episode
                break

        if episode_in_podcast:
            self.logger.info(
                f"Episode for video [{video_id}] already exists for current "
                f"podcast {podcast_id}. Redirecting to {episode_in_podcast}..."
            )
            add_message(self.request, "Episode already exists in podcast.")
            return redirect(
                self.request,
                "episode_details",
                podcast_id=podcast_id,
                episode_id=episode_in_podcast.id,
            )

        try:
            episode_data = await self._get_episode_data(
                same_episode=last_same_episode,
                podcast_id=podcast_id,
                video_id=video_id,
                youtube_link=youtube_link,
            )
        except YoutubeFetchError:
            return redirect(self.request,
                            "podcast_details",
                            podcast_id=podcast_id)

        episode = await self.request.app.objects.create(
            Episode, **episode_data)

        if podcast.download_automatically:
            episode.status = Episode.STATUS_DOWNLOADING
            await self.request.app.objects.update(episode)
            await self._enqueue_task(
                tasks.download_episode,
                youtube_link=episode.watch_url,
                episode_id=episode.id,
            )
            add_message(
                self.request,
                f"Downloading for youtube {episode.source_id} was started.",
            )

        if is_mobile_app(self.request):
            return redirect(self.request, "progress")

        return redirect(
            self.request,
            "episode_details",
            podcast_id=podcast_id,
            episode_id=str(episode.id),
        )
Beispiel #14
0
 async def get(self):
     podcast = await self._get_object()
     await self._generate_rss(podcast.id)
     add_message(self.request,
                 f"RSS for podcast {podcast.name} will be refreshed soon")
     return redirect(self.request, "podcast_details", podcast_id=podcast.id)