Example #1
0
def admin():
    if request.method == "GET":
        if "logged_in" in session:
            videos = Video.objects()
            return render_template("admin.html", videos=videos)
        else:
            return render_template("error.html")
    else:
        form = request.form
        link = form["link"]

        ydl = YoutubeDL()
        data = ydl.extract_info(link, download=False)

        title = data["title"]
        thumbnail = data["thumbnail"]
        views = data["view_count"]
        link = data["webpage_url"]
        youtubeid = data["id"]

        new_video = Video(title=title,
                          thumbnail=thumbnail,
                          views=views,
                          link=link,
                          youtubeid=youtubeid)
        new_video.save()

        return render_template("admin.html")
def admin():
    if "loggedin" in session:
        if request.method == "GET":
            videos = Video.objects()
            return render_template('admin.html', videos=videos)
        elif request.method == "POST":
            form = request.form
            link = form['link']

            ydl = YoutubeDL()
            data = ydl.extract_info(link, download=False)
            title = data['title']
            thumbnail = data['thumbnail']
            views = data['view_count']
            youtubeid = data['id']

            new_video = Video(title=title,
                              thumbnail=thumbnail,
                              views=views,
                              youtubeid=youtubeid,
                              link=link)
            new_video.save()

            return redirect(url_for('admin'))
    else:
        return "Yêu cầu đăng nhập !!!"
Example #3
0
def video():
    if request.method == 'GET':
        videos = Video.objects()
        cardios = Cardio.objects()
        # overweights = Overweight.objects()
        underweights = Underweight.objects()
        yogas= Yoga.objects()
        exercises = Exercise.objects()
        return render_template('admin.html', videos=videos, cardios=cardios, underweights=underweights, yogas=yogas, exercises=exercises )
    elif request.method == 'POST':
        form = request.form
        link = form['link']
        ydl = YoutubeDL()
        data = ydl.extract_info(link, download=False)

        title = data['title']
        thumbnail = data['thumbnail']
        youtube_id = data['id']
        # duration = data['duration']


        new_ex = Exercise(
                title= title,
                link= link,
                thumbnail= thumbnail,
                youtube_id= youtube_id
                # duration= duration
            )

        new_ex.save()
    
        return redirect(url_for('video'))
Example #4
0
def admin():
    if "loggedin" in session:

        if request.method == "GET":
            videos = Video.objects()
            return render_template('admin.html', videos=videos)
        elif request.method == "POST":
            form = request.form
            link = form['link']
            ydl = YoutubeDL()
            data = ydl.extract_info(link, download=False)
            title = data["title"]
            thumbnail = data["thumbnail"]
            views = data["view_count"]
            youtube_id = data["id"]
            new_video = Video(title=title,
                              thumbnail=thumbnail,
                              views=views,
                              link=link,
                              youtube_id=youtube_id)
            new_video.save()

            return redirect(url_for("admin"))
    else:
        return redirect(url_for("login"))
Example #5
0
def getlean(bmi_id):
    if "logged_in" in session:
        # bmi = session['user_bmi']
        body = Body.objects.with_id(bmi_id)
        
        user = User.objects.with_id(session['user_id'])
        # user_id = session['user_id']
        # print(user_id)
        # get_body = Body.objects(user_id = user_id)
        # print(get_body)
        # bmi = Body.objects.order_by('-user_id').first()
        videos = Video.objects()
        cardios = Cardio.objects()
        yogas = Yoga.objects()
        exercises = Exercise.objects()
        underweights = Underweight.objects()
        if body.bmi < 18.5:
            return render_template('underweight.html', full_name = user.fname, user_id = user.id, bmi = body.bmi, videos=videos, cardios=cardios, yogas=yogas, underweights=underweights) 
        elif 18.5 <= body.bmi < 25:
            return render_template('normal.html', full_name = user.fname, user_id = user.id, bmi = body.bmi, videos=videos, cardios=cardios, yogas=yogas, underweights=underweights)
        elif 25 <= body.bmi < 30: 
            return render_template('overweight.html', full_name = user.fname, user_id = user.id, bmi = body.bmi, videos=videos, cardios=cardios, exercises=exercises)
        else:
            return render_template('obese.html', full_name = user.fname, user_id = user.id, bmi = body.bmi, videos=videos, cardios=cardios, exercises=exercises)
    else:
        return render_template(url_for('login'))
