Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON::ParserError unexpected token with playlist #41

Open
benphelps opened this issue Jun 25, 2016 · 4 comments
Open

JSON::ParserError unexpected token with playlist #41

benphelps opened this issue Jun 25, 2016 · 4 comments
Assignees
Milestone

Comments

@benphelps
Copy link

benphelps commented Jun 25, 2016

An error when trying to get information for a playlist:

dl = YoutubeDL::Video.new "https://www.youtube.com/watch?v=aqz-KE-bpKQ&list=PLiYYIXHYUrMI6mMJADvK2FeoSgK3HuZ49"
dl.information
# JSON::ParserError: 784: unexpected token at '{"upload_date": "20150810" ...

I'm using the latest version of the gem, here are the contents of my Gemfile:

source 'https://rubygems.org'

# Rails Stuff
gem 'rails', '4.2.6'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'

gem 'sidekiq'
gem 'sidekiq-status'
gem 'youtube-dl.rb'
gem 'awesome_print'

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'pry-rails'
end

Ruby version ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

@sapslaj sapslaj added the bug label Jun 26, 2016
@sapslaj
Copy link
Member

sapslaj commented Jun 26, 2016

Thanks for reporting this, Ben. I'm looking into it and I'll keep you updated.

@benphelps
Copy link
Author

So trying to dig further into this I've found that youtube-dl returns multiple json strings for each video in a playlist, separated by a new line, this of course breaks the JSON parsing.

@benphelps
Copy link
Author

benphelps commented Jun 26, 2016

Maybe this will help, this is a bit of code I used to pull out the individual media URLs from the JSON response from youtube-dl.

def extract_playlist_sources(json)
  sources = json.split("\n").collect { |json|
    JSON.parse(json)
  }.collect { |source|
    source["webpage_url"]
  }
end

This wouldn't be an easy fix I don't think, it'd require adding support for playlists.

@sapslaj
Copy link
Member

sapslaj commented Jun 26, 2016

Thanks for the help, that really narrowed down the problem. Right now I'm thinking about either forcing #information to return an Array or figuring out if the URL is a playlist and then returning an Array. It also isn't really cool that the JSON from youtube-dl isn't valid JSON, so I'll probably make an issue upstream for that.

I've made a branch and a WIP PR to track development on this.

EDIT: This is definitely going to bring breaking API changes so I'm going to add this to the 0.4.0 milestone.

@sapslaj sapslaj added this to the 0.4.0 milestone Jun 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants