Git Product home page Git Product logo

audible-youtube's Introduction

audible-youtube

audible-youtube is a backend service that enables application softwares to convert and download YouTube videos using API endpoints.

The project aims to decouple and eliminate the overhead of converting YouTube videos to audio files from other apps or services.

Supported audio formats:

  • M4A (MPEG 4 Audio)

Try it here: https://audible-youtube.herokuapp.com/docs

TODO:

  • Support MP3 format
  • Implement webhook for slow option

Technologies

Please refer to the dependencies section in the pyproject.toml file.

Installation

Fork the audible_youtube repo on GitHub, then clone your fork locally.

Setup

  1. cd into the project directory, e.g. audible-youtube.

  2. Inside the project's root directory, run poetry shell. This will create or start the virtual environment. Make sure poetry is installed.

  3. Run poetry install. This will install the project and its dependencies.

  4. Create a copy of .env.example:

    cp .env.example .env
  5. Run the app: uvicorn app.main:app.

  6. Go to http://127.0.0.1:8000/docs

Usage

Convert and Download Videos

  1. /download (Fast option/Recommended)

    Simply make a GET request to the /download path with your search term in the query parameter.

    /download?query=your+search+term
    
    curl -X 'GET' \
    'http://127.0.0.1:8000/download?query=rick+astley+never+gonna+give+you+up' \
      -H 'accept: application/json' \
      -o 'your_audio_file.m4a'
  2. /convert & /save (Slow option)

    First, make a request to the server to convert the video.

    /convert?query=your+search+term
    
    curl -X 'GET' \
      'http://127.0.0.1:8000/convert?query=rick+astley+never+gonna+give+you+up' \
      -H 'accept: application/json'

    Example JSON response:

    {
      "ticket":"7aa156139564bd03b63178ec2ddffb27",
      "title":"Rick Astley - Never Gonna Give You Up (Official Music Video)",
      "link":"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
      "thumbnails":[
        {
          "url":"https://i.ytimg.com/vi/dQw4w9WgXcQ/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAfut6ib46TKYWnNm5PxBrcX8HLWg",
          "width":"360",
          "height":"202"
        },
        {
          "url":"https://i.ytimg.com/vi/dQw4w9WgXcQ/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDRxusbm2_TGTnDWEIhBTYW2cUQkw",
          "width":"720",
          "height":"404"
        }
      ]
    }

    Then use the value of the ticket key in the JSON response to download your audio file.

    /save?ticket=your+assigned+ticket
    
    curl -X 'GET' \
    'http://127.0.0.1:8000/save?ticket=7aa156139564bd03b63178ec2ddffb27' \
        -H 'accept: application/json' \
        -o 'your_audio_file.m4a'

    Your file is likely not ready if the response or file content looks like this:

    {
      "errors":[
          "7aa156139564bd03b63178ec2ddffb27 is not ready. Please wait and resubmit your request"
      ]
    }

    If you get the above error, try again shortly.

IMPORTANT NOTES:

  • The system rate limits requests to 5 per minute.
  • A file is set expire after 2 minutes or once you finish downloading it.

Check out the client examples.

Search Videos

Simply make a GET request to the /search path and pass the search term as a query string.

/search?query=your+search+term
curl -X 'GET' \
  'http://127.0.0.1:8000/search?query=rick+astley+never+gonna+give+you+up' \
  -H 'accept: application/json'

Example JSON response:

Show Example
{
  "type":"video",
  "id":"dQw4w9WgXcQ",
  "title":"Rick Astley - Never Gonna Give You Up (Official Music Video)",
  "publishedTime":"12 years ago",
  "duration":"3:33",
  "viewCount":{
    "text":"1,226,115,753 views",
    "short":"1.2B views"
  },
  "thumbnails":[
    {
      "url":"https://i.ytimg.com/vi/dQw4w9WgXcQ/hq720.jpg?sqp=-oaymwEcCOgCEMoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAfut6ib46TKYWnNm5PxBrcX8HLWg",
      "width":360,
      "height":202
    },
    {
      "url":"https://i.ytimg.com/vi/dQw4w9WgXcQ/hq720.jpg?sqp=-oaymwEcCNAFEJQDSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLDRxusbm2_TGTnDWEIhBTYW2cUQkw",
      "width":720,
      "height":404
    }
  ],
  "richThumbnail":{
    "url":"https://i.ytimg.com/an_webp/dQw4w9WgXcQ/mqdefault_6s.webp?du=3000&sqp=CPye9pQG&rs=AOn4CLDYr_LyEDlnnOvNJBPXL8lI2JF7jA",
    "width":320,
    "height":180
  },
  "descriptionSnippet":[
    {
      "text":""
    },
    {
      "text":"Never Gonna Give You Up",
      "bold":true
    },
    {
      "text":"” was a global smash on its release in July 1987, topping the charts in 25 countries including Rick's ..."
    }
  ],
  "channel":{
    "name":"Rick Astley",
    "id":"UCuAXFkgsw1L7xaCfnd5JJOw",
    "thumbnails":[
      {
        "url":"https://yt3.ggpht.com/BbWaWU-qyR5nfxxXclxsI8zepppYL5x1agIPGfRdXFm5fPEewDsRRWg4x6P6fdKNhj84GoUpUI4=s88-c-k-c0x00ffffff-no-rj",
        "width":68,
        "height":68
      }
    ],
    "link":"https://www.youtube.com/channel/UCuAXFkgsw1L7xaCfnd5JJOw"
  },
  "accessibility":{
    "title":"Rick Astley - Never Gonna Give You Up (Official Music Video) by Rick Astley 12 years ago 3 minutes, 33 seconds 1,226,115,753 views",
    "duration":"3 minutes, 33 seconds"
  },
  "link":"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "shelfTitle":null
}

Deployment

audible-youtube comes with an app.json file for creating an app on Heroku from a GitHub repository.

If your fork is public, you can use the following button:

Deploy

Otherwise, access the following link and replace $YOUR_REPOSITORY_LINK$ with your repository link:

https://heroku.com/deploy?template=$YOUR_REPOSITORY_LINK$

If you're using a frontend app, remember to fill the ALLOWED_ORIGINS field with the URI/URL of said app, leave it empty otherwise. For multiple origins, use a comma-separated value (e.g. https://app.com,example-app.com:8080,app.host.com)

Contributing

Check the contributing guide to learn more about the development process and how you can test your changes.

Have a question?
Discord: cnif.coffee#5404
E-mail: [email protected]

License

audible-youtube is distributed under the MIT License. See LICENSE for more information.

audible-youtube's People

Contributors

dependabot[bot] avatar huenique avatar

Stargazers

 avatar  avatar

Watchers

 avatar

audible-youtube's Issues

`/download` returns Internal Server Error

Heroku logs:

2022-06-28T11:06:54.245360+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/starlette/routing.py", line 61, in app
2022-06-28T11:06:54.245360+00:00 app[web.1]:     response = await func(request)
2022-06-28T11:06:54.245360+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/fastapi/routing.py", line 226, in app
2022-06-28T11:06:54.245360+00:00 app[web.1]:     raw_response = await run_endpoint_function(
2022-06-28T11:06:54.245360+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/fastapi/routing.py", line 159, in run_endpoint_function
2022-06-28T11:06:54.245360+00:00 app[web.1]:     return await dependant.call(**values)
2022-06-28T11:06:54.245361+00:00 app[web.1]:   File "/app/app/api/endpoints.py", line 73, in download
2022-06-28T11:06:54.245361+00:00 app[web.1]:     result = await _validate_search_result(result["result"])
2022-06-28T11:06:54.245361+00:00 app[web.1]: TypeError: list indices must be integers or slices, not str

Internal server error on `/search?query=test&size=5`

Heroku log:

2022-06-22T14:41:52.036084+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/fastapi/routing.py", line 226, in app
2022-06-22T14:41:52.036084+00:00 app[web.1]:     raw_response = await run_endpoint_function(
2022-06-22T14:41:52.036084+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/fastapi/routing.py", line 159, in run_endpoint_function
2022-06-22T14:41:52.036085+00:00 app[web.1]:     return await dependant.call(**values)
2022-06-22T14:41:52.036085+00:00 app[web.1]:   File "/app/app/api/endpoints.py", line 236, in search
2022-06-22T14:41:52.036085+00:00 app[web.1]:     result = await _extract_video_summary(result)
2022-06-22T14:41:52.036085+00:00 app[web.1]:   File "/app/app/api/endpoints.py", line 52, in _extract_video_summary
2022-06-22T14:41:52.036085+00:00 app[web.1]:     "id": entry["id"],
2022-06-22T14:41:52.036086+00:00 app[web.1]: TypeError: 'NoneType' object is not subscriptable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.