Example #6
0
def admin():
    if "loggedin" in session:
        if session['loggedin'] == True:
            if request.method == 'GET':
                videos = Video.objects()
                return render_template('admin.html', videos=videos)
            elif request.method == 'POST':
                form = request.form
                link = form['link']
                ydl = YoutubeDL()

                data = ydl.extract_info(link, download=False)

                title = data['title']
                views = data['view_count']
                thumbnail = data['thumbnail']
                youtube_id = data['id']

                video = Video(title=title,
                              views=views,
                              thumbnail=thumbnail,
                              youtube_id=youtube_id,
                              link=link)

                video.save()

                return redirect(url_for('admin'))
        else:
            return "Đăng nhập chưa mà đòi"
    else:
        return "Đăng nhập chưa mà đòi"
Example #7
0
def admin():
    if "loggedin" in session:
        if request.method =="GET":
            videos = Video.objects()
            print(videos)
            return render_template('admin.html', videos = videos)
        elif request.method =="POST":
            form = request.form
            link = form['link']
            ydl_opts = {
                'nocheckcertificate' : True,
            }
            ydl = YoutubeDL()
            data = ydl.extract_info(link, download = False)
            print(data)
            title = data['title']
            thumbnail = data['thumbnail']
            views = data['view_count']
            youtube_id = data['id']
            uploader = data['uploader']
            new_video = Video(  title = title, 
                                thumbnail = thumbnail, 
                                views = views, 
                                link = link, 
                                youtube_id = youtube_id, 
                                uploader = uploader)
            new_video.save()
            return redirect(url_for('admin'))
    else:
        return "Yêu cầu đăng nhập"
Example #8
0
def admin():
    if request.method == 'GET':
        if 'logged_in' in session:
            videos = Video.objects()
            return render_template('admin.html', videos=videos)
        else:
            return render_template('error.html')

    elif request.method == 'POST':
        form = request.form
        link = form['link']
        ydl = YoutubeDL()
        data = ydl.extract_info(link, download=False)
        title = data['title']
        thumbnail = data['thumbnail']
        views = data['view_count']
        link = data['webpage_url']
        youtubeid = data['id']

        new_video = Video(title=title,
                          thumbnail=thumbnail,
                          views=views,
                          link=link,
                          youtubeid=youtubeid)
        new_video.save()
        return redirect(url_for('admin'))
Example #9
0
def bmi():
    if request.method == "GET":
        if 'user_name' not in session:
            return redirect(url_for('login'))
        else:
            return render_template('check.html', full_name = session['user_name'])
    elif request.method == "POST":
        form = request.form
        weight = form['weight']
        height = form['height']
        time = datetime.datetime.now
        bmi = int(weight) / (int(height) ** 2) *10000
        if bmi < 18.5:
            bmi_type = "underweight"
        elif 18.5 <= bmi < 25:
            bmi_type = "normal"
        elif 25 <= bmi < 30:
            bmi_type = "overweight"
        else:
            bmi_type = "obese"

        if "logged_in" in session:
            # session['user_bmi'] = bmi
            user_id = session['user_id']
            new_body = Body(
                time = time,
                weight = weight,
                height = height,
                bmi = bmi,
                bmi_type = bmi_type
            )
            new_body.save()
            new_body.reload()
            # videos = Video.objects()
            # cardios = Cardio.objects()

            current_user = User.objects.with_id(user_id)
            # current_user.update(add_to_set__bmi_id = str(new_body.id))
            # print(new_body)
            # print(current_user)
            current_user.update(push__bmi_id = new_body)
            # return render_template ('individual.html', all_body = current_user.bmi_id, full_name = session['user_name'], user_id = session['user_id'])
            # return "sadasd"
            return redirect(url_for('individual'))
        else:
            videos = Video.objects()
            cardios = Cardio.objects()
            underweights = Underweight.objects()
            yogas = Yoga.objects()
            exercises = Exercise.objects()
            # overweights = Overweight.objects()
            if bmi < 18.5:
                return render_template('underweight.html', bmi = bmi, yogas=yogas, underweights=underweights, full_name = session['user_name']) 
            elif 18.5 <= bmi < 25:
                return render_template('normal.html', bmi = bmi, videos=videos, yogas=yogas, underweights=underweights, full_name = session['user_name'])
            elif 25 <= bmi < 30:
                return render_template('overweight.html', bmi = bmi, videos=videos, cardios=cardios, exercises=exercises,full_name = session['user_name'])
            elif bmi > 30:
                return render_template('obese.html', bmi = bmi, videos=videos, cardios=cardios, exercises=exercises)
Example #10
0
def history():
    if "loggedin" in session:
        if session['loggedin'] == True:
            all_video = Video.objects()
            return render_template('history.html', all_video=all_video)
        else:
            return redirect(url_for('login'))
    else:
        return redirect(url_for('login'))
