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

Is there a simple way to format upload_date? #12048

Closed
friskyweasel opened this issue Feb 10, 2017 · 2 comments
Closed

Is there a simple way to format upload_date? #12048

friskyweasel opened this issue Feb 10, 2017 · 2 comments

Comments

@friskyweasel
Copy link

@friskyweasel friskyweasel commented Feb 10, 2017

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2017.02.10. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2017.02.10

Before submitting an issue make sure you have:

  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • Bug report (encountered problems with youtube-dl)
  • Site support request (request for adding support for a new site)
  • Feature request (request for a new functionality)
  • Question
  • Other

The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your issue



Hello! Youtube-DL is a fantastic tool - thanks to you all for all of your hard work on this project! My question is about the upload_date filename functionality. Lets say I have a youtube-dl command like this:

youtube-dl -i -o "/videos/%(upload_date)s_%(title)s.%(ext)s" https://www.youtube.com/playlist?list=AnyValidPlaylistCodeHere

It works perfectly, but instead of the first portion of the downloaded file being something like "20170209_", I would like it to be "2017-02-09_". I thought this would be a 5-minute thing, but after reading/searching, I can't see a simple way to do it. I noted someone had requested to convert the %(NAME)s renaming functionality to python string.format {}, but it did not look like his code commits were accepted (they broke other functionality). I also noticed this "Utils.py" file in the main Git archive, but was not sure how to utilize it.

I am running Linux Mint 17.2 with xfce desktop. Would I need to use some sort of external post-processing to reformat the date in my downloaded file names? I was 99% sure there would be some simple way to accomplish it in youtube-dl, but i'm afraid i'm stumped. I would love if someone could give me the "most common / simplest" approach to such a renaming task in linux...the solution doesn't have to necessarily involve using youtube-dl....it's awesome enough as it is! : )

Thanks for any help you can provide...

@cqnkxy
Copy link

@cqnkxy cqnkxy commented Feb 14, 2017

Why not simply write a Python script to do the formatting for you?

If you wanna to modify youtube-dl, I found that upload_date is formatted by calling unified_strdate in utils.py, which will format the date to the form of YYYYMMDD. And the unified_strdate is used solely on upload_date. So it's trivial to change the output of unified_strdate to your desired format, but it will cause problem for the date_from_str function within utils.py, which doesn't take care of your desired date format. We need to add compatibility in the latter function. So if you just wanna the naming conversion, modify the format specifier in unified_strdate, and add a compatible rule in date_from_str, then you are good to go(without caring for test cases for unified_strdate).

@friskyweasel
Copy link
Author

@friskyweasel friskyweasel commented Feb 14, 2017

thanks cqnkxy - this is exactly what i was looking for - i ended up using a little bash script to do it (im a noob to bash)...but your excellent youtube-dl specific input will give me some new areas to explore - thanks for your help!

in case any other noobs want the steps i used to modify the date:
#problem: i was prefixing my files with the youtube-dl upload date, but for plex, i needed the dates in yyyy-mm-dd format rather than yyyymmdd format

#steps taken inside my bash script:
#when calling youtube-dl, i used the -o operator to prefix file name with upload_date:
#-o "/path/to/your/download/directory/%(upload_date)s_%(title)s.%(ext)s"

#once youtube-dl was finished, used this little fix_dates function to loop through the downloaded files and manually add the "-" to create yyyy-mm-dd format

fix_dates() {
cd $1

for file in *
do
#if 5th char is a -, we assume we have already modified its date
if [ ${file:4:1} = "-" ]; then
echo date already formatted
else
echo date NOT already formatted - fixing it now
mv "$file" "${file:0:4}-${file:4:2}-${file:6}"
fi
done
}

#call function
fix_dates "/path/to/your/download/directory"

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.