YoutubeApi / app.py
moazzamdev's picture
Update app.py
0c4bdd3 verified
# import streamlit as st
# import requests
# from ytmusicapi import YTMusic
# ytmusic = YTMusic()
# # Function to fetch search results from the API
# def fetch_search_results(query):
# results = ytmusic.search(query)
# return results
# # Main Streamlit app
# def main():
# st.title("YouTube Music Search")
# # Search bar
# search_query = st.text_input("Enter your search query:", "")
# # Button to trigger search
# if st.button("Search"):
# if search_query:
# # Fetch search results
# results = fetch_search_results(search_query)
# if results:
# st.write("Search Results:")
# for result in results:
# st.write(result)
# else:
# st.error("Failed to fetch search results. Please try again later.")
# else:
# st.warning("Please enter a search query.")
# if __name__ == "__main__":
# main()
from flask import Flask, request, jsonify
from ytmusicapi import YTMusic
import streamlit as st
app = Flask(__name__)
ytmusic = YTMusic()
@app.route("/search/")
def search():
query = request.args.get('query')
search_results = ytmusic.search(query)
return jsonify(search_results)