Skip to content

Commit

Permalink
Merge branch 'main' into profile_page
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrimadh authored Oct 31, 2024
2 parents f2a7e41 + 472d125 commit bc18ef6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
DuplicateKeyError,
)

from bson import ObjectId
from src.recommenderapp.search import Search
from bson.objectid import ObjectId

from src.recommenderapp.client import client
from src.recommenderapp.utils import (
beautify_feedback_data,
Expand All @@ -31,8 +33,8 @@
get_friends,
get_recent_movies,
get_recent_friend_movies,
fetch_streaming_link,
)
from src.recommenderapp.search import Search

from src.recommenderapp.item_based import (
recommend_for_new_user,
Expand Down Expand Up @@ -120,7 +122,17 @@ def predict():
user_rating, user[1], client
)

resp = {"recommendations": recommendations, "genres": genres, "imdb_id": imdb_id}
web_url = []
for element in imdb_id:
web_url.append(fetch_streaming_link(element))

resp = {
"recommendations": recommendations,
"genres": genres,
"imdb_id": imdb_id,
}

print(resp, end="\n")
return resp


Expand Down
7 changes: 7 additions & 0 deletions src/recommenderapp/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,21 @@ $(document).ready(function () {
var i = 0
var recommendations = response["recommendations"]
var imdbIds = response["imdb_id"]
var webUrls = response["web_url"]
for (var i = 0; i < recommendations.length; i++) {
var element = recommendations[i]
var imdbID = imdbIds[i]
var web_url = webUrls[i]
var diventry = $("<div/>")
var fieldset = $("<fieldset/>", { id: i }).css("border", "0")
var link = $("<a/>")
.text("IMDb🔗")
.css({ "text-decoration": "none" })
.attr("href", "https://www.imdb.com/title/" + imdbID)
var streaming_link = $("<a/>")
.text(" Stream Here!🍿")
.css({ "text-decoration": "none" })
.attr("href", web_url)
var li = $("<li/>").text(element)
var radios = $(`
<table class='table predictTable'>
Expand All @@ -112,6 +118,7 @@ $(document).ready(function () {

diventry.append(li)
diventry.append(link)
diventry.append(streaming_link)
diventry.append(radios)
fieldset.append(diventry)
ulList.append(fieldset)
Expand Down
29 changes: 29 additions & 0 deletions src/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from bson.objectid import ObjectId
import pandas as pd
import os
import requests


def create_colored_tags(genres):
Expand Down Expand Up @@ -471,3 +472,31 @@ def get_user_history(client, user_id):
except PyMongoError as e:
print(f"Database error: {str(e)}")
raise


def fetch_streaming_link(imdb_id):
"""
Fetches the streaming links of movies.
"""
if not imdb_id:
return jsonify({"error": "Please provide imdb_id"}), 400

url = f"https://api.watchmode.com/v1/title/{imdb_id}/sources/"
api_key = "fh04Ehayqo4Rdn7RJ0vaGttCD8QYbmWRgZsB4DYy"

headers = {"Authorization": f"Bearer {api_key}"}

params = {"apiKey": api_key, "regions": "US"}

response = requests.get(url, headers=headers, params=params)

sources = {
item["name"]: {"platform": item["name"], "url": item["web_url"]}
for item in response.json()
}
res = sorted(sources.values(), key=lambda x: x["platform"])

if res: # Check if res is not empty
return res[0]["url"] # Returns the first URL

return None

0 comments on commit bc18ef6

Please sign in to comment.