Beispiel #1
0
def profile():
    try:
        profile_pics = save_img(request.files['picture'])
        current_user.profile = profile_pics
        db.session.commit()
    except:
        pass
    name = current_user.name
    email = current_user.email
    dob = current_user.dob
    try:
        image_file = url_for('static',
                             filename='movies/' + current_user.profile)
    except:
        pass
    friends = Friend.query.filter_by(get=current_user).filter(
        Friend.u_friend != 'null').all()
    total = len(friends)

    return jsonify({
        "name": name,
        'email': email,
        "dob": dob,
        #'image': image_file,
        'friends': total
    })
Beispiel #2
0
def upload_episode(series_name, season_id):
    series_ = Series.query.filter_by(name=series_name).first()
    s_season= Series_Season.query.filter_by(season=series_).filter_by(season_id=season_id).first()
    form= Episode()
    if form.validate_on_submit():
        episode_number = int(form.name.data)
        id = ''
        name = str(series_.name)
        search = ia.search_movie(name)
        for i in range(0, 1):
            # getting the id
            id = search[i].movieID
        # getting information
        series = ia.get_movie(id)
        ia.update(series, 'episodes')
        episodes = series.data['episodes']
        for episode_list in episodes:
            if episode_number in episodes[episode_list]:
                episode__ = Series_Episodes(episodes=s_season)
                episode__.episode_name =  episodes[episode_list]['name']
                episode__.movies= save_img(form.movie.data)
                episode__.movie_data = (request.files['movie']).read()
                db.session.add(episode__)
                db.session.commit()

    return jsonify({

        'message': 'Added'
    })
Beispiel #3
0
def profile():
    try:
        # changing profile name
        data = request.get_json()
        if data:
            name = Users.query.filter_by(name=data['name']).first()
            if name and name != current_user:
                return jsonify({
                    "message":
                    "This name is already used by another user",
                })
            elif current_user.name == data['name']:
                return jsonify({
                    "message": "You are currently using this name",
                })

            else:
                current_user.name = data['name']
                db.session.commit()
        # uploading photo
        try:
            profile_pics = save_img(request.files['picture'])
            current_user.profile = profile_pics
            db.session.commit()
            user_photo = str(profile_pics).partition('.')
            if user_photo[-1] == 'jpg' or user_photo[-1] == 'png':
                Cloud.uploader.upload(
                    f"{os.path.join(os.path.abspath('Api/static/movies/'), profile_pics)}",
                    chunk_size=6000000,
                    public_id=current_user.name,
                    overwrite=True,
                    eager=[{
                        "width": 300,
                        "height": 300,
                        "crop": "pad",
                        "audio_codec": "none"
                    }, {
                        "width": 160,
                        "height": 100,
                        "crop": "crop",
                        "gravity": "south",
                        "audio_codec": "none"
                    }],
                    eager_async=True,
                    notification_url=
                    "https://mysite.example.com/notify_endpoint",
                    resource_type="image")
                return jsonify({"message": 'Uploaded'})
            else:

                return jsonify({"message": 'Only image extensions allowed'})
        except:
            pass
    except:
        pass
    name = current_user.name
    email = current_user.email
    dob = current_user.dob
    friends = Friend.query.filter_by(get=current_user).filter(
        Friend.u_friend != 'null').all()
    total = len(friends)

    return jsonify({
        "name": name,
        'email': email,
        "dob": dob,
        # 'image' : getting cloudinary link / current user's name,
        'friends': total
    })
