HenrikDK / youtube-xbmc-plugin

Official Youtube Plugin for XBMC (Now on GitHub)
88 stars 71 forks source link

Music videos not playing again - possible fix #95

Open gitman0 opened 9 years ago

gitman0 commented 9 years ago

I found that music videos were not playing again, and again I am seeing signature extraction algorithm failing to compile in the debug log. I found that the '$' character was not being properly replaced with '_S_' in the main function name when piecing algorithm together. It does this in the _getFullAlgoCode function, but not where it concats everything together. I made the following edit and it appears to have resolved my issues. Can anyone else confirm?

--- YouTubePlayer.py    2015-01-19 21:41:53.880901235 -0500
+++ YouTubePlayer.py    2015-01-20 12:12:07.872778896 -0500
@@ -484,7 +484,7 @@
                 algoLines[i] = '\t' + algoLines[i]
             fullAlgoCode  = 'def extractedSignatureAlgo(param):'
             fullAlgoCode += '\n'.join(algoLines)
-            fullAlgoCode += '\n\treturn %s(param)' % mainFunName
+            fullAlgoCode += '\n\treturn %s(param)' % mainFunName.replace('$','_S_')
             fullAlgoCode += '\noutSignature = extractedSignatureAlgo( inSignature )\n'

             # after this function we should have all needed code in fullAlgoCode

This is the error I was seeing in the debug log. I added some extra statements to get the specific error message:

21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : '---------------------------------------'
21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : '|    ALGO FOR SIGNATURE DECRYPTION    |'
21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : '---------------------------------------'
21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : 'def extractedSignatureAlgo(param):       
                                                def _S_s(a):
                                                        a=list(a)
                                                        Zs__ur(a,28)
                                                        Zs__KU(a,29)
                                                        Zs__wt(a,1)
                                                        Zs__ur(a,23)
                                                        Zs__wt(a,1)
                                                        Zs__ur(a,31)
                                                        Zs__KU(a,4)
                                                        Zs__KU(a,28)
                                                        return "".join(a)

                                                return $s(param)
                                            outSignature = extractedSignatureAlgo( inSignature )
                                            '
21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : '---------------------------------------'
21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : 'Error: <type 'exceptions.SyntaxError'> - invalid syntax (, line 14)'
21:44:03 T:1920  NOTICE: [YouTube-4.4.10] decrypt_signature : 'decryptSignature compile algo code EXCEPTION'

I'm not sure what causes some videos to have a signature extraction function names with a dollar sign in them, it seems random. But I'm not sure why others aren't reporting the same thing more frequently.

mark79 commented 9 years ago

gitman0: your fix worked for me. Good catch!

mrjwm2 commented 9 years ago

gitman0, I have tried the edit and Vevo still does not play. I am using v4.4.1 Any thoughts? How could I produce the log as you have shown above? I don't see this info in my debug log.

Thanks

mrjwm2 commented 9 years ago

Update: I performed a reinstall of Helix and all is good. (must not have deleted all v5 files) I also found the method to debugging within the youtube addon. Thanks for the fix. I use the download feature in v4.4.1 often. Thanks for keeping this version alive!

gitman0 commented 9 years ago

good to hear, mark79 and mrjwm2!

gitman0 commented 9 years ago

Here's a new set of edits, friends. More dollar sign issues are being accounted for here, specifically the dollar sign being used in the local object/var names:

--- YouTubePlayer.py    2015-01-30 15:25:01.000000000 -0500
+++ YouTubePlayer.py    2015-01-30 20:09:55.824869635 -0500
@@ -529,7 +530,7 @@

     def _extractLocalVarNames(self, mainFunBody ):
         valid_funcs = ( 'reverse', 'split', 'splice', 'slice', 'join' )
-        match = re.compile( r'[; =(,](\w+)\.(\w+)\(' ).findall( mainFunBody )
+        match = re.compile( r'[; =(,]([\$\w]+)\.(\w+)\(' ).findall( mainFunBody )
         local_vars = []
         for name in match:
             if name[1] not in valid_funcs:
@@ -538,7 +539,7 @@
         return set( local_vars )

     def _getLocalVarObjBody(self, varName, playerData):
-        match = re.search( r'var %s={.*?}};' % varName, playerData )
+        match = re.search( r'var %s={.*?}};' % varName.replace('$','\\$'), playerData )
         if match:
             self.common.log('Found variable object: ' + match.group(0))
             return match.group(0)
@@ -566,10 +567,12 @@
             varNames = self._extractLocalVarNames(funBody)
             if len(varNames):
                 for varName in varNames:
+                    varName_=varName.replace('$','_S_')
                     self.common.log("Found local var object: " + str(varName))
                     self.common.log("Known vars: " + str(allLocalVarNamesTab))
                     if varName not in allLocalVarNamesTab:
                         self.common.log("Adding local var object %s to known objects" % varName)
+                        funBody=funBody.replace(varName,varName_)
                         allLocalVarNamesTab.append(varName)
                         funBody = self._getLocalVarObjBody( varName, playerData ) + "\n" + funBody
mrjwm2 commented 9 years ago

Thanks gitman0, I will test and let you know.

mrjwm2 commented 9 years ago

working just fine with the changes

gitman0 commented 9 years ago

great. any chance you had a video that wasn't working that is now working after these latest changes? thanks,

mrjwm2 commented 9 years ago

No not this edit. But the previous edit fixed Vevo. I made a log before and after this change, I am trying to see if I can figure out what does what. :) Would I be right that your new edit makes the function always replace $ with S whenever identified?

Date: Wed, 4 Feb 2015 13:32:52 -0800 From: notifications@github.com To: youtube-xbmc-plugin@noreply.github.com CC: mrjwm2@hotmail.com Subject: Re: [youtube-xbmc-plugin] Music videos not playing again - possible fix (#95)

great. any chance you had a video that wasn't working that is now working after these latest changes? thanks,

— Reply to this email directly or view it on GitHub.

gitman0 commented 9 years ago

the first edit was for the main function name, but the last set of edits was specifically for the function calls within the main function. it seemed totally random whether Youtube handed out the code with dollar signs in them or not. like you, i was able to fix music videos after the first edit, but last week i experienced two nonconsecutive days in which it did not work, and the reason was the dollar sign character again but this time within the function.

this is what i saw in the debug log prior to the last edits:

14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : 'Main signature function name = "at"'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] _extractLocalVarNames : 'Found variable names: []'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] _jsToPy : 'function at(a){a=a.split("");$s.kB(a,2);$s.tN(a,44);$s.hw(a,28);$s.kB(a,3);$s.tN(a,17);$s.kB(a,1);return a.join("")
}'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : '---------------------------------------'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : '|    ALGO FOR SIGNATURE DECRYPTION    |'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : '---------------------------------------'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : 'def extractedSignatureAlgo(param):       
                                                def at(a):
                                                        a=list(a)
                                                        $s__kB(a,2)
                                                        $s__tN(a,44)
                                                        $s__hw(a,28)
                                                        $s__kB(a,3)
                                                        $s__tN(a,17)
                                                        $s__kB(a,1)
                                                        return "".join(a)

                                                return at(param)
                                            outSignature = extractedSignatureAlgo( inSignature )
                                            '
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : '---------------------------------------'
14:16:08 T:4800  NOTICE: [YouTube-4.4.10] decrypt_signature : 'decryptSignature compile algo code EXCEPTION'