Git Product home page Git Product logo

youtube-stream-url's Introduction

youtube-stream-url

Get stream url from youtube video in node.js (included Copyright Music Video).

Installation

With npm do:

npm install youtube-stream-url

Usage

const Youtube = require('youtube-stream-url');

Youtube.getInfo({url: 'https://www.youtube.com/watch?v=pJ7WN3yome4'}).then(video => console.log(video));

Full output

{ 
    videoDetails: {
        videoId: 'pJ7WN3yome4',
        title: 'M1 Ultra Mac Studio - Benchmarks & Thermals (The TRUTH!)',
        lengthSeconds: '1165',
        keywords: [
        'mac studio',
        'mac',
        'apple',
        'apple mac',
        'apple mac studio',
        'mac studio benchmarks',
        'mac studio teardown',
        'mac studio perfornance',
        'mac studio vs',
        'm1 ultra',
        'm1 ultra chip',
        'm1 ultra mac studio',
        'm1 ultra vs m1 max',
        'm1 max vs m1 ultra',
        'm1 max vs m1 ultra mac studio',
        'm1 ultra vs m1 max mac studio',
        'mac studio vs macbook pro',
        'mac studio vs imac',
        'mac studio vs mac mini',
        'mac studio thermal throttle test',
        'mac studio benchmarks test',
        'mac studio watt metere',
        'mac studio max tech',
        'mac studio ultra'
        ],
        channelId: 'UCptwuAv0XQHo1OQUSaO6NHw',
        isOwnerViewing: false,
        shortDescription: '...',
        isCrawlable: true,
        thumbnail: { thumbnails: [Array] },
        averageRating: 4.9487238,
        allowRatings: true,
        viewCount: '1124295',
        author: 'Thái Trinh Official',
        isPrivate: false,
        isUnpluggedCorpus: false,
        isLiveContent: false
    },
    formats: [
        {
        url: 'https://r4---sn-8qj-i5ol7.googlevideo.com/videoplayback...',
        type: 'video/mp4; codecs="avc1.64001F, mp4a.40.2"',
        itag: '22',
        quality: 'hd720'
        },
        ...
    ],
    liveData: { //For live video (videoDetails.isLiveContent == true)
        manifestUrl: 'https://manifest.googlevideo.com/...',
        data: {
            segments: [
                {
                    "isMasterPlaylist": true,
                    "streamInf": {
                        "bandwidth": 290288,
                        "codecs": [
                            "mp4a.40.5,avc1.42c00b"
                        ],
                        "resolution": 256,
                        "frameRate": 15,
                        "videoRange": "SDR",
                        "subtitles": "vtt",
                        "closedCaptions": "NONE"
                    },
                    "url": "https://manifest.googlevideo.com/api/manifest/hls_playlist/.../playlist/index.m3u8"
                },
                ...
            ],
            "media": {
                "SUBTITLES": {
                    "vtt": {
                        "en": {
                            "groupId": "vtt",
                            "uri": "https://manifest.googlevideo.com/...",
                            "type": "SUBTITLES",
                            "language": "en",
                            "name": "en",
                            "default": false,
                            "autoselect": "YES"
                        }
                    }
                }
            }
        }
    }
}

For live video, you can get HLS Stream URL via liveData field. liveData.data format is m3u8-file-parser output of manifest file from liveData.manifestUrl.

Handle error

By default, getInfo function return false when an error occurred while process. If you want manualy handle error, you can pass option throwOnError: true

try {
    await Youtube.getInfo({url: '...', throwOnError: true})
} catch (e) {
    //Handle error here
}

Update

Since the youtube-stream-url binary is updated regularly, you can run npm update to check for and download any updates for it.

License

MIT © Dang Dung

youtube-stream-url's People

Contributors

ba11b0y avatar dangdungcntt avatar dependabot[bot] avatar mataniko avatar yomomano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

youtube-stream-url's Issues

Returns false with a valid VID due to response not being in JSON format

Hey I am using your module and it seems that the response string is no longer in JSON but in a different format since the axios call fails inside getInfo with a unexpected token error. The response looks similar to this