Beispiel #4
0
def upload_movie():
    # data = request.get_json()
    form = Movies_()
    id = ''
    if form.validate_on_submit():
        name = str(form.name.data)
        search = ia.search_movie(name)
        for i in range(0, 1):
            # getting the id
            id = search[i].movieID
        movie = requests.get(
            f"https://api.themoviedb.org/3/movie/tt{id}?api_key=03fe919b123d0ced4b33dd633638527a&language=en-US"
        )
        CONFIG_PATTERN = 'http://api.themoviedb.org/3/configuration?api_key={key}'
        KEY = '03fe919b123d0ced4b33dd633638527a'

        url = CONFIG_PATTERN.format(key=KEY)
        r = requests.get(url)
        config = r.json()
        base_url = config['images']['base_url']
        sizes = config['images']['poster_sizes']

        def size_str_to_int(x):
            return float("inf") if x == 'original' else int(x[1:])

        filename = ''
        max_size = max(sizes, key=size_str_to_int)

        IMG_PATTERN = 'http://api.themoviedb.org/3/movie/{imdbid}/images?api_key={key}'
        r = requests.get(IMG_PATTERN.format(key=KEY, imdbid=f'tt{id}'))
        api_response = r.json()

        posters = api_response['posters']
        poster_urls = []
        for poster in posters:
            rel_path = poster['file_path']
            url = "{0}{1}{2}".format(base_url, max_size, rel_path)
            poster_urls.append(url)
        for nr, url in enumerate(poster_urls):
            r = requests.get(url)
            filetype = r.headers['content-type'].split('/')[-1]
            filename = 'poster_{0}.{1}'.format(nr + 1, filetype)
        with open(os.path.join(os.path.abspath('Api/static/movies/'), filename), 'wb') as w:
            w.write(r.content)
        movie_detail = movie.text
        dict_movie = json.loads(movie_detail)
        movie_name = save_img(form.movie.data)
        video_file = request.files['movie']
        credit = requests.get(f"https://api.themoviedb.org/3/movie/tt{id}/credits?api_key={KEY}&language=en-US")
        casts = credit.text
        lists = []
        json_casts = json.loads(casts)
        cast = json_casts['cast']
        for i in cast:
            lists.append(i['original_name'])

        description = str(dict_movie['overview'])
        review = str(dict_movie["vote_average"])
        movies = Movie()
        movies.public_id = str(uuid.uuid4())
        movies.name = str(dict_movie['original_title'])
        movies.description = description
        movies.review = review
        genres = dict_movie['genres']
        movies.cast1 = lists[0]
        movies.cast2 = lists[1]
        movies.cast3 = lists[2]
        movies.cast4 = lists[3]
        genre = []
        company = dict_movie['production_companies']
        com = []
        for i in company:
            com.append(i['name'])
        for i in genres:
            genre.append(i['name'])
        movies.genre = genre[0]
        movies.creator = com[0]
        movies.created_on = str(dict_movie['release_date'])
        movies.runtime = str(dict_movie['runtime'])
        movies.poster = filename
        movies.movies = movie_name

        Cloud.uploader.upload(f"{os.path.join(os.path.abspath('Api/static/movies/'), filename)}",
                              chunk_size=6000000,
                              public_id=str(dict_movie['original_title']),
                              overwrite=True,
                              eager=[
                                  {"width": 300, "height": 300, "crop": "pad", "audio_codec": "none"},
                                  {"width": 160, "height": 100, "crop": "crop", "gravity": "south",
                                   "audio_codec": "none"}],
                              eager_async=True,
                              notification_url="https://mysite.example.com/notify_endpoint",
                              resource_type="image")


        Cloud.uploader.upload(f"{os.path.join(os.path.abspath('Api/static/movies/'), movie_name)}",
                              chunk_size=6000000,
                              public_id=str(dict_movie['original_title']),
                              overwrite=True,
                              eager=[
                                  {"width": 300, "height": 300, "crop": "pad", "audio_codec": "none"},
                                  {"width": 160, "height": 100, "crop": "crop", "gravity": "south",
                                   "audio_codec": "none"}],
                              eager_async=True,
                              notification_url="https://mysite.example.com/notify_endpoint",
                              resource_type="video")

        movies.movie_data = video_file.read(CHUNK_SIZE)
        db.session.add(movies)
        db.session.commit()
    c = ''
    try:
        c = Movie.query.all()
    except:
        pass
    return render_template('_.html', form=form, c=c)
Beispiel #5
0
def profile():
    try:
        profile_pics = save_img(request.files['picture'])
        user_photo = str(profile_pics).partition('.')
        if user_photo[-1] == 'jpg':
            Cloud.uploader.upload(
                f"{os.path.join(os.path.abspath('Api/static/movies/'), profile_pics)}",
                chunk_size=6000000,
                public_id=current_user.name,
                overwrite=True,
                eager=[{
                    "width": 300,
                    "height": 300,
                    "crop": "pad",
                    "audio_codec": "none"
                }, {
                    "width": 160,
                    "height": 100,
                    "crop": "crop",
                    "gravity": "south",
                    "audio_codec": "none"
                }],
                eager_async=True,
                notification_url="https://mysite.example.com/notify_endpoint",
                resource_type="image")
        else:
            Cloud.uploader.upload(
                f"{os.path.join(os.path.abspath('Api/static/movies/'), profile_pics)}",
                chunk_size=6000000,
                public_id=current_user.name,
                overwrite=True,
                eager=[{
                    "width": 300,
                    "height": 300,
                    "crop": "pad",
                    "audio_codec": "none"
                }, {
                    "width": 160,
                    "height": 100,
                    "crop": "crop",
                    "gravity": "south",
                    "audio_codec": "none"
                }],
                eager_async=True,
                notification_url="https://mysite.example.com/notify_endpoint",
                resource_type="video")
        current_user.profile = profile_pics
        db.session.commit()
    except:
        pass
    name = current_user.name
    email = current_user.email
    dob = current_user.dob
    friends = Friend.query.filter_by(get=current_user).filter(
        Friend.u_friend != 'null').all()
    total = len(friends)

    return jsonify({
        "name": name,
        'email': email,
        "dob": dob,
        # 'image' : getting cloudinary link / current user's name,
        'friends': total
    })