コード例 #1
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def orderuser(user_name):

    try:
        # Getting my username
        my_username = db.getLogin()

        # Getting my user id
        my_id = db.getUserId(my_username)

        # Getting user id to search
        users_id = db.getUserId(user_name)

        #Getting vote information
        votes = db.getAllVotes()

        # Getting videos ordered by user name
        ordered = db.orderByUser(users_id, my_id)

        return render_template('videos.html',
                               videos=ordered,
                               username=my_username,
                               votes=votes,
                               userid=my_id,
                               get_votes=db.calcVotes,
                               check_voted=db.checkVote)

    except:
        return redirect('/')
コード例 #2
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def ordercategory(category_name):

    # Not my videos or profile page
    profile = False

    try:
        # Getting user name
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting categories by name and ordering
        category_id = db.getCategoryIdByName(category_name)

        # Getting vote information
        votes = db.getAllVotes()

        # Getting video list ordered by category name
        ordered = db.orderByCategory(category_id, userid, profile)

        return render_template('videos.html',
                               videos=ordered,
                               username=user_name,
                               votes=votes,
                               userid=userid,
                               get_votes=db.calcVotes,
                               check_voted=db.checkVote)

    except:
        return redirect('/')
コード例 #3
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def orderprofilecategory(category_name):

    # My videos and profile
    profile = True

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting category by category name and ordering
        category_id = db.getCategoryIdByName(category_name)

        # Getting vote information
        votes = db.getAllVotes()

        # Getting profile video list ordered by category name
        ordered = db.orderByCategory(category_id, userid, profile)

        return render_template('dashboard.html',
                               videos=ordered,
                               username=user_name,
                               votes=votes,
                               get_votes=db.calcVotes)

    except:
        return redirect('/')
コード例 #4
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def videos():

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting original videos created by other users
        videos = db.getOtherVideos(userid)

        # Getting the vote information
        votes = db.getAllVotes()

        return render_template('videos.html',
                               videos=videos,
                               username=user_name,
                               votes=votes,
                               userid=userid,
                               get_votes=db.calcVotes,
                               check_voted=db.checkVote)

    except:
        return redirect('/')
コード例 #5
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def repost(videoid):

    # Video's original creator
    origin = "false"

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Get playlist by id
        video = db.getVideoById(videoid)

        # Setting variables with copied video data
        title = video['title']
        description = video['description']
        img_source = video['img_source']
        video_source = video['video_source']
        category_id = video['category_id']

        # Adding video to database
        db.addVideo(userid, title, description, img_source, video_source,
                    category_id, origin)

        return redirect('/{}'.format(user_name))

    except:
        return redirect('/')
コード例 #6
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def downvote(videoid):

    # Set vote value
    vote = -1

    # Calculating the votes for video
    total_votes = db.calcVotes(videoid)

    if total_votes == None:
        total_votes = 0

    # This deletes a video if it has a total score of -5
    if total_votes > -4:
        try:
            # Getting username
            user_name = db.getLogin()

            # Getting user id
            userid = db.getUserId(user_name)

            # Make vote
            db.vote(videoid, userid, vote)
            return redirect('/videos')

        except:
            redirect('/')

    else:
        db.delete(videoid)
        return redirect('/videos')
コード例 #7
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def edit(videoid):

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting categories list
        categories = db.getCategories()

        # Getting playlists by id
        video = db.getVideoById(videoid)

        # Checks to make sure video belongs to the user editing the video.
        if int(userid) == int(video['user_id']):
            return render_template('edit-video.html',
                                   video=video,
                                   categories=categories)

        else:
            return redirect('/profile')

    except:
        return redirect('/')
コード例 #8
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def dashboard(username):

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting list of my videos
        videos = db.getMyVideos(userid)

        # If user has no videos redirect to welcome screen
        if not videos:
            return redirect('/welcome')

        # Getting the vote information
        votes = db.getAllVotes()

        return render_template('dashboard.html',
                               username=username,
                               videos=videos,
                               votes=votes,
                               get_votes=db.calcVotes)

    except:
        return redirect('/')
コード例 #9
0
ファイル: api.py プロジェクト: rita-amante/projects-ect
    def index(self, sample_upload, nome):
        user = "******"

        size = 0
        data = b""
        h = MD5.new()

        # Robustez
        try:
            tipo = sample_upload.filename.split(".")
            tipo = tipo[len(tipo) - 1]
        except Exception:
            print("FILE_ERROR")
            raise cherrypy.HTTPRedirect("/samples")

        if str.lower(tipo) == "wav":
            while True:
                block = sample_upload.file.read(4096)
                if not block:
                    break
                data = data + block
                h.update(block)
                size += len(block)

            name = h.hexdigest()
            name = name[0:16]
            file = os.path.join(PATH + "/samples/" + name + ".wav")
            with open(file, 'wb') as fout:
                fout.write(data)

            # Se o ficheiro é Stereo
            if (wave.open(file, "rb").getnchannels() == 2):
                # Passar de Stereo para Mono usando comando bash e ffmpeg
                subprocess.Popen("ffmpeg -i " + file + " -map_channel 0.0.0 " +
                                 file + " -y",
                                 shell=True,
                                 stdout=subprocess.PIPE)

            uid = db.getUserId(user)
            db.setSample(
                json.dumps({
                    "authorid": str(uid),
                    "samplehid": name,
                    "name": nome,
                    "path": "samples/" + name + ".wav"
                }))

        else:
            print("FILE_ERROR")

        raise cherrypy.HTTPRedirect("/samples")
コード例 #10
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def upvote(videoid):

    # Set vote value
    vote = 1

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Make vote
        db.vote(videoid, userid, vote)

        return redirect('/videos')

    except:
        redirect('/')
コード例 #11
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def newplaylist():

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting list of categories
        categories = db.getCategories()

        return render_template('new-video.html',
                               user_name=user_name,
                               userid=userid,
                               categories=categories)

    except:
        return redirect('/')
コード例 #12
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def check():

    if request.method == 'POST':
        form = request.form
        username = form['username']
        password = form['password']

        # Authenticating the user
        try:
            result = db.authenticate(username, password)

            if result:
                user = str(result[0])
                if username == user:

                    # Setting Username
                    db.setLogin(username)

                    # Getting User ID
                    userid = db.getUserId(username)

                    # Checking if user has any videos
                    videos = db.getMyVideos(userid)

                    if videos:
                        return redirect('/videos')

                    else:
                        return redirect('/welcome')

            else:
                message = {
                    "message_type": "error",
                    "message_info": "Invalid Login Details!"
                }

                return render_template('login.html', message=message)

        except:
            return redirect('/')

    return render_template('login.html')
コード例 #13
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def ordersaved(status):

    try:
        # Getting username
        user_name = db.getLogin()

        # Getting user id
        userid = db.getUserId(user_name)

        # Getting vote information
        votes = db.getAllVotes()

        # Getting profile video list ordered by original and reposted
        ordered = db.orderBySaved(userid, status)

        return render_template('dashboard.html',
                               videos=ordered,
                               username=user_name,
                               votes=votes,
                               get_votes=db.calcVotes)

    except:
        return redirect('/')
コード例 #14
0
ファイル: app.py プロジェクト: raysaini19/vidx-video-sharing
def delete(videoid):

    try:
        # Get username
        user_name = db.getLogin()

        # Getting playlists by id
        video = db.getVideoById(videoid)

        # Getting user id
        userid = db.getUserId(user_name)

        # Checks to make sure video belongs to the user deleting the video via the url.
        if int(userid) == int(video['user_id']):
            # Delete the video
            db.delete(videoid)
            return redirect('/{}'.format(user_name))

        else:
            return redirect('/profile')

    except:
        return redirect('/')
コード例 #15
0
def test_getUserId():
    assert db.getUserId("equipa") != None
    assert db.getUserId("dias.eurico") in [2, "2"]
    assert db.getUserId("qwertyiwantthistofail1234554321") == None
    assert db.getUserId("") == None
コード例 #16
0
 def testE(self):
     result = int(db.getUserId(tests.username))
     self.assertGreater(result, 0)