funkyg / funkytunes

A streaming music player for Android, using torrents.
GNU General Public License v3.0
122 stars 24 forks source link

SkyTorrentsAdapter: skytorrents.in stopped serving .torrent files #39

Closed christophfink closed 7 years ago

christophfink commented 7 years ago

FunkyTunes keeps crashing on my LineageOS 14.1-20170725-NIGHTLY-hammerhead (no gapps) trying to open an album. I started investigating into the error and found that TheProxyPirate.pw is now redirecting to an ad network :/ It might not be directly connected to the error I am experiencing, but still should be fixed. Thanks!

gjedeer commented 7 years ago

The README isn't exactly up to date, this is the list of TPB proxies used and TheProxyPirate.pw isn't among them any more:

https://github.com/funkyg/funkytunes/blob/master/app/src/main/kotlin/com/github/funkyg/funkytunes/network/PirateBayAdapter.kt#L28

Logcat please?

gjedeer commented 7 years ago

Also: are you using 0.2.0? Maybe you're stuck with some old version still using theproxypirate.pw?

christophfink commented 7 years ago

You are right, I just looked at the README. Of course I did not realise there was a new list of TPB proxies.

logcat in attachment, the relevant part seems to be:

08-02 14:29:02.547 22807 22807 E AndroidRuntime: FATAL EXCEPTION: main
08-02 14:29:02.547 22807 22807 E AndroidRuntime: Process: com.github.funkyg.funkytunes, PID: 22807
08-02 14:29:02.547 22807 22807 E AndroidRuntime: java.lang.StringIndexOutOfBoundsException: length=2730; regionStart=1556; regionLength=-1557
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at java.lang.String.substring(String.java:1931)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.github.funkyg.funkytunes.network.SkyTorrentsAdapter.parseHtmlItem(SkyTorrentsAdapter.kt:217)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.github.funkyg.funkytunes.network.SkyTorrentsAdapter.parseHtml(SkyTorrentsAdapter.kt:172)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.github.funkyg.funkytunes.network.SkyTorrentsAdapter.access$parseHtml(SkyTorrentsAdapter.kt:28)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.github.funkyg.funkytunes.network.SkyTorrentsAdapter$search_mirror$request$2.onResponse(SkyTorrentsAdapter.kt:55)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.github.funkyg.funkytunes.network.SkyTorrentsAdapter$search_mirror$request$2.onResponse(SkyTorrentsAdapter.kt:54)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:751)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:95)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6186)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
08-02 14:29:02.547 22807 22807 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
08-02 14:29:02.552  2403  3243 W ActivityManager:   Force finishing activity

I’ll try to gather more information on which string is the culprit and come back to you

christophfink commented 7 years ago

The problem seems to be that SkyTorrentsAdapter.kt’s MAGNET_LINK matches not only on links containing magnet links, but also other <a href (it’s in line https://github.com/funkyg/funkytunes/blob/master/app/src/main/kotlin/com/github/funkyg/funkytunes/network/SkyTorrentsAdapter.kt#L188 )

A quick workaround, but a bit ugly, is to extend the sort pattern to include the “protocol” magnet and adding it again to the extracted string (a bit like a negative lookahead)

--- a/app/src/main/kotlin/com/github/funkyg/funkytunes/network/SkyTorrentsAdapter.kt
+++ b/app/src/main/kotlin/com/github/funkyg/funkytunes/network/SkyTorrentsAdapter.kt
@@ -185,7 +185,7 @@ class SkyTorrentsAdapter(context: Context) {
         val NAME_END = "</a>"
         val TORRENT_LINK = "<a href=\""
         val TORRENT_LINK_END = "\" rel=\"nofollow\""
-        val MAGNET_LINK = "<a href=\""
+        val MAGNET_LINK = "<a href=\"magnet:?"
         val MAGNET_LINK_END = "\" rel=\"nofollow\""
         val SIZE = "<td class=\"is-hidden-touch\" >"
         val SIZE_END = "</td>"
@@ -213,7 +213,7 @@ class SkyTorrentsAdapter(context: Context) {
         val torrentLink = prefixDetails + htmlItem.substring(torrentLinkStart, htmlItem.indexOf(TORRENT_LINK_END, torrentLinkStart))

         // Magnet link is second
         val magnetLinkStart = htmlItem.indexOf(MAGNET_LINK, torrentLinkStart) + MAGNET_LINK.length
-        val magnetLink = htmlItem.substring(magnetLinkStart, htmlItem.indexOf(MAGNET_LINK_END, magnetLinkStart))
+        val magnetLink = "magnet:?" + htmlItem.substring(magnetLinkStart, htmlItem.indexOf(MAGNET_LINK_END, magnetLinkStart))

         val sizeStart = htmlItem.indexOf(SIZE, magnetLinkStart) + SIZE.length

I don’t know whether you would accept such a hack as a pull request, so I’m not submitting one. Also the comments suggest that you consider moving to parsing the html as an xml rather than a string, so I would not like to invest time into rewriting the whole .kt to using regular expressions either.

christophfink commented 7 years ago

I dug a bit further into it and it seems that the actual problem is that skytorrents.in (seems to have) stopped providing links to .torrent files.

The changes outlined in my comment above prevent the fatal exception, but do not yield results. Rather, the skytorrents adapter fails gracefully, and the Piratebay adapter steps in and downloads the torrent successfully.

gjedeer commented 7 years ago

It's a pity! Torrents made the app so much more responsive. Send a pr please. If you want to rewrite that using xml, send another one later, but a quickfix would be appreciated.

On August 2, 2017 4:56:32 PM GMT+02:00, christophfink notifications@github.com wrote:

I dug a bit further into it and it seems that the actual problem is that skytorrents.in (seems to have) stopped providing links to .torrent files.

The changes outlined in my comment above prevent the fatal exception, but do not yield results. Rather, the skytorrents adapter fails gracefully, and the Piratebay adapter steps in and downloads the torrent successfully.

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/funkyg/funkytunes/issues/39#issuecomment-319698087

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.