"errordetail=0&apiary_host_firstparty=&t=1&itct=CAEQu2kiEwizpfiYhNTcAhXt9OMHHY8uDeAop5UD&no_get_video_log=1&tmi=1&host_language=en&allow_ratings=1&avg_rating=4.84187364578&keywords=world+star+hip+hop%2Cworldstarhiphop%2Cworldstar%2Cworld+star%2Cworldstar+youtube%2Cyoutube+worldstar%2Cworldstarhiphop+youtube%2Cyoutube+worldstarhiphop%2Cworldstarhiphop+channel%2Cwshh%2Chip+hop%2Chip+hop+music%2Crap%2Crap+music%2Cmusic%2Cmusic+video%2Cexclusive%2CWSHH+exclusive%2CLil+Baby%2CLil+Baby+2018%2CLil+Baby+music+video%2CLil+Baby+video%2CLil+Baby+First+Class%2CFirst+Class+Lil+Baby%2CFirst+Class%2CFirst+Class+music+video%2CFirst+Class+video%2Cmusic+video+First+Class&innertube_context_client_version=1.20180801&xhr_apiary_host=youtubei.youtube.com&fexp=23708904%2C23708906%2C23708910%2C23710476%2C23721699%2C23721898%2C23727195%2C23727262%2C23729689%2C23733751%2C23735347%2C23737531%2C23738491%2C23740493%2C23744176%2C23745105%2C23746304%2C23749835%2C23751767%2C23752246%2C23752869%2C23753284%2C23755635%2C23755886%2C9449243%2C9471235%2C9485000&cr=US&root_ve_type=51879&is_listed=1&apiary_host=&status=fail&timestamp=1533407530&player_error_log_fraction=1.0&reason=This+video+is+unavailable.&innertube_api_version=v1&fflags=skip_restore_on_abandon_in_bulleit%3Dtrue%26kevlar_allow_multistep_video_init%3Dtrue%26mweb_bulleit_show_ad_top_bar_for_phones%3Dtrue%26variable_load_timeout_ms%3D0%26html5_disable_audio_slicing%3Dtrue%26html5_min_buffer_to_resume%3D6%26html5_get_video_info_promiseajax%3Dtrue%26html5_jumbo_ull_nonstreaming_mffa_ms%3D4000%26bulleit_get_midroll_info_timeout_ms%3D8000%26html5_max_headm_for_streaming_xhr%3D0%26html5_live_disable_dg_pacing%3Dtrue%26bulleit_use_cue_video_to_reset_on_stop_ad%3Dtrue%26html5_probe_live_using_range%3Dtrue%26use_forced_linebreak_preskip_text%3Dtrue%26show_thumbnail_behind_ypc_offer_module%3Dtrue%26html5_jumbo_mobile_subsegment_readahead_target%3D3.3%26vmap_enabled_living_room%3Dtrue%26youtubei_for_web%3Dtrue%26html5_variability_no_discount_thresh%3D1.0%26html5_qoe_intercept%3D%26html5_jumbo_ull_subsegment_readahead_target%3D1.3%26lightweight_watch_video_swf%3Dtrue%26html5_subsegment_readahead_target_buffer_health_secs%3D0.5%26lasr_captions_holdback_counterfactual_id%3D0%26desktop_shopping_companion_wta_support%3Dtrue%26html5_suspend_loader%3Dtrue%26enable_static_font_size_on_text_only_preview%3Dtrue%26html5_post_interrupt_readahead%3D20%26html5_new_seeking%3Dtrue%26html5_manifestless_accurate_sliceinfo%3Dtrue%26html5_remove_pause%3Dfalse%26dynamic_ad_break_pause_threshold_sec%3D0%26show_countdown_on_bumper%3Dtrue%26html5_manifestless_interpolate%3Dtrue%26web_player_edge_autohide_killswitch2%3Dtrue%26html5_variability_full_discount_thresh%3D3.0%26low_engagement_player_quality_cap%3D360%26html5_incremental_parser_buffer_duration_secs%3D1.5%26html5_fludd_suspend%3Dtrue%26html5_allowable_liveness_drift_chunks%3D2%26html5_subsegment_readahead_require_whitelist%3Dtrue%26html5_vp9_live_blacklist_edge%3Dtrue%26html5_disable_preserve_reference%3Dtrue%26website_actions_throttle_percentage%3D1.0%26html5_pipeline_manifestless%3Dtrue%26html5_min_upgrade_health%3D0%26html5_serverside_call_server_on_biscotti_timeout%3Dtrue%26html5_deadzone_multiplier%3D1.0%26html5_fallbacks_delay_primary_probes%3Dtrue%26html5_tight_max_buffer_allowed_impaired_time%3D0.0%26html5_live_low_latency_bandwidth_window%3D0.0%26call_release_video_in_bulleit%3Dtrue%26bulleit_block_player_pause_until_ad_start%3Dtrue%26html5_streaming_xhr_buffer_mdat%3Dtrue%26html5_use_media_capabilities%3Dtrue%26html5_new_vis_fullscreen_and_airplay%3Dtrue%26enable_dni_lozenge_play_button%3Dtrue%26show_interstitial_white%3Dtrue%26flex_theater_mode%3Dtrue%26html5_incremental_parser_coalesce_slice_buffers%3Dtrue%26html5_disable_non_contiguous%3Dtrue%26delay_bulleit_media_load_timer%3Dtrue%26html5_incremental_parser_buffer_extra_bytes%3D16384%26html5_adaptive_readahead_loading_ratio_samples_minimum_amount%3D50%26html5_log_rebuffer_events%3D0%26stop_using_ima_sdk_gpt_request_activity%3Dtrue%26html5_max_readahead_bandwidth_cap%3D0%26html5_creativeless_vast_on_ima%3Dtrue%26mweb_cougar_big_controls%3Dtrue%26allow_live_autoplay%3Dtrue%26desktop_action_companion_wta_support%3Dtrue%26html5_parse_inline_fallback_host%3Dtrue%26use_new_skip_icon%3Dtrue%26html5_subsegment_readahead_timeout_secs%3D2.0%26use_survey_skip_in_0s%3Dtrue%26html5_minimum_readahead_seconds%3D0.0%26enable_overlays_wta%3Dtrue%26html5_live_4k_more_buffer%3Dtrue%26tvhtml5_min_readbehind_secs%3D20%26html5_widevine_robustness_strings%3Dtrue%26add_border_to_bulleit_mweb_skip%3Dtrue%26bulleit_update_tsla_cookie%3Dtrue%26bulleit_round_up_tsla%3Dtrue%26html5_ignore_bad_bitrates%3Dtrue%26html5_reattach_resource_after_timeout_limit%3D0%26set_interstitial_start_button%3Dtrue%26html5_view_offset%3D0.0%26html5_start_date_from_element%3Dtrue%26html5_max_buffer_duration%3D120%26show_thumbnail_on_standard%3Dtrue%26ad_video_end_renderer_duration_milliseconds%3D7000%26desktop_image_companion_wta_support%3Dtru…BQ3Jtc0tsVWtSMGFwcTVPc2w5VFk4M05vZzRIQ2pMQk9yUHVmb0dvc1J0ZGZoTHdkNC0yQVZaSkl6RGFidjVhTU8wT2lZR0JudjBxdlk3WDJOR0ZnU0NQb01vckNjYWJsT21oQXZQeFhueGgzd2tqWnpMVGhGRQ%3D%3D&title=Lil+Baby+%22First+Class%22+%28WSHH+Exclusive+-+Official+Music+Video%29&hl=en_US&ucid=UC-yXuc1__OzjwpsJPlxYUCQ&player_response=%7B%22playabilityStatus%22%3A%7B%22status%22%3A%22UNPLAYABLE%22%2C%22reason%22%3A%22This+video+is+unavailable.%22%2C%22errorScreen%22%3A%7B%22playerErrorMessageRenderer%22%3A%7B%22reason%22%3A%7B%22simpleText%22%3A%22This+video+is+unavailable.%22%7D%2C%22proceedButton%22%3A%7B%22buttonRenderer%22%3A%7B%22style%22%3A%22STYLE_PRIMARY%22%2C%22size%22%3A%22SIZE_DEFAULT%22%2C%22isDisabled%22%3Afalse%2C%22text%22%3A%7B%22simpleText%22%3A%22Watch+on+YouTube%22%7D%2C%22trackingParams%22%3A%22CAcQ8FsiEwizpfiYhNTcAhXt9OMHHY8uDeAop5UD%22%7D%7D%2C%22thumbnail%22%3A%7B%22thumbnails%22%3A%5B%7B%22url%22%3A%22%2F%2Fs.ytimg.com%2Fyts%2Fimg%2Fmeh7-vflGevej7.png%22%2C%22width%22%3A140%2C%22height%22%3A100%7D%5D%7D%2C%22icon%22%3A%7B%22iconType%22%3A%22ERROR_OUTLINE%22%7D%7D%7D%7D%2C%22videoDetails%22%3A%7B%22thumbnail%22%3A%7B%22thumbnails%22%3A%5B%7B%22url%22%3A%22http%3A%2F%2Fi.ytimg.com%2Fvi%2FZqyxlBKiEIQ%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%5Cu0026rs%3DAOn4CLBVkxPkLpQ-MtKSBPB5zlnvzMLQKQ%22%2C%22width%22%3A168%2C%22height%22%3A94%7D%2C%7B%22url%22%3A%22http%3A%2F%2Fi.ytimg.com%2Fvi%2FZqyxlBKiEIQ%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCMQBEG5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%5Cu0026rs%3DAOn4CLBWlGYjcAsDliFM1zucC5g52nFGBQ%22%2C%22width%22%3A196%2C%22height%22%3A110%7D%2C%7B%22url%22%3A%22http%3A%2F%2Fi.ytimg.com%2Fvi%2FZqyxlBKiEIQ%2Fhqdefault.jpg%3Fsqp%3D-oaymwEXCPYBEIoBSFryq4qpAwkIARUAAIhCGAE%3D%5Cu0026rs%3DAOn4CLCOjvuyKI8fNNprl3Up5t_xBDYk_g%22%2C%22width%22%3A246%2C%22height%22%3A138%7D%2C%7B%22url%22%3A%22http%3A%2F%2Fi.ytimg.com%2Fvi%2FZqyxlBKiEIQ%2Fhqdefault.jpg%3Fsqp%3D-oaymwEXCNACELwBSFryq4qpAwkIARUAAIhCGAE%3D%5Cu0026rs%3DAOn4CLAbe8B0N81_sIXlblbi5tS354SH_A%22%2C%22width%22%3A336%2C%22height%22%3A188%7D%5D%7D%7D%2C%22messages%22%3A%5B%7B%22mealbarPromoRenderer%22%3A%7B%22messageTexts%22%3A%5B%7B%22runs%22%3A%5B%7B%22text%22%3A%22Our+new+desktop+experience+was+built+to+be+your+music+destination.+Listen+to+official+albums+%5Cu0026+more.%22%7D%5D%7D%5D%2C%22actionButton%22%3A%7B%22buttonRenderer%22%3A%7B%22style%22%3A%22STYLE_PRIMARY%22%2C%22size%22%3A%22SIZE_DEFAULT%22%2C%22text%22%3A%7B%22runs%22%3A%5B%7B%22text%22%3A%22Check+it+out%22%7D%5D%7D%2C%22navigationEndpoint%22%3A%7B%22clickTrackingParams%22%3A%22CAYQ7G8iEwizpfiYhNTcAhXt9OMHHY8uDeAop5UD%22%2C%22urlEndpoint%22%3A%7B%22url%22%3A%22https%3A%2F%2Fmusic.youtube.com%22%7D%7D%2C%22trackingParams%22%3A%22CAYQ7G8iEwizpfiYhNTcAhXt9OMHHY8uDeAop5UD%22%7D%7D%2C%22dismissButton%22%3A%7B%22buttonRenderer%22%3A%7B%22style%22%3A%22STYLE_BLUE_TEXT%22%2C%22size%22%3A%22SIZE_DEFAULT%22%2C%22text%22%3A%7B%22runs%22%3A%5B%7B%22text%22%3A%22No+thanks%22%7D%5D%7D%2C%22serviceEndpoint%22%3A%7B%22clickTrackingParams%22%3A%22CAUQ7W8iEwizpfiYhNTcAhXt9OMHHY8uDeAop5UD%22%2C%22feedbackEndpoint%22%3A%7B%22feedbackToken%22%3A%22AB9zfpKm4U8OJO6VOdBz8zNgUypZYBJke4U8_eDkn1u6UoIqYXW_wO21b9aAoFdPwlmrFdhl1dm1iiwZNMXiVDyJ8dZMjFRFRs9QDqseWIt8vzYkm3xUnn8i4MhoMU0n3hlJ-GYiwRG3LrepT6_sq7y_GQu2Z5RORg%22%2C%22uiActions%22%3A%7B%22hideEnclosingContainer%22%3Atrue%7D%7D%7D%2C%22trackingParams%22%3A%22CAUQ7W8iEwizpfiYhNTcAhXt9OMHHY8uDeAop5UD%22%7D%7D%2C%22triggerCondition%22%3A%22TRIGGER_CONDITION_POST_AD%22%2C%22style%22%3A%22STYLE_MESSAGE%22%2C%22trackingParams%22%3A%22CAQQ42kYACITCLOl-JiE1NwCFe304wcdjy4N4CinlQM%3D%22%2C%22impressionEndpoints%22%3A%5B%7B%22clickTrackingParams%22%3A%22CAQQ42kYACITCLOl-JiE1NwCFe304wcdjy4N4CinlQM%3D%22%2C%22feedbackEndpoint%22%3A%7B%22feedbackToken%22%3A%22AB9zfpJ0PxhZP937LTr8nwYryH5jVf_kTcDh03NV2c60ynd6d9YmJwBxC6f28GgY6yXcw4_5Z3qRftw-eaukYJSvT7FVHP48ddtYCAjzpGLO-vzJHrB5GroG92UajeFdbxm5gQDqq0bT8qLk3rkw8SOU4iBx_8Y_mg%22%2C%22uiActions%22%3A%7B%22hideEnclosingContainer%22%3Afalse%7D%7D%7D%5D%2C%22isVisible%22%3Atrue%2C%22messageTitle%22%3A%7B%22runs%22%3A%5B%7B%22text%22%3A%22Where+music+meets+your+desktop%22%7D%5D%7D%7D%7D%5D%2C%22adSafetyReason%22%3A%7B%22isEmbed%22%3Atrue%2C%22isRemarketingEnabled%22%3Atrue%2C%22isFocEnabled%22%3Atrue%7D%7D&enablecsi=1&thumbnail_url=http%3A%2F%2Fi.ytimg.com%2Fvi%2FZqyxlBKiEIQ%2Fdefault.jpg&view_count=15643543&ldpj=-7&fmt_list=&gapi_hint_params=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.gapi.en.yK0z3MKtgaU.O%2Fm%3D__features__%2Frt%3Dj%2Fd%3D1%2Frs%3DAHpOoo-SafOYj4n3budMysbWxppU-lxJeg&author=WORLDSTARHIPHOP&watermark=%2Chttp%3A%2F%2Fs.ytimg.com%2Fyts%2Fimg%2Fwatermark%2Fyoutube_watermark-vflHX6b6E.png%2Chttp%3A%2F%2Fs.ytimg.com%2Fyts%2Fimg%2Fwatermark%2Fyoutube_hd_watermark-vflAzLcD6.png&csn=KfFlW_PsOO3pj-8Pj920gA4&cver=1.20180801&vss_host=s.youtube.com&url_encoded_fmt_stream_map=&errorcode=150&innertube_api_key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&csi_page_type=embed&length_seconds=205&c=WEB&video_id=ZqyxlBKiEIQ&idpj=-7"

is this a valid response string?

Download speed too slow

This tool can download at < ~50 KB/s only
image

However, In the same network condition, other tools such as yt-dlp can be > 10MBps
Pls keep your greats effort to improve your project...

Does not work with music videos.

First of all, your project is amazing and sorry for my english

ok the problem is that when searching for songs it does not bring the formats, I leave an example capture
example

403 Error on nodeJS

Hello .
on node server that running on render.com , i always get 403 no permission error with borken url link to the video, on local everything works fine.
EDIT : On local it works on anything(videoId/songId) , on node only on videoId, any ideas why it cant fetch a url with songId? any help is appreciated !

Error in /src/index.js

node_modules/youtube-stream-url/src/index.js:3
const getInfo = async({url}) => {
^

SyntaxError: Unexpected token (
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/home/shail/projects/music_streamer_js/index.js:1:79)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)

False negative on stream because of 'response.data.indexOf("errorcode") > -1'

Hi, I found that YT video ID 'xFrGuyw1V8s' randomly fails so I debugged a bit and find that the condition 'response.data.indexOf("errorcode") > -1' causes false negatives for this stream: when removing this condition in getInfo(), the stream loads normally always...

As mentioned, the failure seems to happen randomly. No idea why 'errorcode' sometimes occurs and sometimes doesnt. Maybe it's because of ABBA? :)

Please try with YT video ID 'xFrGuyw1V8s'

Thanks

The package no longer works.

Hi, I tried the package recently and found that it no longer works, when I run the code, it returns "false", following is the screenshoot.
image

Video JSON structure always return "false"

When I use this code:

const Youtube = require('youtube-stream-url');

Youtube.getInfo({url: 'https://www.youtube.com/watch?v=pJ7WN3yome4'}).then(video => console.log(video));

it returns

false

instead of JSON, why??

not working in safari

It is not working in safari browser
can you help me out
i have searched it is range issue

CAn you please look at it

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.