Example #11
0
def video():
    user = session.get('username')
    allWordSave = Reviews.objects()
    numberOfWords = 0
    for i in allWordSave:
        if i.username == user:
            numberOfWords += 1
    videos = Video.objects()
    return render_template("videos.html",
                           videos=videos,
                           user=user,
                           numberOfWords=numberOfWords)
Example #12
0
def download_audio(youtube_id):
    # Count
    all_video=[]
    now = datetime.now()
    count_video = Video.objects()
    for video in count_video:
        if video['time'].day == now.day:
            all_video.append(video)
    
    found_count = Count.objects()
    if (len(found_count) > 0) and (found_count[len(found_count)-1]['time'].day == now.day) and (found_count[len(found_count)-1]['time'].month == now.month) and (found_count[len(found_count)-1]['time'].year == now.year):
        number = len(all_video)
        found_count[len(found_count)-1].update(set__amount=number)
    else:
        new_count = Count(
            amount = 1,
            time = now
        )
        new_count.save()
    
    # Download
    found_video = Video.objects.with_id(youtube_id)
    if found_video is not None:
        # Download
        options = {
        'format': 'bestaudio/audio',
        'outtmpl': '%(id)s'
        }

        dl = youtube_dl.YoutubeDL(options)
        result = dl.extract_info(
        found_video.link,
        download = True
        )

        # Send File
        save_file = found_video.title.replace(" ", "")
        save_file = re.sub('[^A-Za-z0-9]+', '', save_file)
        os.rename(result['id'], save_file + '.mp3')
        try:
            # Set Download Type
            found_video.update(set__download_type="Audio")
            found_video.update(set__time=datetime.now())

            return send_file(save_file + '.mp3', save_file + '.mp3', as_attachment=True)
        except Exception as e:
            return str(e)

        # Delete Video from Database
        # found_video.delete()
    else:
        return 'Video is not found'
Example #13
0
def admin():
    user = session.get('username')
    if user is None:
        return redirect(url_for('login'))
    else:
        total_vegetablesAndFruits = Vegetablesfruits.objects()
        total_animals = Animals.objects()
        total_food = Food.objects()
        total_actions = Actions.objects()
        x = len(total_vegetablesAndFruits)
        y = len(total_animals)
        z = len(total_food)
        if request.method == 'GET':
            videos = Video.objects()
            return render_template(
                "admin.html",
                total_vegetablesAndFruits=total_vegetablesAndFruits,
                total_animals=total_animals,
                total_food=total_food,
                total_actions=total_actions,
                x=x,
                y=y,
                z=z,
                videos=videos)
        elif request.method == 'POST':
            form = request.form
            link = form['link']

            ydl = YoutubeDL()

            data = ydl.extract_info(link, download=False)

            title = data['title']
            thumbnail = data['thumbnail']
            views = data['view_count']
            youtube_id = data['id']
            link = link
            video = Video(
                title=title,
                thumbnail=thumbnail,
                views=views,
                youtube_id=youtube_id,
                link=link,
            )
            video.save()
            return redirect(url_for('admin'))
Example #14
0
def index():
    videos = Video.objects()
    return render_template('index.html', videos = videos)
Example #15
0
def update_video(comment_payload: CommentType, video_id: str, request: Request,
                 response: Response, action: str):

    user = auth_module.get_me(request=request)

    if user is None:
        response.status_code = status.HTTP_401_UNAUTHORIZED
        return util_module.generate_response_context(status=403,
                                                     error='access denied!',
                                                     data=None)

    # Update video
    if action == 'update':
        return {"msg": "update video!"}

    # Trash video
    if action == 'trash':

        # Perform clean delete
        Video.objects(pk=video_id).update(set__status="deleted")

        return {"msg": "trashed"}

    if action == 'upvote':

        # Push user to upvotes arrat
        Video.objects(pk=video_id).update(
            add_to_set__upvotes=[user.get("_id")],
            pull__downvotes=user.get("_id"))

        return {"msg": "upvoting video"}

    if action == 'downvote':

        # Push user to downvotes array
        Video.objects(pk=video_id).update(
            add_to_set__downvotes=[user.get("_id")],
            pull__upvotes=user.get("_id"),
        )

        return {"msg": "downvote video"}

    if action == 'comment':

        # Initialize comment
        comment = Comment()
        comment.video = video_id
        comment.comment = comment_payload.comment

        # Initialize author
        author = CommentAuthor()
        author.name = user.get("name")
        author.surname = user.get("surname")
        author.user = user.get("_id")

        # Append author and save
        comment.author = author
        comment.save()

        return {"msg": "comment added!"}

    # Provide action
    return {"msg": "updating video!"}
Example #16
0
def index():
    all_videos = Video.objects()
    return render_template("index.html", all_videos=all_videos)