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

Headphones will stop re-importing same release #2674

Closed
spuniun opened this issue Jun 13, 2016 · 4 comments
Closed

Headphones will stop re-importing same release #2674

spuniun opened this issue Jun 13, 2016 · 4 comments

Comments

@spuniun
Copy link

spuniun commented Jun 13, 2016

I've noticed that when headphones encounters releases with non-standard ASCII characters it does not know that the download was successfully imported and reattempts the import indefinitely until the source folder is removed from the download client.

For example, I'm currently dealing with Justin Timberlake - CAN'T STOP THE FEELING! (Original Song From DreamWorks Animation's ''Trolls'') (2016) - 320-WEB being reimported from rtorrent over and over and over:
Jun 11 19:52 Can’t Stop the Feeling! (2016) Jun 11 19:57 Can’t Stop the Feeling! (2016)[1] Jun 11 20:42 Can’t Stop the Feeling! (2016)[10] Jun 12 04:12 Can’t Stop the Feeling! (2016)[100] Jun 12 04:17 Can’t Stop the Feeling! (2016)[101] Jun 12 04:22 Can’t Stop the Feeling! (2016)[102] Jun 12 04:27 Can’t Stop the Feeling! (2016)[103] Jun 12 04:32 Can’t Stop the Feeling! (2016)[104] Jun 12 04:37 Can’t Stop the Feeling! (2016)[105] Jun 12 04:42 Can’t Stop the Feeling! (2016)[106] Jun 12 04:47 Can’t Stop the Feeling! (2016)[107] Jun 12 04:52 Can’t Stop the Feeling! (2016)[108] Jun 12 04:57 Can’t Stop the Feeling! (2016)[109] Jun 11 20:47 Can’t Stop the Feeling! (2016)[11] Jun 12 05:02 Can’t Stop the Feeling! (2016)[110] Jun 12 05:07 Can’t Stop the Feeling! (2016)[111] Jun 12 05:12 Can’t Stop the Feeling! (2016)[112] Jun 12 05:17 Can’t Stop the Feeling! (2016)[113] Jun 12 05:22 Can’t Stop the Feeling! (2016)[114] Jun 12 05:27 Can’t Stop the Feeling! (2016)[115] Jun 12 05:32 Can’t Stop the Feeling! (2016)[116] Jun 12 05:37 Can’t Stop the Feeling! (2016)[117] Jun 12 05:42 Can’t Stop the Feeling! (2016)[118] Jun 12 05:47 Can’t Stop the Feeling! (2016)[119]
This is a single with 1 song and clearly is completing the import within a few seconds so the 5min interval is not the cause. I have marked the release as downloaded and ignored and even paused the artist but headphones keeps picking it up from torrent download directory. I've observed this same behavior with other albums that have non-standard ASCII characters such as this:

2016-06-12 23:12:23 WARNING Error moving file 01 Justin Timberlake - Can’t Stop the Feeling! (original song from Dreamworks Animation’s “Trolls”).mp3: [Errno 1] Operation not permitted: '/home/plex/local-sorted/Music/Justin Timberlake/Can\xe2\x80\x99t Stop the Feeling! (2016)/01 Justin Timberlake - Can\xe2\x80\x99t Stop the Feeling! (original song from Dreamworks Animation\xe2\x80\x99s \xe2\x80\x9cTrolls\xe2\x80\x9d).mp3' 2016-06-12 23:12:23 INFO Checking which files we need to move..... 2016-06-12 23:12:23 INFO Moving files: /tmp/headphones_yz6sKl/headphones 2016-06-12 23:12:23 INFO Renaming files 2016-06-12 23:12:23 INFO Successfully applied metadata to: /tmp/headphones_yz6sKl/headphones/01 - CAN'T STOP THE FEELING!.mp3 2016-06-12 23:12:23 INFO Beets recommendation for tagging items: Recommendation.medium 2016-06-12 23:12:18 INFO Preparing to write metadata to tracks.... 2016-06-12 23:12:18 INFO Cleaning up files 2016-06-12 23:12:13 INFO Copying files to /tmp/headphones_yz6sKl/headphones subfolder to preserve downloaded files for seeding 2016-06-12 23:12:13 INFO Starting post-processing for: Justin Timberlake - Can’t Stop the Feeling! 2016-06-12 23:12:12 INFO Found "Justin Timberlake - CAN'T STOP THE FEELING! (Original Song From DreamWorks Animation's ''Trolls'') (2016) - 320-WEB" in torrent download folder. Verifying....
Albums/Artists with only standard ASCII characters never encounter this issue which I've only been able to resolve by removing from headphones' defined download path.

@konfiot
Copy link

konfiot commented Jun 23, 2016

Got the same problem here

@YipYup
Copy link
Contributor

YipYup commented Jul 22, 2016

This seems to be caused when single or double quotes are present in the file name, escaping the handling of the file.

I had a few folders giving me issues too. I ended up removing the single and double quotes from the file name, and then Headphones was able to process them. Hopefully a permanent solution can be created.

@permster
Copy link
Contributor

permster commented Sep 13, 2018

I dug into this issue way further than I wanted to and thought I would share my findings in case it helps others. In my situation I get an [Errno 13] permission denied when it moves each file to the destination location.

From the python docs on shutil.move():
If the destination is on the current filesystem, then os.rename() is used. Otherwise, src is copied (using shutil.copy2()) to dst and then removed.

Then looking at shtuil.copy2() in the docs:
Similar to shutil.copy(), but metadata is copied as well – in fact, this is just shutil.copy() followed by shutil.copystat().

So when it goes to move across filesystems it does a copy() and then copystat(). In my case the copy works fine but the copystat() fails with permission denied. This causes duplicate copies of the files at the destination. Each time it runs post-processing it creates more copies under other [1], [2], etc. folders. I had over 600 GB of duplicate files from not catching this issue right away.

Bottom line is that the helpers.py function smartMove() needs additional error handling. Either that or headphones needs a mechanism to mark post-processing as failed for the release and skip over it. That way at least you don't get a ton of duplicates at the destination. This isn't the only reported issue on this either. Some are still open and some are closed.

More info: https://stackoverflow.com/a/26654245

@permster
Copy link
Contributor

Looks like Couch Potato has some code that works around this issue.
https://github.com/CouchPotato/CouchPotatoServer/blob/12ca4c22680961346e0aa2617941bf1a7252fc67/couchpotato/core/plugins/renamer.py#L843

Try catch on the shutil.move() with exception handling. In the exception handler if both destination file exists and it's the same size as the source file it logs and deletes the source file.

If I get some time later this week I'll get a pull request going with the workaround.

AdeHub added a commit that referenced this issue Oct 14, 2018
@AdeHub AdeHub closed this as completed Dec 8, 2018
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

No branches or pull requests

5 participants