Python youtube_dl instantly deletes file right after downloading it - youtube-dl

I made this script, and for the most part, it works. However, once it downloads to the /Downloads folder, it instantly deletes it, stating, for example: "[ffmpeg] Destination: C:\Users\bertr\Downloads\Sanford Clark - It's Nothing To Me.mp3
Deleting original file C:\Users\bertr\Downloads\Sanford Clark - It's Nothing To Me.webm (pass -k to keep)"
Is there anything I can do to prevent it from deleting it?
print("hi")
link = linkhere.get()
print(link)
user = getpass.getuser()
params = {
'format': 'bestaudio/best',
'outtmpl': 'C:/Users/{}/Downloads/%(title)s.%(ext)s'.format(user),
'postprocessors':[{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
youtube = yt.YoutubeDL(params)
youtube.download([link])
print('downloaded file')```

You are just downloading a mp3 file so video will not be kept. However you can add 'keepvideo': True to params. So, video will not be deleted.
params = {
'format': 'bestaudio/best',
'outtmpl': 'C:/Users/{}/Downloads/%(title)s.%(ext)s'.format(user),
'keepvideo': True,
'postprocessors':[{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}

Related

How to delete multiple key from digitalocean space object storage?

I am trying to delete multiple object once by using delete_objects. But i am getting an error. I didn’t found any solution regarding to this issue.
client = boto3.client("s3", **config)
response = client.delete_objects(
Bucket=BUCKET,
Delete={
'Objects': [
{
'Key': 'asdasd1.png',
},
{
'Key': 'asdasd1.png',
}
]
},
RequestPayer='requester'
)
I get an error like this:
An error occurred (NotImplemented) when calling the DeleteObjects operation: Unknown
INFO: 127.0.0.1:46958 - "DELETE /image/ HTTP/1.1" 500 Internal Server Error
maybe this can help you, it's another way to do it
def cleanup_from_s3(bucket, remote_path):
s3_contents = list_s3(bucket, remote_path)
if s3_contents == []:
return
for s3_content in s3_contents:
filename = s3_content["Key"]
s3_client.delete_object(Bucket=bucket, Key="{0}/{1}".format(remote_path, filename))

How to export html report from newman

I am using newman via node. Here is the code I'm running:
//File is named newmanRunner.js
const fs = require('fs'),
newman = require('newman');
let rawdata = fs.readFileSync('collections/optionsFile.json');
let optionsJson = JSON.parse(rawdata);
console.log(optionsJson);
newman.run(optionsJson, function(err){
if(err){console.log("Error in collection run: " , err)};
console.log('Collection run complete');
});
Here is the json file with the runtime options:
{
"collection": "collections/my_collection.json",
"data": "data/datafiles/someData.json",
"environment": "data/environments/testEnvironment.json",
"globals": "data/global/globalVars.json",
"iterationCount": 1,
"reporters": "html",
"reporter-html-export": "reports/report.html"
}
I run the collection by the following command:
node newmanRunner.js
The problem I run into is that the html report is generated in a directory titled 'newman' which is in the same directory from which I'm running. I'd like the file to saved to the 'reports' directory. Can anyone point out what I'm doing wrong here? I'm having a hard time finding any documentation on how to include the runtime options in a json file that can be loaded at runtime.
node: 6.11.2
newman: 3.8.3
os: macOS 10.13.3
As is usual I found the needed documentation shortly after posting the question. Anyway, posting here to hopefully help someone in the future.
Newman Run Events
Look at the options.reporters and options.reporter sections. They aren't super intuitive so here is my json file working as expected:
{
"collection": "collections/my_collection.json",
"data": "data/datafiles/someData.json",
"environment": "data/environments/testEnvironment.json",
"globals": "data/global/globalVars.json",
"iterationCount": 1,
"reporters": "html",
"reporter": { "html": {"export": "reports/report.html"} }
}

Use Sublime3 SFTP on EC2

I am trying to edit file in EC2 remotely, I spend a while to setup the config.json but I still got timeout error.
I am using mac and I already chmod 400 to .pem file
{
"type": "sftp",
"sync_down_on_open": true,
"host": "xxx.xx.xx.xxx",
"user": "ubuntu",
"remote_path": "/home/ubuntu/",
"connect_timeout": 30,
"sftp_flags": ["-o IdentityFile=/Users/kevinzhang/Desktop/zhang435_ec2.pem"],
}
I figure it out, Just in case anyone also have the same problem
I am use MAC OS
installed ubuntu
the config file is have is looks like
{
// The tab key will cycle through the settings when first created
// Visit http://wbond.net/sublime_packages/sftp/settings for help
// sftp, ftp or ftps
"type": "sftp",
// "save_before_upload": true,
"upload_on_save": true,
"sync_down_on_open": true,
"sync_skip_deletes": false,
"sync_same_age": true,
"confirm_downloads": false,
"confirm_sync": true,
"confirm_overwrite_newer": false,
"host": "xxxx.compute.amazonaws.com",
"user": "ubuntu",
//"password": "password",
"port": "22",
"remote_path": "/home/ubuntu/",
"ignore_regexes": [
"\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
"sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
"\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini"
],
//"file_permissions": "664",
//"dir_permissions": "775",
//"extra_list_connections": 0,
"connect_timeout": 30,
//"keepalive": 120,
//"ftp_passive_mode": true,
//"ftp_obey_passive_host": false,
"ssh_key_file": "~/.ssh/id_rsa",
"sftp_flags": ["-o IdentityFile=<YOUR.PEM FILE path>"],
//"preserve_modification_times": false,
//"remote_time_offset_in_hours": 0,
//"remote_encoding": "utf-8",
//"remote_locale": "C",
//"allow_config_upload": false,
}
If you have permission problem :
chmod -R 0777 /home/ubuntu/YOURFILE/
this just enable read and write for all user
You may want to create a new user if above not working for you:
https://habd.as/sftp-to-ubuntu-server-sublime-text/
I do not know if this makes different , But looks like it start working for me for both user once Icreate a new user

how to set directory in ydl_opts in using youtube-dl in python?

**
What do i need to add to specify that all the download mp3 will go to this directory: e:/python/downloadedsongs
ydl_opts = {
'format': 'bestaudio/best',
'download_archive': 'downloaded_songs.txt',
'outtmpl': '%(title)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
if i understand it correctly outtmpl is for the template of the name of output file.
**
outtmpl can contain directory names, simply set
'outtmpl': 'e:/python/downloadedsongs/%(title)s.%(ext)s',

Apache Drill: Not able to query the database

I am using UBUNTU 14.04.
I have started to explore about querying HDFS using apache drill, installed it my local system and configured the Storage plugin to point remote HDFS. Below is the configuration setup:
{
"type": "file",
"enabled": true,
"connection": "hdfs://devlpmnt.mycrop.kom:8020",
"workspaces": {
"root": {
"location": "/",
"writable": false,
"defaultInputFormat": null
}
},
"formats": {
"json": {
"type": "json"
}
}
}
After creating a json file "rest.json", I passed the query:
select * from hdfs.`/tmp/rest.json` limit 1
I am getting following error:
org.apache.drill.common.exceptions.UserRemoteException: PARSE ERROR: From line 1, column 15 to line 1, column 18: Table 'hdfs./tmp/rest.json' not found
I would appreciate if someone tries to help me figure out what is wrong.
Thanks in advance!!