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

video-ids output format for list cmd #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

itscaro
Copy link
Contributor

@itscaro itscaro commented Apr 21, 2021

Description

Maybe useful to avoid using jq to reformat.

Usage could be:

./youtubedr download $(./youtubedr list <playlistID> --format video-ids)

# or

./youtubedr list <playlistID> --format video-ids | ./youtubedr download

Issues to fix

Please link issues this PR will fix:
#[issue number]

if no relevant issue, but this will fix something important for reference
, please free to open an issue.

Reminding

Something you can do before PR to reduce time to merge

  • run "make build" to build the code
  • run "make format" to reformat the code
  • run "make lint" if you are using unix system
  • run "make test-integration" to pass all tests

plainWriter(w)
writer, ok := writers[outputFormat]
if !ok {
return errUnhandledFormat(outputFormat)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the flag is handled by addFormatFlag which prints 4 formats. For info cmd, this new format is not implemented. Maybe when info cmd accepts multiple URLs we can extract all video IDs the same way as list cmd does in this PR?

./youtubedr-dev info <videoID> --format video-ids
unhandled output format: video-ids
./youtubedr-dev list <playlistID> --format video-ids
JTRqppn4vNo lhbytXY9gEs 7Y7m3uMRNak GjhRMetsok0 fePN2EFK5bU 7sX44EkgTds sAb-ogxZIAI kv-8SeTfT0k CHvhcM_Rvlo -075jrjea4Q ZgHrrkG175M KK58lRTSn5I iIfgwENiL3o VNNXO4DIHUo

@corny
Copy link
Collaborator

corny commented Apr 22, 2021

Which problem does this pull request solve? Do you want to download all videos of a playlist?

@itscaro
Copy link
Contributor Author

itscaro commented Apr 22, 2021

This PR tries to export directly a list of IDs separated by space, which can be piped into other tools. Download a playlist is one of the goals, this can be (and I would like to propose a PR) done in download cmd, if it detects a playlist then it will download all media from playlist.

The format video-ids is intended for a broader usage, maybe someone wants do sth with other tools? This format could be used to extract video id in info cmd too.

Currently I used this command after list cmd is implemented

 youtubedr list <playlistID> --format json | jq '.Videos[].ID' | xargs -r youtubedr download

Feel free to decline the PR @corny

@corny
Copy link
Collaborator

corny commented Apr 23, 2021

What do you think about adding CSV as output format and optionally selecting the columns? If you want all video IDs, you can just select the videoID column and skip the first line (column header).

@itscaro
Copy link
Contributor Author

itscaro commented Apr 23, 2021

Video IDs
<ID1> <ID2>

Like this? nice idea. I'll change the PR this wk.
Do you have an idea how to pass arg to choose column to keep it simple?

@corny
Copy link
Collaborator

corny commented Apr 23, 2021

It's better to have column headers without spaces. Example:

$ youtubedr list --format csv --csv-columns video_id,title <playlistID>
video_id,title
id1,title2
id2,"title with space"

Or just IDs without headers:

$ youtubedr list --format csv --csv-columns video_id, --csv-headers false <playlistID>
id1
id2

Just use NewWriter() from the encoding/csv package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants